Skip to content

Commit c7962f0

Browse files
committed
Fix vue/comma-style tests with newer ESLint Stylistic versions
1 parent 1be942b commit c7962f0

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

tests/lib/rules/comma-style.js

Lines changed: 39 additions & 2 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,18 @@ tester.run('comma-style', rule, {
3436
</template>`,
3537
options: ['first', { exceptions: { ArrowFunctionExpression: false } }]
3638
},
37-
`
39+
...(eslintStylisticVersion === undefined ||
40+
semver.lt(eslintStylisticVersion, '3.0.0')
41+
? [
42+
`
3843
<template>
3944
<CustomButton v-slot="a,
4045
b
4146
,c" />
4247
</template>
43-
`,
48+
`
49+
]
50+
: []),
4451
{
4552
code: `
4653
<template>
@@ -52,6 +59,36 @@ tester.run('comma-style', rule, {
5259
}
5360
],
5461
invalid: [
62+
...(eslintStylisticVersion !== undefined &&
63+
semver.gte(eslintStylisticVersion, '3.0.0')
64+
? [
65+
{
66+
code: `
67+
<template>
68+
<CustomButton v-slot="a,
69+
b
70+
,c" />
71+
</template>
72+
`,
73+
output: `
74+
<template>
75+
<CustomButton v-slot="a,
76+
b,
77+
c" />
78+
</template>
79+
`,
80+
errors: [
81+
{
82+
message: "',' should be placed last.",
83+
line: 5,
84+
column: 13,
85+
endLine: 5,
86+
endColumn: 14
87+
}
88+
]
89+
}
90+
]
91+
: []),
5592
{
5693
code: `
5794
<template>

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)