3
3
*/
4
4
'use strict'
5
5
6
+ const { existsSync, readFileSync } = require ( 'node:fs' )
7
+ const path = require ( 'node:path' )
8
+ const semver = require ( 'semver' )
6
9
const { RuleTester } = require ( '../../eslint-compat' )
7
10
const rule = require ( '../../../lib/rules/comma-style' )
8
11
9
12
const tester = new RuleTester ( {
10
13
languageOptions : { parser : require ( 'vue-eslint-parser' ) , ecmaVersion : 2018 }
11
14
} )
12
15
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
+
13
28
tester . run ( 'comma-style' , rule , {
14
29
valid : [
15
30
`<template>
@@ -34,13 +49,18 @@ tester.run('comma-style', rule, {
34
49
</template>` ,
35
50
options : [ 'first' , { exceptions : { ArrowFunctionExpression : false } } ]
36
51
} ,
37
- `
52
+ ...( eslintStylisticVersion === undefined ||
53
+ semver . lt ( eslintStylisticVersion , '5.0.0' )
54
+ ? [
55
+ `
38
56
<template>
39
57
<CustomButton v-slot="a,
40
58
b
41
59
,c" />
42
60
</template>
43
- ` ,
61
+ `
62
+ ]
63
+ : [ ] ) ,
44
64
{
45
65
code : `
46
66
<template>
@@ -52,6 +72,36 @@ tester.run('comma-style', rule, {
52
72
}
53
73
] ,
54
74
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
+ : [ ] ) ,
55
105
{
56
106
code : `
57
107
<template>
0 commit comments