Skip to content

fix: ensure there's only one instance of plugin-vue in the config #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
516 changes: 329 additions & 187 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"schedule:monthly"
],
"ignorePaths": [
"**/node_modules/**"
"**/node_modules/**",
"test/fixtures/redefine-plugin-vue"
],
"ignoreDeps": ["espree"]
}
40 changes: 38 additions & 2 deletions src/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import process from 'node:process'
import tseslint from 'typescript-eslint'
import type { TSESLint } from '@typescript-eslint/utils'
import pluginVue from 'eslint-plugin-vue'

import { TsEslintConfigForVue } from './configs'
import groupVueFiles from './groupVueFiles'
Expand Down Expand Up @@ -78,9 +79,10 @@ export function defineConfigWithVueTs(
return pipe(
configs,
flattenConfigs,
deduplicateVuePlugin,
insertAndReorderConfigs,
resolveVueTsConfigs,
tseslint.config, // this might not be necessary, but it doesn't hurt to keep it
tseslint.config, // this might not be necessary, but it doesn't hurt to keep it
)
}

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

return [
...configsWithoutTypeAwareRules.slice(0, lastExtendedConfigIndex + 1),
...createBasicSetupConfigs(projectOptions.tsSyntaxInTemplates, projectOptions.scriptLangs),
...createBasicSetupConfigs(
projectOptions.tsSyntaxInTemplates,
projectOptions.scriptLangs,
),

// user-turned-off type-aware rules must come after the last extended config
// in case some rules re-enabled by the extended config
Expand Down Expand Up @@ -248,3 +253,34 @@ const rulesRequiringTypeInformation = new Set(
function doesRuleRequireTypeInformation(ruleName: string): boolean {
return rulesRequiringTypeInformation.has(ruleName)
}

function deduplicateVuePlugin(configs: RawConfigItem[]): RawConfigItem[] {
return configs.map(config => {
if (config instanceof TsEslintConfigForVue || !config.plugins?.vue) {
return config
}

const currentVuePlugin = config.plugins.vue
if (currentVuePlugin !== pluginVue) {
const currentVersion: string = currentVuePlugin.meta?.version || 'unknown'
const expectedVersion: string = pluginVue.meta?.version || 'unknown'

const configName: string = config.name || 'unknown config'

console.warn(
`Warning: Multiple instances of eslint-plugin-vue detected in ${configName}. ` +
`Replacing version ${currentVersion} with version ${expectedVersion}.`,
)

return {
...config,
plugins: {
...config.plugins,
vue: pluginVue,
},
}
}

return config
})
}
9 changes: 9 additions & 0 deletions test/fixtures/redefine-plugin-vue/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,vue,css,scss,sass,less,styl}]
charset = utf-8
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

end_of_line = lf
max_line_length = 100
1 change: 1 addition & 0 deletions test/fixtures/redefine-plugin-vue/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
30 changes: 30 additions & 0 deletions test/fixtures/redefine-plugin-vue/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
.DS_Store
dist
dist-ssr
coverage
*.local

/cypress/videos/
/cypress/screenshots/

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

*.tsbuildinfo
7 changes: 7 additions & 0 deletions test/fixtures/redefine-plugin-vue/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"Vue.volar",
"dbaeumer.vscode-eslint",
"EditorConfig.EditorConfig"
]
}
39 changes: 39 additions & 0 deletions test/fixtures/redefine-plugin-vue/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# redefine-plugin-vue

This template should help get you started developing with Vue 3 in Vite.

## Recommended IDE Setup

[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).

## Type Support for `.vue` Imports in TS

TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types.

## Customize configuration

See [Vite Configuration Reference](https://vite.dev/config/).

## Project Setup

```sh
pnpm install
```

### Compile and Hot-Reload for Development

```sh
pnpm dev
```

### Type-Check, Compile and Minify for Production

```sh
pnpm build
```

### Lint with [ESLint](https://eslint.org/)

```sh
pnpm lint
```
1 change: 1 addition & 0 deletions test/fixtures/redefine-plugin-vue/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
20 changes: 20 additions & 0 deletions test/fixtures/redefine-plugin-vue/eslint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { globalIgnores } from 'eslint/config'
import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript'
import pluginVue from 'eslint-plugin-vue'

// To allow more languages other than `ts` in `.vue` files, uncomment the following lines:
// import { configureVueProject } from '@vue/eslint-config-typescript'
// configureVueProject({ scriptLangs: ['ts', 'tsx'] })
// More info at https://github.com/vuejs/eslint-config-typescript/#advanced-setup

export default defineConfigWithVueTs(
{
name: 'app/files-to-lint',
files: ['**/*.{ts,mts,tsx,vue}'],
},

globalIgnores(['**/dist/**', '**/dist-ssr/**', '**/coverage/**']),

pluginVue.configs['flat/essential'],
vueTsConfigs.recommended,
)
13 changes: 13 additions & 0 deletions test/fixtures/redefine-plugin-vue/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
32 changes: 32 additions & 0 deletions test/fixtures/redefine-plugin-vue/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "redefine-plugin-vue",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "run-p type-check \"build-only {@}\" --",
"preview": "vite preview",
"build-only": "vite build",
"type-check": "vue-tsc --build",
"lint": "eslint . --fix"
},
"dependencies": {
"vue": "^3.5.13"
},
"devDependencies": {
"@tsconfig/node22": "^22.0.1",
"@types/node": "^22.14.0",
"@vitejs/plugin-vue": "^5.2.3",
"@vue/eslint-config-typescript": "workspace:*",
"@vue/tsconfig": "^0.7.0",
"eslint": "^9.22.0",
"eslint-plugin-vue": "~10.0.0",
"jiti": "^2.4.2",
"npm-run-all2": "^8.0.4",
"typescript": "~5.8.0",
"vite": "^6.2.4",
"vite-plugin-vue-devtools": "^7.7.2",
"vue-tsc": "^2.2.8"
}
}
Binary file not shown.
47 changes: 47 additions & 0 deletions test/fixtures/redefine-plugin-vue/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<script setup lang="ts">
import HelloWorld from './components/HelloWorld.vue'
import TheWelcome from './components/TheWelcome.vue'
</script>

<template>
<header>
<img alt="Vue logo" class="logo" src="./assets/logo.svg" width="125" height="125" />

<div class="wrapper">
<HelloWorld msg="You did it!" />
</div>
</header>

<main>
<TheWelcome />
</main>
</template>

<style scoped>
header {
line-height: 1.5;
}

.logo {
display: block;
margin: 0 auto 2rem;
}

@media (min-width: 1024px) {
header {
display: flex;
place-items: center;
padding-right: calc(var(--section-gap) / 2);
}

.logo {
margin: 0 2rem 0 0;
}

header .wrapper {
display: flex;
place-items: flex-start;
flex-wrap: wrap;
}
}
</style>
86 changes: 86 additions & 0 deletions test/fixtures/redefine-plugin-vue/src/assets/base.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* color palette from <https://github.com/vuejs/theme> */
:root {
--vt-c-white: #ffffff;
--vt-c-white-soft: #f8f8f8;
--vt-c-white-mute: #f2f2f2;

--vt-c-black: #181818;
--vt-c-black-soft: #222222;
--vt-c-black-mute: #282828;

--vt-c-indigo: #2c3e50;

--vt-c-divider-light-1: rgba(60, 60, 60, 0.29);
--vt-c-divider-light-2: rgba(60, 60, 60, 0.12);
--vt-c-divider-dark-1: rgba(84, 84, 84, 0.65);
--vt-c-divider-dark-2: rgba(84, 84, 84, 0.48);

--vt-c-text-light-1: var(--vt-c-indigo);
--vt-c-text-light-2: rgba(60, 60, 60, 0.66);
--vt-c-text-dark-1: var(--vt-c-white);
--vt-c-text-dark-2: rgba(235, 235, 235, 0.64);
}

/* semantic color variables for this project */
:root {
--color-background: var(--vt-c-white);
--color-background-soft: var(--vt-c-white-soft);
--color-background-mute: var(--vt-c-white-mute);

--color-border: var(--vt-c-divider-light-2);
--color-border-hover: var(--vt-c-divider-light-1);

--color-heading: var(--vt-c-text-light-1);
--color-text: var(--vt-c-text-light-1);

--section-gap: 160px;
}

@media (prefers-color-scheme: dark) {
:root {
--color-background: var(--vt-c-black);
--color-background-soft: var(--vt-c-black-soft);
--color-background-mute: var(--vt-c-black-mute);

--color-border: var(--vt-c-divider-dark-2);
--color-border-hover: var(--vt-c-divider-dark-1);

--color-heading: var(--vt-c-text-dark-1);
--color-text: var(--vt-c-text-dark-2);
}
}

*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
font-weight: normal;
}

body {
min-height: 100vh;
color: var(--color-text);
background: var(--color-background);
transition:
color 0.5s,
background-color 0.5s;
line-height: 1.6;
font-family:
Inter,
-apple-system,
BlinkMacSystemFont,
'Segoe UI',
Roboto,
Oxygen,
Ubuntu,
Cantarell,
'Fira Sans',
'Droid Sans',
'Helvetica Neue',
sans-serif;
font-size: 15px;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
1 change: 1 addition & 0 deletions test/fixtures/redefine-plugin-vue/src/assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading