Skip to content

Commit d88f17f

Browse files
committed
Fix vue/func-call-spacing tests with newer ESLint Stylistic versions
1 parent bf0cd48 commit d88f17f

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

tests/lib/rules/func-call-spacing.js

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

6-
const { RuleTester } = require('../../eslint-compat')
6+
const semver = require('semver')
7+
const { RuleTester, ESLint } = require('../../eslint-compat')
78
const rule = require('../../../lib/rules/func-call-spacing')
9+
const { eslintStylisticVersion } = require('../../test-utils/eslint-stylistic')
810

911
const tester = new RuleTester({
1012
languageOptions: { parser: require('vue-eslint-parser'), ecmaVersion: 2020 }
1113
})
1214

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+
1351
tester.run('func-call-spacing', rule, {
1452
valid: [
1553
`
@@ -61,7 +99,7 @@ tester.run('func-call-spacing', rule, {
6199
errors: [
62100
{
63101
message: 'Unexpected whitespace between function name and paren.',
64-
line: 3
102+
...getErrorPosition(3, 23, 'unexpected')
65103
}
66104
]
67105
},
@@ -80,7 +118,7 @@ tester.run('func-call-spacing', rule, {
80118
errors: [
81119
{
82120
message: 'Missing space between function name and paren.',
83-
line: 3
121+
...getErrorPosition(3, 23, 'missing')
84122
}
85123
]
86124
},
@@ -102,7 +140,7 @@ tester.run('func-call-spacing', rule, {
102140
errors: [
103141
{
104142
message: 'Unexpected whitespace between function name and paren.',
105-
line: 4
143+
...getErrorPosition(4, 27, 'unexpected')
106144
}
107145
]
108146
}

0 commit comments

Comments
 (0)