Skip to content

Commit ebf6cb5

Browse files
chore: Use ESLint v9 in development env (#2775)
Co-authored-by: Flo Edelmann <git@flo-edelmann.de>
1 parent 24eccf4 commit ebf6cb5

25 files changed

+179
-154
lines changed

.changeset/fast-penguins-reflect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-vue": minor
3+
---
4+
5+
Added [`@typescript-eslint/parser`](https://typescript-eslint.io/packages/parser) as an optional peer dependency

.changeset/gentle-glasses-tie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-vue": patch
3+
---
4+
5+
Fixed false negatives when using typescript-eslint v8 in [`vue/script-indent`](https://eslint.vuejs.org/rules/script-indent.html) rule

.github/workflows/CI.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
with:
4747
node-version: ${{ matrix.node }}
4848
- name: Install Packages
49-
run: npm install -f
49+
run: npm install
5050
- name: Install ESLint v${{ matrix.eslint }}
5151
run: npm install --save-dev eslint@${{ matrix.eslint }} -f
5252
- name: Test
@@ -61,8 +61,23 @@ jobs:
6161
- name: Install Node.js
6262
uses: actions/setup-node@v4
6363
- name: Install Packages
64-
run: npm install -f
64+
run: npm install
6565
- name: Uninstall @stylistic/eslint-plugin
6666
run: npm uninstall -D @stylistic/eslint-plugin
6767
- name: Test
6868
run: npm test
69+
70+
test-with-typescript-eslint-v7:
71+
name: Test with typescript-eslint v7
72+
runs-on: ubuntu-latest
73+
steps:
74+
- name: Checkout
75+
uses: actions/checkout@v4
76+
- name: Install Node.js
77+
uses: actions/setup-node@v4
78+
- name: Install Packages
79+
run: npm install
80+
- name: Install @typescript-eslint/parser@7
81+
run: npm install -D @typescript-eslint/parser@7 -f
82+
- name: Test
83+
run: npm test

.github/workflows/Release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Setup Node.js
2323
uses: actions/setup-node@v4
2424
- name: Install Dependencies
25-
run: npm install -f
25+
run: npm install
2626

2727
- name: Create Release Pull Request or Publish to npm
2828
id: changesets

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
yarn.lock
99
yarn-error.log
1010
/docs/.vitepress/dist
11-
/docs/.vitepress/build-system/shim/eslint.mjs
12-
/docs/.vitepress/build-system/shim/assert.mjs
11+
/docs/.vitepress/build-system/shim/vue-eslint-parser.mjs
12+
/docs/.vitepress/build-system/shim/@typescript-eslint/parser.mjs
1313
/docs/.vitepress/.temp
1414
/docs/.vitepress/cache
1515
typings/eslint/lib/rules

docs/.vitepress/build-system/build.mts

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,38 @@ import { fileURLToPath } from 'url'
99
const dirname = path.dirname(fileURLToPath(import.meta.url))
1010

1111
build(
12-
path.join(dirname, './src/eslint.mjs'),
13-
path.join(dirname, './shim/eslint.mjs'),
14-
['path', 'assert', 'util', 'esquery']
12+
path.join(
13+
dirname,
14+
'../../../node_modules/@typescript-eslint/parser/dist/index.js'
15+
),
16+
path.join(dirname, './shim/@typescript-eslint/parser.mjs'),
17+
[
18+
'util',
19+
'node:util',
20+
'path',
21+
'node:path',
22+
'fs',
23+
'node:fs',
24+
'semver',
25+
'fast-glob',
26+
'debug'
27+
]
1528
)
29+
1630
build(
17-
path.join(dirname, '../../../node_modules/assert'),
18-
path.join(dirname, './shim/assert.mjs'),
19-
['path']
31+
path.join(dirname, '../../../node_modules/vue-eslint-parser/index.js'),
32+
path.join(dirname, './shim/vue-eslint-parser.mjs'),
33+
[
34+
'path',
35+
'debug',
36+
'semver',
37+
'assert',
38+
'module',
39+
'events',
40+
'esquery',
41+
'fs',
42+
'eslint'
43+
]
2044
)
2145

2246
function build(input: string, out: string, injects: string[] = []) {
@@ -42,16 +66,22 @@ function bundle(entryPoint: string, externals: string[]) {
4266
}
4367

4468
function transform(code: string, injects: string[]) {
69+
const normalizeInjects = [
70+
...new Set(injects.map((inject) => inject.replace(/^node:/u, '')))
71+
]
4572
const newCode = code.replace(/"[a-z]+" = "[a-z]+";/u, '')
4673
return `
47-
${injects
74+
${normalizeInjects
4875
.map(
4976
(inject) =>
50-
`import $inject_${inject.replace(/-/gu, '_')}$ from '${inject}';`
77+
`import $inject_${inject.replace(/[\-:]/gu, '_')}$ from '${inject}';`
5178
)
5279
.join('\n')}
5380
const $_injects_$ = {${injects
54-
.map((inject) => `${inject.replace(/-/gu, '_')}:$inject_${inject}$`)
81+
.map(
82+
(inject) =>
83+
`"${inject}":$inject_${inject.replace(/^node:/u, '').replace(/[\-:]/gu, '_')}$`
84+
)
5585
.join(',\n')}};
5686
function require(module, ...args) {
5787
return $_injects_$[module] || {}

docs/.vitepress/build-system/shim/eslint/use-at-your-own-risk.mjs

Lines changed: 0 additions & 3 deletions
This file was deleted.

docs/.vitepress/build-system/shim/esquery.mjs

Lines changed: 0 additions & 5 deletions
This file was deleted.

docs/.vitepress/build-system/shim/path.mjs

Lines changed: 0 additions & 38 deletions
This file was deleted.

docs/.vitepress/build-system/src/eslint.mjs

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/.vitepress/config.mts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { defineConfig } from 'vitepress'
33
import path from 'pathe'
44
import { fileURLToPath } from 'url'
55
import { viteCommonjs, vitePluginRequireResolve } from './vite-plugin.mjs'
6+
import eslint4b, { requireESLintUseAtYourOwnRisk4b } from 'vite-plugin-eslint4b'
67

78
// Pre-build cjs packages that cannot be bundled well.
89
import './build-system/build.mjs'
@@ -142,24 +143,30 @@ export default async () => {
142143

143144
vite: {
144145
publicDir: path.resolve(dirname, './public'),
145-
plugins: [vitePluginRequireResolve(), viteCommonjs()],
146+
plugins: [
147+
vitePluginRequireResolve(),
148+
viteCommonjs(),
149+
eslint4b() as any,
150+
requireESLintUseAtYourOwnRisk4b()
151+
],
146152
resolve: {
147153
alias: {
148-
'eslint/use-at-your-own-risk': path.join(
154+
'vue-eslint-parser': path.join(
155+
dirname,
156+
'./build-system/shim/vue-eslint-parser.mjs'
157+
),
158+
'@typescript-eslint/parser': path.join(
149159
dirname,
150-
'./build-system/shim/eslint/use-at-your-own-risk.mjs'
160+
'./build-system/shim/@typescript-eslint/parser.mjs'
151161
),
152-
eslint: path.join(dirname, './build-system/shim/eslint.mjs'),
153-
assert: path.join(dirname, './build-system/shim/assert.mjs'),
154-
path: path.join(dirname, './build-system/shim/path.mjs'),
155162

156163
tslib: path.join(dirname, '../../node_modules/tslib/tslib.es6.js'),
157-
esquery: path.join(dirname, './build-system/shim/esquery.mjs'),
158-
globby: path.join(dirname, './build-system/shim/globby.mjs')
164+
globby: path.join(dirname, './build-system/shim/empty.mjs'),
165+
'fast-glob': path.join(dirname, './build-system/shim/empty.mjs'),
166+
module: path.join(dirname, './build-system/shim/empty.mjs')
159167
}
160168
},
161169
define: {
162-
'process.env.NODE_DEBUG': 'false',
163170
'require.cache': '{}'
164171
}
165172
},

docs/.vitepress/theme/components/eslint-code-block.vue

Lines changed: 33 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
class="eslint-code-block"
99
:filename="filename"
1010
:language="language"
11-
:preprocess="preprocess"
12-
:postprocess="postprocess"
1311
dark
1412
:format="format"
1513
:fix="fix"
@@ -20,8 +18,6 @@
2018
<script>
2119
import EslintEditor from '@ota-meshi/site-kit-eslint-editor-vue'
2220
import { markRaw } from 'vue'
23-
import * as plugin from '../../../..'
24-
const { rules, processors } = plugin.default || plugin
2521
2622
export default {
2723
name: 'ESLintCodeBlock',
@@ -61,13 +57,23 @@ export default {
6157
code: '',
6258
height: '100px',
6359
linter: null,
64-
preprocess: processors['.vue'].preprocess,
65-
postprocess: processors['.vue'].postprocess,
6660
format: {
6761
insertSpaces: true,
6862
tabSize: 2
6963
},
70-
tsEslintParser: null
64+
tsEslintParser: null,
65+
baseConfig: {
66+
files: ['**'],
67+
plugins: {},
68+
processor: 'vue/vue',
69+
languageOptions: {
70+
ecmaVersion: 'latest',
71+
sourceType: 'module',
72+
parserOptions: {
73+
ecmaFeatures: { jsx: true }
74+
}
75+
}
76+
}
7177
}
7278
},
7379
@@ -85,40 +91,13 @@ export default {
8591
}
8692
}
8793
return {
88-
globals: {
89-
console: false,
90-
// ES2015 globals
91-
ArrayBuffer: false,
92-
DataView: false,
93-
Float32Array: false,
94-
Float64Array: false,
95-
Int16Array: false,
96-
Int32Array: false,
97-
Int8Array: false,
98-
Map: false,
99-
Promise: false,
100-
Proxy: false,
101-
Reflect: false,
102-
Set: false,
103-
Symbol: false,
104-
Uint16Array: false,
105-
Uint32Array: false,
106-
Uint8Array: false,
107-
Uint8ClampedArray: false,
108-
WeakMap: false,
109-
WeakSet: false,
110-
// ES2017 globals
111-
Atomics: false,
112-
SharedArrayBuffer: false
113-
},
94+
...this.baseConfig,
11495
rules: this.rules,
115-
parser: 'vue-eslint-parser',
116-
parserOptions: {
117-
parser,
118-
ecmaVersion: 'latest',
119-
sourceType: 'module',
120-
ecmaFeatures: {
121-
jsx: true
96+
languageOptions: {
97+
...this.baseConfig?.languageOptions,
98+
parserOptions: {
99+
...this.baseConfig?.languageOptions?.parserOptions,
100+
parser
122101
}
123102
}
124103
}
@@ -150,7 +129,8 @@ export default {
150129
151130
methods: {
152131
async loadTypescriptESLint() {
153-
this.tsEslintParser = await import('@typescript-eslint/parser')
132+
const tsEslintParser = await import('@typescript-eslint/parser')
133+
this.tsEslintParser = tsEslintParser.default || tsEslintParser
154134
}
155135
},
156136
@@ -161,21 +141,24 @@ export default {
161141
const lines = this.code.split('\n').length
162142
this.height = `${Math.max(120, 20 * (1 + lines))}px`
163143
// Load linter.
164-
const [{ Linter }, { parseForESLint }] = await Promise.all([
144+
const [plugin, { Linter }, vueEslintParser, globals] = await Promise.all([
145+
import('../../../..'),
165146
import('eslint'),
166-
import('espree').then(() => import('vue-eslint-parser'))
147+
import('vue-eslint-parser'),
148+
import('globals')
167149
])
168150
if (this.langTs || this.typescript) {
169151
await this.loadTypescriptESLint()
170152
}
171153
172-
const linter = (this.linter = markRaw(new Linter()))
173-
174-
for (const ruleId of Object.keys(rules)) {
175-
linter.defineRule(`vue/${ruleId}`, rules[ruleId])
176-
}
177-
178-
linter.defineParser('vue-eslint-parser', { parseForESLint })
154+
this.linter = markRaw(new Linter())
155+
this.baseConfig.plugins.vue = markRaw(plugin.default || plugin)
156+
this.baseConfig.languageOptions.parser = markRaw(
157+
vueEslintParser.default || vueEslintParser
158+
)
159+
this.baseConfig.languageOptions.globals = markRaw({
160+
...globals.browser
161+
})
179162
}
180163
}
181164

0 commit comments

Comments
 (0)