Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reporting "Use the latest vue-eslint-parser" message in non-vue files. #1262

Merged
merged 1 commit into from Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
})
}
})