|
1 | 1 | importprocessfrom'node:process' |
2 | 2 | importtseslintfrom'typescript-eslint' |
3 | 3 | importtype{TSESLint}from'@typescript-eslint/utils' |
| 4 | +importpluginVuefrom'eslint-plugin-vue' |
4 | 5 |
|
5 | 6 | import{TsEslintConfigForVue}from'./configs' |
6 | 7 | importgroupVueFilesfrom'./groupVueFiles' |
@@ -78,9 +79,10 @@ export function defineConfigWithVueTs( |
78 | 79 | returnpipe( |
79 | 80 | configs, |
80 | 81 | flattenConfigs, |
| 82 | +deduplicateVuePlugin, |
81 | 83 | insertAndReorderConfigs, |
82 | 84 | resolveVueTsConfigs, |
83 | | -tseslint.config,// this might not be necessary, but it doesn't hurt to keep it |
| 85 | +tseslint.config,// this might not be necessary, but it doesn't hurt to keep it |
84 | 86 | ) |
85 | 87 | } |
86 | 88 |
|
@@ -191,7 +193,10 @@ function insertAndReorderConfigs(configs: RawConfigItem[]): RawConfigItem[] { |
191 | 193 |
|
192 | 194 | return[ |
193 | 195 | ...configsWithoutTypeAwareRules.slice(0,lastExtendedConfigIndex+1), |
194 | | - ...createBasicSetupConfigs(projectOptions.tsSyntaxInTemplates,projectOptions.scriptLangs), |
| 196 | + ...createBasicSetupConfigs( |
| 197 | +projectOptions.tsSyntaxInTemplates, |
| 198 | +projectOptions.scriptLangs, |
| 199 | +), |
195 | 200 |
|
196 | 201 | // user-turned-off type-aware rules must come after the last extended config |
197 | 202 | // in case some rules re-enabled by the extended config |
@@ -248,3 +253,34 @@ const rulesRequiringTypeInformation = new Set( |
248 | 253 | functiondoesRuleRequireTypeInformation(ruleName:string):boolean{ |
249 | 254 | returnrulesRequiringTypeInformation.has(ruleName) |
250 | 255 | } |
| 256 | + |
| 257 | +functiondeduplicateVuePlugin(configs:RawConfigItem[]):RawConfigItem[]{ |
| 258 | +returnconfigs.map(config=>{ |
| 259 | +if(configinstanceofTsEslintConfigForVue||!config.plugins?.vue){ |
| 260 | +returnconfig |
| 261 | +} |
| 262 | + |
| 263 | +constcurrentVuePlugin=config.plugins.vue |
| 264 | +if(currentVuePlugin!==pluginVue){ |
| 265 | +constcurrentVersion:string=currentVuePlugin.meta?.version||'unknown' |
| 266 | +constexpectedVersion:string=pluginVue.meta?.version||'unknown' |
| 267 | + |
| 268 | +constconfigName:string=config.name||'unknown config' |
| 269 | + |
| 270 | +console.warn( |
| 271 | +`Warning: Multiple instances of eslint-plugin-vue detected in${configName}. `+ |
| 272 | +`Replacing version${currentVersion} with version${expectedVersion}.`, |
| 273 | +) |
| 274 | + |
| 275 | +return{ |
| 276 | + ...config, |
| 277 | +plugins:{ |
| 278 | + ...config.plugins, |
| 279 | +vue:pluginVue, |
| 280 | +}, |
| 281 | +} |
| 282 | +} |
| 283 | + |
| 284 | +returnconfig |
| 285 | +}) |
| 286 | +} |