Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/rules/no-multi-spaces.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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)
})
}
})