Skip to content

Commit 3a4aa1a

Browse files
authored
Fix reporting "Use the latest vue-eslint-parser" message in non-vue files. (#1262)
1 parent 872c0b8 commit 3a4aa1a

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

lib/rules/no-multi-spaces.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
'use strict'
66

7+
const path = require('path')
8+
79
// ------------------------------------------------------------------------------
810
// Rule Definition
911
// ------------------------------------------------------------------------------
@@ -50,11 +52,14 @@ module.exports = {
5052
return {
5153
Program(node) {
5254
if (context.parserServices.getTemplateBodyTokenStore == null) {
53-
context.report({
54-
loc: { line: 1, column: 0 },
55-
message:
56-
'Use the latest vue-eslint-parser. See also https://eslint.vuejs.org/user-guide/#what-is-the-use-the-latest-vue-eslint-parser-error.'
57-
})
55+
const filename = context.getFilename()
56+
if (path.extname(filename) === '.vue') {
57+
context.report({
58+
loc: { line: 1, column: 0 },
59+
message:
60+
'Use the latest vue-eslint-parser. See also https://eslint.vuejs.org/user-guide/#what-is-the-use-the-latest-vue-eslint-parser-error.'
61+
})
62+
}
5863
return
5964
}
6065
if (!node.templateBody) {

lib/utils/index.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -1531,11 +1531,14 @@ function defineTemplateBodyVisitor(
15311531
scriptVisitor
15321532
) {
15331533
if (context.parserServices.defineTemplateBodyVisitor == null) {
1534-
context.report({
1535-
loc: { line: 1, column: 0 },
1536-
message:
1537-
'Use the latest vue-eslint-parser. See also https://eslint.vuejs.org/user-guide/#what-is-the-use-the-latest-vue-eslint-parser-error'
1538-
})
1534+
const filename = context.getFilename()
1535+
if (path.extname(filename) === '.vue') {
1536+
context.report({
1537+
loc: { line: 1, column: 0 },
1538+
message:
1539+
'Use the latest vue-eslint-parser. See also https://eslint.vuejs.org/user-guide/#what-is-the-use-the-latest-vue-eslint-parser-error.'
1540+
})
1541+
}
15391542
return {}
15401543
}
15411544
return context.parserServices.defineTemplateBodyVisitor(

tests/lib/rules-without-vue-eslint-parser.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
const Linter = require('eslint').Linter
88
const parser = require('babel-eslint')
99
const rules = require('../..').rules
10+
const assert = require('assert')
1011

1112
describe("Don't crash even if without vue-eslint-parser.", () => {
1213
const code = '<template><div>TEST</div></template>'
@@ -25,7 +26,16 @@ describe("Don't crash even if without vue-eslint-parser.", () => {
2526
}
2627
linter.defineParser('babel-eslint', parser)
2728
linter.defineRule(ruleId, rules[key])
28-
linter.verifyAndFix(code, config, 'test.vue')
29+
const resultVue = linter.verifyAndFix(code, config, 'test.vue')
30+
for (const { message } of resultVue.messages) {
31+
assert.strictEqual(
32+
message,
33+
'Use the latest vue-eslint-parser. See also https://eslint.vuejs.org/user-guide/#what-is-the-use-the-latest-vue-eslint-parser-error.'
34+
)
35+
}
36+
37+
const resultJs = linter.verifyAndFix(code, config, 'test.js')
38+
assert.strictEqual(resultJs.messages.length, 0)
2939
})
3040
}
3141
})

0 commit comments

Comments
 (0)