Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fd6fc41

Browse files
Test support for multiple versions of ESLint Stylistic (#2884)
1 parent ee3955e commit fd6fc41

File tree

6 files changed

+162
-24
lines changed

6 files changed

+162
-24
lines changed

‎.changeset/great-ravens-happen.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 [`@stylistic/eslint-plugin`](https://eslint.style/) as optional peer dependency

‎.github/workflows/CI.yml‎

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ jobs:
3131
strategy:
3232
matrix:
3333
node: [18, 20, 21, 'lts/*']
34-
eslint: [9]
35-
include:
36-
# On old ESLint version
37-
- node: 18
38-
eslint: 8
39-
4034
runs-on: ubuntu-latest
4135
steps:
4236
- name: Checkout
@@ -47,8 +41,23 @@ jobs:
4741
node-version: ${{ matrix.node }}
4842
- name: Install Packages
4943
run: npm install
50-
- name: Install ESLint v${{ matrix.eslint }}
51-
run: npm install --save-dev eslint@${{ matrix.eslint }} -f
44+
- name: Test
45+
run: npm test
46+
47+
test-with-eslint-v8:
48+
name: Test with ESLint v8
49+
runs-on: ubuntu-latest
50+
steps:
51+
- name: Checkout
52+
uses: actions/checkout@v4
53+
- name: Install Node.js v18
54+
uses: actions/setup-node@v4
55+
with:
56+
node-version: 18
57+
- name: Install Packages
58+
run: npm install
59+
- name: Install ESLint v8
60+
run: npm install --save-dev eslint@8 --force
5261
- name: Test
5362
run: npm test
5463

@@ -63,7 +72,25 @@ jobs:
6372
- name: Install Packages
6473
run: npm install
6574
- name: Uninstall @stylistic/eslint-plugin
66-
run: npm uninstall -D @stylistic/eslint-plugin
75+
run: npm uninstall @stylistic/eslint-plugin
76+
- name: Test
77+
run: npm test
78+
79+
test-with-old-eslint-stylistic:
80+
name: Test with old ESLint Stylistic
81+
strategy:
82+
matrix:
83+
stylistic: [2, 3, 4]
84+
runs-on: ubuntu-latest
85+
steps:
86+
- name: Checkout
87+
uses: actions/checkout@v4
88+
- name: Install Node.js
89+
uses: actions/setup-node@v4
90+
- name: Install Packages
91+
run: npm install
92+
- name: Install @stylistic/eslint-plugin v${{ matrix.stylistic }}
93+
run: npm install -D @stylistic/eslint-plugin@${{ matrix.stylistic }} --force
6794
- name: Test
6895
run: npm test
6996

@@ -77,7 +104,7 @@ jobs:
77104
uses: actions/setup-node@v4
78105
- name: Install Packages
79106
run: npm install
80-
- name: Install @typescript-eslint/parser@7
81-
run: npm install -D @typescript-eslint/parser@7 -f
107+
- name: Install @typescript-eslint/parser v7
108+
run: npm install -D @typescript-eslint/parser@7 --force
82109
- name: Test
83110
run: npm test

‎package.json‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,15 @@
5858
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
5959
},
6060
"peerDependencies": {
61+
"@stylistic/eslint-plugin": "^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0",
62+
"@typescript-eslint/parser": "^7.0.0 || ^8.0.0",
6163
"eslint": "^8.57.0 || ^9.0.0",
62-
"vue-eslint-parser": "^10.0.0",
63-
"@typescript-eslint/parser": "^7.0.0 || ^8.0.0"
64+
"vue-eslint-parser": "^10.0.0"
6465
},
6566
"peerDependenciesMeta": {
67+
"@stylistic/eslint-plugin": {
68+
"optional": true
69+
},
6670
"@typescript-eslint/parser": {
6771
"optional": true
6872
}
@@ -78,7 +82,7 @@
7882
"devDependencies": {
7983
"@changesets/cli": "^2.29.2",
8084
"@ota-meshi/site-kit-eslint-editor-vue": "^0.2.4",
81-
"@stylistic/eslint-plugin": "^2.12.1",
85+
"@stylistic/eslint-plugin": "^5.2.2",
8286
"@svitejs/changesets-changelog-github-compact": "^1.2.0",
8387
"@types/eslint": "^8.56.2",
8488
"@types/natural-compare": "^1.4.3",

‎tests/lib/rules/comma-style.js‎

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
*/
44
'use strict'
55

6+
const semver = require('semver')
67
const { RuleTester } = require('../../eslint-compat')
78
const rule = require('../../../lib/rules/comma-style')
9+
const { eslintStylisticVersion } = require('../../test-utils/eslint-stylistic')
810

911
const tester = new RuleTester({
1012
languageOptions: { parser: require('vue-eslint-parser'), ecmaVersion: 2018 }
@@ -34,13 +36,6 @@ tester.run('comma-style', rule, {
3436
</template>`,
3537
options: ['first', { exceptions: { ArrowFunctionExpression: false } }]
3638
},
37-
`
38-
<template>
39-
<CustomButton v-slot="a,
40-
b
41-
,c" />
42-
</template>
43-
`,
4439
{
4540
code: `
4641
<template>
@@ -173,3 +168,53 @@ tester.run('comma-style', rule, {
173168
}
174169
]
175170
})
171+
172+
if (
173+
eslintStylisticVersion === undefined ||
174+
semver.lt(eslintStylisticVersion, '3.0.0') ||
175+
semver.satisfies(process.version, '<19.0.0 || ^21.0.0')
176+
) {
177+
tester.run('comma-style', rule, {
178+
valid: [
179+
`
180+
<template>
181+
<CustomButton v-slot="a,
182+
b
183+
,c" />
184+
</template>
185+
`
186+
],
187+
invalid: []
188+
})
189+
} else {
190+
tester.run('comma-style', rule, {
191+
valid: [],
192+
invalid: [
193+
{
194+
code: `
195+
<template>
196+
<CustomButton v-slot="a,
197+
b
198+
,c" />
199+
</template>
200+
`,
201+
output: `
202+
<template>
203+
<CustomButton v-slot="a,
204+
b,
205+
c" />
206+
</template>
207+
`,
208+
errors: [
209+
{
210+
message: "',' should be placed last.",
211+
line: 5,
212+
column: 13,
213+
endLine: 5,
214+
endColumn: 14
215+
}
216+
]
217+
}
218+
]
219+
})
220+
}

‎tests/lib/rules/func-call-spacing.js‎

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,54 @@
33
*/
44
'use strict'
55

6+
const semver = require('semver')
67
const { RuleTester } = require('../../eslint-compat')
78
const rule = require('../../../lib/rules/func-call-spacing')
9+
const { eslintStylisticVersion } = require('../../test-utils/eslint-stylistic')
810

911
const tester = new RuleTester({
1012
languageOptions: { parser: require('vue-eslint-parser'), ecmaVersion: 2020 }
1113
})
1214

15+
/**
16+
* @param {number} line
17+
* @param {number} column
18+
* @param {'unexpected' | 'missing'} errorType
19+
* @returns {{line: number, column: number, endLine: number, endColumn: number}}
20+
*/
21+
function getErrorPosition(line, column, errorType) {
22+
if (
23+
eslintStylisticVersion !== undefined &&
24+
semver.lt(eslintStylisticVersion, '3.0.0')
25+
) {
26+
return {
27+
line,
28+
column: column - 3,
29+
endLine: undefined,
30+
endColumn: undefined
31+
}
32+
}
33+
34+
if (
35+
eslintStylisticVersion === undefined ||
36+
semver.satisfies(process.version, '<19.0.0 || ^21.0.0')
37+
) {
38+
return {
39+
line,
40+
column: errorType === 'unexpected' ? column : column - 1,
41+
endLine: line,
42+
endColumn: column
43+
}
44+
}
45+
46+
return {
47+
line,
48+
column,
49+
endLine: line,
50+
endColumn: errorType === 'unexpected' ? column + 1 : column
51+
}
52+
}
53+
1354
tester.run('func-call-spacing', rule, {
1455
valid: [
1556
`
@@ -61,7 +102,7 @@ tester.run('func-call-spacing', rule, {
61102
errors: [
62103
{
63104
message: 'Unexpected whitespace between function name and paren.',
64-
line: 3
105+
...getErrorPosition(3,23,'unexpected')
65106
}
66107
]
67108
},
@@ -80,7 +121,7 @@ tester.run('func-call-spacing', rule, {
80121
errors: [
81122
{
82123
message: 'Missing space between function name and paren.',
83-
line: 3
124+
...getErrorPosition(3,23,'missing')
84125
}
85126
]
86127
},
@@ -102,7 +143,7 @@ tester.run('func-call-spacing', rule, {
102143
errors: [
103144
{
104145
message: 'Unexpected whitespace between function name and paren.',
105-
line: 4
146+
...getErrorPosition(4,27,'unexpected')
106147
}
107148
]
108149
}

‎tests/test-utils/eslint-stylistic.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { existsSync, readFileSync } = require('node:fs')
2+
const path = require('node:path')
3+
4+
const eslintStylisticPackagePath = path.join(
5+
__dirname,
6+
'../..',
7+
'node_modules',
8+
'@stylistic',
9+
'eslint-plugin',
10+
'package.json'
11+
)
12+
const eslintStylisticVersion = existsSync(eslintStylisticPackagePath)
13+
? JSON.parse(readFileSync(eslintStylisticPackagePath, 'utf8')).version
14+
: undefined
15+
16+
module.exports = { eslintStylisticVersion }

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /