Skip to content

Commit a3070fe

Browse files
committed
fix: override duplicate plugin-vue instances with the peer dep one
1 parent e2ddf59 commit a3070fe

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

src/utilities.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import process from 'node:process'
22
import tseslint from 'typescript-eslint'
33
import type { TSESLint } from '@typescript-eslint/utils'
4+
import pluginVue from 'eslint-plugin-vue'
45

56
import { TsEslintConfigForVue } from './configs'
67
import groupVueFiles from './groupVueFiles'
@@ -78,9 +79,10 @@ export function defineConfigWithVueTs(
7879
return pipe(
7980
configs,
8081
flattenConfigs,
82+
deduplicateVuePlugin,
8183
insertAndReorderConfigs,
8284
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
8486
)
8587
}
8688

@@ -191,7 +193,10 @@ function insertAndReorderConfigs(configs: RawConfigItem[]): RawConfigItem[] {
191193

192194
return [
193195
...configsWithoutTypeAwareRules.slice(0, lastExtendedConfigIndex + 1),
194-
...createBasicSetupConfigs(projectOptions.tsSyntaxInTemplates, projectOptions.scriptLangs),
196+
...createBasicSetupConfigs(
197+
projectOptions.tsSyntaxInTemplates,
198+
projectOptions.scriptLangs,
199+
),
195200

196201
// user-turned-off type-aware rules must come after the last extended config
197202
// in case some rules re-enabled by the extended config
@@ -248,3 +253,34 @@ const rulesRequiringTypeInformation = new Set(
248253
function doesRuleRequireTypeInformation(ruleName: string): boolean {
249254
return rulesRequiringTypeInformation.has(ruleName)
250255
}
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+
}

test/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ test('#87: should not error if the project root has an older version of espree i
203203
test.only('#161: should warn and override the vue plugin if there are multiple versions of `eslint-plugin-vue` found in the config', async () => {
204204
const { stderr } = await runLintAgainst('redefine-plugin-vue', FROM_FIXTURES)
205205
expect(stderr).not.toMatch(`Cannot redefine plugin "vue"`)
206-
// TODO: test our warning message
206+
expect(stderr).toMatch('Warning: Multiple instances of eslint-plugin-vue detected')
207207
})
208208

209209

0 commit comments

Comments
 (0)