Skip to content

Commit 50bf912

Browse files
committed
⚒ upgrade core rule tests
Acorn now throws right syntax error at the arrow function that is at the argument of unary expressions. But some core rule tests gets fail for that syntax error, so I have to update ESLint submodule to f44a6b4fd92602af8e2c75d5852f796ec064aa8e.
1 parent 84dac95 commit 50bf912

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

test/core-rules.js

+54-7
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ function wrapCode(code) {
6262
/**
6363
* Modify the given test pattern to test with vue-eslint-parser.
6464
*
65+
* @param {string} ruleId The rule ID.
6566
* @param {string|object} pattern - The test pattern to be modified.
6667
* @returns {object|null} The modified pattern.
6768
*/
68-
function modifyPattern(pattern) {
69+
//eslint-disable-next-line complexity
70+
function modifyPattern(ruleId, pattern) {
6971
if (typeof pattern === "string") {
7072
if (pattern.startsWith("#!")) {
7173
return null
@@ -76,6 +78,9 @@ function modifyPattern(pattern) {
7678
parser: PARSER_PATH,
7779
}
7880
}
81+
82+
// If a test case depends on filename or special parser (returns constant AST
83+
// object), we cannot rewrite the test case with `vue-eslint-parser`.
7984
if (
8085
pattern.parser != null ||
8186
pattern.filename != null ||
@@ -84,22 +89,60 @@ function modifyPattern(pattern) {
8489
return null
8590
}
8691

92+
// Ignore for now
93+
if (
94+
ruleId === "newline-per-chained-call" &&
95+
pattern.code === "foo.bar()['foo' + \u2029 + 'bar']()"
96+
) {
97+
return null
98+
}
99+
100+
// Wrap the code by `<script>` tag.
87101
pattern.filename = "test.vue"
88102
pattern.parser = PARSER_PATH
89103
pattern.code = wrapCode(pattern.code)
90104
if (pattern.output != null) {
91105
pattern.output = wrapCode(pattern.output)
92106
}
107+
93108
if (Array.isArray(pattern.errors)) {
94109
for (const error of pattern.errors) {
95110
if (typeof error === "object" && !processed.has(error)) {
96111
processed.add(error)
97112

98-
if (error.line != null) {
99-
error.line = Number(error.line) + 1
113+
// The line number +1 because `<script>\n` is inserted.
114+
if (typeof error.line === "number") {
115+
error.line += 1
116+
}
117+
if (typeof error.endLine === "number") {
118+
error.endLine += 1
100119
}
101-
if (error.endLine != null) {
102-
error.endLine = Number(error.endLine) + 1
120+
121+
// `semi` rule is special a bit.
122+
// The `endLine` is explicitly undefined if it inserts semi into EOF.
123+
// The `endColumn` is explicitly undefined if it inserts semi into EOF.
124+
// Those becomes non-EOF because `\n</script>` is inserted.
125+
if (ruleId === "semi") {
126+
if (
127+
Object.hasOwnProperty.call(error, "endLine") &&
128+
error.endLine === undefined
129+
) {
130+
const lines = pattern.code.split(/\r\n|[\r\n]/gu)
131+
error.endLine = lines.length
132+
}
133+
if (
134+
Object.hasOwnProperty.call(error, "endColumn") &&
135+
error.endColumn === undefined
136+
) {
137+
error.endColumn = 1
138+
}
139+
}
140+
141+
// Wrap the code by `<script>` tag.
142+
if (Array.isArray(error.suggestions)) {
143+
for (const suggestion of error.suggestions) {
144+
suggestion.output = wrapCode(suggestion.output)
145+
}
103146
}
104147
}
105148
}
@@ -120,8 +163,12 @@ function modifyPattern(pattern) {
120163
*/
121164
function overrideRun(ruleId, impl, patterns) {
122165
return originalRun.call(this, ruleId, impl, {
123-
valid: patterns.valid.map(modifyPattern).filter(Boolean),
124-
invalid: patterns.invalid.map(modifyPattern).filter(Boolean),
166+
valid: patterns.valid
167+
.map(pattern => modifyPattern(ruleId, pattern))
168+
.filter(Boolean),
169+
invalid: patterns.invalid
170+
.map(pattern => modifyPattern(ruleId, pattern))
171+
.filter(Boolean),
125172
})
126173
}
127174

test/fixtures/eslint

Submodule eslint updated 572 files

0 commit comments

Comments
 (0)