3
3
*/
4
4
'use strict'
5
5
6
+ const semver = require ( 'semver' )
6
7
const { RuleTester } = require ( '../../eslint-compat' )
7
8
const rule = require ( '../../../lib/rules/func-call-spacing' )
9
+ const { eslintStylisticVersion } = require ( '../../test-utils/eslint-stylistic' )
8
10
9
11
const tester = new RuleTester ( {
10
12
languageOptions : { parser : require ( 'vue-eslint-parser' ) , ecmaVersion : 2020 }
11
13
} )
12
14
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
+
13
54
tester . run ( 'func-call-spacing' , rule , {
14
55
valid : [
15
56
`
@@ -61,7 +102,7 @@ tester.run('func-call-spacing', rule, {
61
102
errors : [
62
103
{
63
104
message : 'Unexpected whitespace between function name and paren.' ,
64
- line : 3
105
+ ... getErrorPosition ( 3 , 23 , 'unexpected' )
65
106
}
66
107
]
67
108
} ,
@@ -80,7 +121,7 @@ tester.run('func-call-spacing', rule, {
80
121
errors : [
81
122
{
82
123
message : 'Missing space between function name and paren.' ,
83
- line : 3
124
+ ... getErrorPosition ( 3 , 23 , 'missing' )
84
125
}
85
126
]
86
127
} ,
@@ -102,7 +143,7 @@ tester.run('func-call-spacing', rule, {
102
143
errors : [
103
144
{
104
145
message : 'Unexpected whitespace between function name and paren.' ,
105
- line : 4
146
+ ... getErrorPosition ( 4 , 27 , 'unexpected' )
106
147
}
107
148
]
108
149
}
0 commit comments