Skip to content

Commit

Permalink
Fix reporting "Use the latest vue-eslint-parser" message in non-vue f…
Browse files Browse the repository at this point in the history
…iles. (#1262)
  • Loading branch information
ota-meshi committed Jul 31, 2020
1 parent 872c0b8 commit 3a4aa1a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
15 changes: 10 additions & 5 deletions lib/rules/no-multi-spaces.js
Expand Up @@ -4,6 +4,8 @@
*/
'use strict'

const path = require('path')

// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
Expand Down Expand Up @@ -50,11 +52,14 @@ module.exports = {
return {
Program(node) {
if (context.parserServices.getTemplateBodyTokenStore == null) {
context.report({
loc: { line: 1, column: 0 },
message:
'Use the latest vue-eslint-parser. See also https://eslint.vuejs.org/user-guide/#what-is-the-use-the-latest-vue-eslint-parser-error.'
})
const filename = context.getFilename()
if (path.extname(filename) === '.vue') {
context.report({
loc: { line: 1, column: 0 },
message:
'Use the latest vue-eslint-parser. See also https://eslint.vuejs.org/user-guide/#what-is-the-use-the-latest-vue-eslint-parser-error.'
})
}
return
}
if (!node.templateBody) {
Expand Down
13 changes: 8 additions & 5 deletions lib/utils/index.js
Expand Up @@ -1531,11 +1531,14 @@ function defineTemplateBodyVisitor(
scriptVisitor
) {
if (context.parserServices.defineTemplateBodyVisitor == null) {
context.report({
loc: { line: 1, column: 0 },
message:
'Use the latest vue-eslint-parser. See also https://eslint.vuejs.org/user-guide/#what-is-the-use-the-latest-vue-eslint-parser-error'
})
const filename = context.getFilename()
if (path.extname(filename) === '.vue') {
context.report({
loc: { line: 1, column: 0 },
message:
'Use the latest vue-eslint-parser. See also https://eslint.vuejs.org/user-guide/#what-is-the-use-the-latest-vue-eslint-parser-error.'
})
}
return {}
}
return context.parserServices.defineTemplateBodyVisitor(
Expand Down
12 changes: 11 additions & 1 deletion tests/lib/rules-without-vue-eslint-parser.js
Expand Up @@ -7,6 +7,7 @@
const Linter = require('eslint').Linter
const parser = require('babel-eslint')
const rules = require('../..').rules
const assert = require('assert')

describe("Don't crash even if without vue-eslint-parser.", () => {
const code = '<template><div>TEST</div></template>'
Expand All @@ -25,7 +26,16 @@ describe("Don't crash even if without vue-eslint-parser.", () => {
}
linter.defineParser('babel-eslint', parser)
linter.defineRule(ruleId, rules[key])
linter.verifyAndFix(code, config, 'test.vue')
const resultVue = linter.verifyAndFix(code, config, 'test.vue')
for (const { message } of resultVue.messages) {
assert.strictEqual(
message,
'Use the latest vue-eslint-parser. See also https://eslint.vuejs.org/user-guide/#what-is-the-use-the-latest-vue-eslint-parser-error.'
)
}

const resultJs = linter.verifyAndFix(code, config, 'test.js')
assert.strictEqual(resultJs.messages.length, 0)
})
}
})

0 comments on commit 3a4aa1a

Please sign in to comment.