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 ( eslintStylisticVersion === undefined ) {
23
+ return {
24
+ line,
25
+ column : errorType === 'unexpected' ? column : column - 1 ,
26
+ endLine : line ,
27
+ endColumn : column
28
+ }
29
+ }
30
+
31
+ if ( semver . lt ( eslintStylisticVersion , '3.0.0' ) ) {
32
+ return {
33
+ line,
34
+ column : column - 3 ,
35
+ endLine : undefined ,
36
+ endColumn : undefined
37
+ }
38
+ }
39
+
40
+ return {
41
+ line,
42
+ column,
43
+ endLine : line ,
44
+ endColumn : errorType === 'unexpected' ? column + 1 : column
45
+ }
46
+ }
47
+
13
48
tester . run ( 'func-call-spacing' , rule , {
14
49
valid : [
15
50
`
@@ -61,7 +96,7 @@ tester.run('func-call-spacing', rule, {
61
96
errors : [
62
97
{
63
98
message : 'Unexpected whitespace between function name and paren.' ,
64
- line : 3
99
+ ... getErrorPosition ( 3 , 23 , 'unexpected' )
65
100
}
66
101
]
67
102
} ,
@@ -80,7 +115,7 @@ tester.run('func-call-spacing', rule, {
80
115
errors : [
81
116
{
82
117
message : 'Missing space between function name and paren.' ,
83
- line : 3
118
+ ... getErrorPosition ( 3 , 23 , 'missing' )
84
119
}
85
120
]
86
121
} ,
@@ -102,7 +137,7 @@ tester.run('func-call-spacing', rule, {
102
137
errors : [
103
138
{
104
139
message : 'Unexpected whitespace between function name and paren.' ,
105
- line : 4
140
+ ... getErrorPosition ( 4 , 27 , 'unexpected' )
106
141
}
107
142
]
108
143
}
0 commit comments