|
1 | 1 | import process from 'node:process'
|
2 | 2 | import tseslint from 'typescript-eslint'
|
3 | 3 | import type { TSESLint } from '@typescript-eslint/utils'
|
| 4 | +import pluginVue from 'eslint-plugin-vue' |
4 | 5 |
|
5 | 6 | import { TsEslintConfigForVue } from './configs'
|
6 | 7 | import groupVueFiles from './groupVueFiles'
|
@@ -78,9 +79,10 @@ export function defineConfigWithVueTs(
|
78 | 79 | return pipe(
|
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 | function doesRuleRequireTypeInformation(ruleName: string): boolean {
|
249 | 254 | return rulesRequiringTypeInformation.has(ruleName)
|
250 | 255 | }
|
| 256 | + |
| 257 | +function deduplicateVuePlugin(configs: RawConfigItem[]): RawConfigItem[] { |
| 258 | + return configs.map(config => { |
| 259 | + if (config instanceof TsEslintConfigForVue || !config.plugins?.vue) { |
| 260 | + return config |
| 261 | + } |
| 262 | + |
| 263 | + const currentVuePlugin = config.plugins.vue |
| 264 | + if (currentVuePlugin !== pluginVue) { |
| 265 | + const currentVersion: string = currentVuePlugin.meta?.version || 'unknown' |
| 266 | + const expectedVersion: string = pluginVue.meta?.version || 'unknown' |
| 267 | + |
| 268 | + const configName: 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 | + return config |
| 285 | + }) |
| 286 | +} |
0 commit comments