Skip to content

Commit e45a2c2

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

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

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

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

6+
const semver = require('semver')
67
const { RuleTester } = 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: 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+
if (semver.satisfies(process.version, '<19.0.0 || ^21.0.0')) {
41+
return {
42+
line,
43+
column: errorType === 'unexpected' ? column : column - 1,
44+
endLine: line,
45+
endColumn: column
46+
}
47+
}
48+
49+
return {
50+
line,
51+
column,
52+
endLine: line,
53+
endColumn: errorType === 'unexpected' ? column + 1 : column
54+
}
55+
}
56+
1357
tester.run('func-call-spacing', rule, {
1458
valid: [
1559
`
@@ -61,7 +105,7 @@ tester.run('func-call-spacing', rule, {
61105
errors: [
62106
{
63107
message: 'Unexpected whitespace between function name and paren.',
64-
line: 3
108+
...getErrorPosition(3, 23, 'unexpected')
65109
}
66110
]
67111
},
@@ -80,7 +124,7 @@ tester.run('func-call-spacing', rule, {
80124
errors: [
81125
{
82126
message: 'Missing space between function name and paren.',
83-
line: 3
127+
...getErrorPosition(3, 23, 'missing')
84128
}
85129
]
86130
},
@@ -102,7 +146,7 @@ tester.run('func-call-spacing', rule, {
102146
errors: [
103147
{
104148
message: 'Unexpected whitespace between function name and paren.',
105-
line: 4
149+
...getErrorPosition(4, 27, 'unexpected')
106150
}
107151
]
108152
}

0 commit comments

Comments
 (0)