Skip to content

Commit 5978ef4

Browse files
committed
Fix vue/comma-style tests with newer ESLint Stylistic versions
1 parent bbfdbb0 commit 5978ef4

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

tests/lib/rules/comma-style.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@
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 }
1113
})
1214

15+
const isOldStylistic =
16+
eslintStylisticVersion === undefined ||
17+
semver.lt(eslintStylisticVersion, '3.0.0') ||
18+
semver.satisfies(process.version, '<19.0.0 || ^21.0.0')
19+
1320
tester.run('comma-style', rule, {
1421
valid: [
1522
`<template>
@@ -34,13 +41,17 @@ tester.run('comma-style', rule, {
3441
</template>`,
3542
options: ['first', { exceptions: { ArrowFunctionExpression: false } }]
3643
},
37-
`
44+
...(isOldStylistic
45+
? [
46+
`
3847
<template>
3948
<CustomButton v-slot="a,
4049
b
4150
,c" />
4251
</template>
43-
`,
52+
`
53+
]
54+
: []),
4455
{
4556
code: `
4657
<template>
@@ -52,6 +63,35 @@ tester.run('comma-style', rule, {
5263
}
5364
],
5465
invalid: [
66+
...(isOldStylistic
67+
? []
68+
: [
69+
{
70+
code: `
71+
<template>
72+
<CustomButton v-slot="a,
73+
b
74+
,c" />
75+
</template>
76+
`,
77+
output: `
78+
<template>
79+
<CustomButton v-slot="a,
80+
b,
81+
c" />
82+
</template>
83+
`,
84+
errors: [
85+
{
86+
message: "',' should be placed last.",
87+
line: 5,
88+
column: 13,
89+
endLine: 5,
90+
endColumn: 14
91+
}
92+
]
93+
}
94+
]),
5595
{
5696
code: `
5797
<template>

tests/test-utils/eslint-stylistic.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
// eslint-disable-next-line no-console
17+
console.log('ESLint Stylistic version:', eslintStylisticVersion)
18+
19+
module.exports = { eslintStylisticVersion }

0 commit comments

Comments
 (0)