diff --git a/lib/rules/no-multi-spaces.js b/lib/rules/no-multi-spaces.js index ef1fee678..aa8b70a22 100644 --- a/lib/rules/no-multi-spaces.js +++ b/lib/rules/no-multi-spaces.js @@ -4,6 +4,8 @@ */ 'use strict' +const path = require('path') + // ------------------------------------------------------------------------------ // Rule Definition // ------------------------------------------------------------------------------ @@ -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) { diff --git a/lib/utils/index.js b/lib/utils/index.js index 5abb635ed..814517e39 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -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( diff --git a/tests/lib/rules-without-vue-eslint-parser.js b/tests/lib/rules-without-vue-eslint-parser.js index cd91f7915..b7c585134 100644 --- a/tests/lib/rules-without-vue-eslint-parser.js +++ b/tests/lib/rules-without-vue-eslint-parser.js @@ -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 = '' @@ -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) }) } })