Skip to content

Commit 21b0fb5

Browse files
committed
Fix vue/comma-style tests with ESLint Stylistic v5
1 parent 1be942b commit 21b0fb5

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

tests/lib/rules/comma-style.js

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

6+
const { existsSync, readFileSync } = require('node:fs')
7+
const path = require('node:path')
8+
const semver = require('semver')
69
const { RuleTester } = require('../../eslint-compat')
710
const rule = require('../../../lib/rules/comma-style')
811

912
const tester = new RuleTester({
1013
languageOptions: { parser: require('vue-eslint-parser'), ecmaVersion: 2018 }
1114
})
1215

16+
const eslintStylisticPackagePath = path.join(
17+
__dirname,
18+
'../../..',
19+
'node_modules',
20+
'@stylistic',
21+
'eslint-plugin',
22+
'package.json'
23+
)
24+
const eslintStylisticVersion = existsSync(eslintStylisticPackagePath)
25+
? JSON.parse(readFileSync(eslintStylisticPackagePath, 'utf8')).version
26+
: undefined
27+
1328
tester.run('comma-style', rule, {
1429
valid: [
1530
`<template>
@@ -34,13 +49,18 @@ tester.run('comma-style', rule, {
3449
</template>`,
3550
options: ['first', { exceptions: { ArrowFunctionExpression: false } }]
3651
},
37-
`
52+
...(eslintStylisticVersion === undefined ||
53+
semver.lt(eslintStylisticVersion, '5.0.0')
54+
? [
55+
`
3856
<template>
3957
<CustomButton v-slot="a,
4058
b
4159
,c" />
4260
</template>
43-
`,
61+
`
62+
]
63+
: []),
4464
{
4565
code: `
4666
<template>
@@ -52,6 +72,36 @@ tester.run('comma-style', rule, {
5272
}
5373
],
5474
invalid: [
75+
...(eslintStylisticVersion !== undefined &&
76+
semver.gte(eslintStylisticVersion, '5.0.0')
77+
? [
78+
{
79+
code: `
80+
<template>
81+
<CustomButton v-slot="a,
82+
b
83+
,c" />
84+
</template>
85+
`,
86+
output: `
87+
<template>
88+
<CustomButton v-slot="a,
89+
b,
90+
c" />
91+
</template>
92+
`,
93+
errors: [
94+
{
95+
message: "',' should be placed last.",
96+
line: 5,
97+
column: 13,
98+
endLine: 5,
99+
endColumn: 14
100+
}
101+
]
102+
}
103+
]
104+
: []),
55105
{
56106
code: `
57107
<template>

0 commit comments

Comments
 (0)