3
3
*/
4
4
'use strict'
5
5
6
- const { RuleTester } = require ( '../../eslint-compat' )
6
+ const semver = require ( 'semver' )
7
+ const { RuleTester, ESLint } = 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 :
26
+ errorType === 'missing' && semver . gte ( ESLint . version , '9.0.0' )
27
+ ? column - 1
28
+ : column ,
29
+ endLine : line ,
30
+ endColumn : column
31
+ }
32
+ }
33
+
34
+ if ( semver . lt ( eslintStylisticVersion , '3.0.0' ) ) {
35
+ return {
36
+ line,
37
+ column : column - 3 ,
38
+ endLine : undefined ,
39
+ endColumn : undefined
40
+ }
41
+ }
42
+
43
+ return {
44
+ line,
45
+ column,
46
+ endLine : line ,
47
+ endColumn : errorType === 'unexpected' ? column + 1 : column
48
+ }
49
+ }
50
+
13
51
tester . run ( 'func-call-spacing' , rule , {
14
52
valid : [
15
53
`
@@ -61,7 +99,7 @@ tester.run('func-call-spacing', rule, {
61
99
errors : [
62
100
{
63
101
message : 'Unexpected whitespace between function name and paren.' ,
64
- line : 3
102
+ ... getErrorPosition ( 3 , 23 , 'unexpected' )
65
103
}
66
104
]
67
105
} ,
@@ -80,7 +118,7 @@ tester.run('func-call-spacing', rule, {
80
118
errors : [
81
119
{
82
120
message : 'Missing space between function name and paren.' ,
83
- line : 3
121
+ ... getErrorPosition ( 3 , 23 , 'missing' )
84
122
}
85
123
]
86
124
} ,
@@ -102,7 +140,7 @@ tester.run('func-call-spacing', rule, {
102
140
errors : [
103
141
{
104
142
message : 'Unexpected whitespace between function name and paren.' ,
105
- line : 4
143
+ ... getErrorPosition ( 4 , 27 , 'unexpected' )
106
144
}
107
145
]
108
146
}
0 commit comments