diff --git a/README.md b/README.md index b070b4098..f0798eb06 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,14 @@ > Official ESLint plugin for Vue.js +## :exclamation: Attention - this is documentation for version `5.x` :exclamation: + +This branch contains `eslint-plugin-vue@next` which is a pre-released `5.0`, but it's not the default version that you get with `npm install eslint-plugin-vue`. In order to install this you need to specify either `"eslint-plugin-vue": "next"` in `package.json` or do `npm install eslint-plugin-vue@next`. + +Please try it and report any issues that you might have encountered. + +If you want to check previous releases [go here](https://github.com/vuejs/eslint-plugin-vue/releases). + ## :art: Playground on the Web You can try this plugin on the Web. @@ -14,15 +22,13 @@ You can try this plugin on the Web. ## :grey_exclamation: Requirements -- [ESLint](http://eslint.org/) `>=3.18.0`. - - `>=4.7.0` to use `eslint --fix`. - - `>=4.14.0` to use with `babel-eslint`. -- Node.js `>=4.0.0` +- [ESLint](http://eslint.org/) `^5.0.0`. +- Node.js `>=6.5.0` ## :cd: Installation ```bash -npm install --save-dev eslint eslint-plugin-vue +npm install --save-dev eslint eslint-plugin-vue@next ``` ## :rocket: Usage diff --git a/circle.yml b/circle.yml index 96c519a76..3d1494456 100644 --- a/circle.yml +++ b/circle.yml @@ -1,16 +1,16 @@ machine: node: - version: 8 + version: 10 dependencies: pre: - nvm install 6 - - nvm install 4 + - nvm install 8 test: override: - - nvm use 4 && npm test - nvm use 6 && npm test - nvm use 8 && npm test + - nvm use 10 && npm test # Test for the minimum version we are supporting. - - nvm use 8 && npm i eslint@3.18.0 --no-save && $(npm bin)/mocha tests/lib/rules/*.js --reporter dot + - nvm use 10 && npm i eslint@5.0.0 --no-save && $(npm bin)/mocha tests/lib/rules/*.js --reporter dot diff --git a/lib/utils/indent-common.js b/lib/utils/indent-common.js index f93379daa..afef755f5 100644 --- a/lib/utils/indent-common.js +++ b/lib/utils/indent-common.js @@ -14,7 +14,7 @@ const assert = require('assert') // Helpers // ------------------------------------------------------------------------------ -const KNOWN_NODES = new Set(['ArrayExpression', 'ArrayPattern', 'ArrowFunctionExpression', 'AssignmentExpression', 'AssignmentPattern', 'AwaitExpression', 'BinaryExpression', 'BlockStatement', 'BreakStatement', 'CallExpression', 'CatchClause', 'ClassBody', 'ClassDeclaration', 'ClassExpression', 'ConditionalExpression', 'ContinueStatement', 'DebuggerStatement', 'DoWhileStatement', 'EmptyStatement', 'ExperimentalRestProperty', 'ExperimentalSpreadProperty', 'ExportAllDeclaration', 'ExportDefaultDeclaration', 'ExportNamedDeclaration', 'ExportSpecifier', 'ExpressionStatement', 'ForInStatement', 'ForOfStatement', 'ForStatement', 'FunctionDeclaration', 'FunctionExpression', 'Identifier', 'IfStatement', 'ImportDeclaration', 'ImportDefaultSpecifier', 'ImportNamespaceSpecifier', 'ImportSpecifier', 'LabeledStatement', 'Literal', 'LogicalExpression', 'MemberExpression', 'MetaProperty', 'MethodDefinition', 'NewExpression', 'ObjectExpression', 'ObjectPattern', 'Program', 'Property', 'RestElement', 'ReturnStatement', 'SequenceExpression', 'SpreadElement', 'Super', 'SwitchCase', 'SwitchStatement', 'TaggedTemplateExpression', 'TemplateElement', 'TemplateLiteral', 'ThisExpression', 'ThrowStatement', 'TryStatement', 'UnaryExpression', 'UpdateExpression', 'VariableDeclaration', 'VariableDeclarator', 'WhileStatement', 'WithStatement', 'YieldExpression', 'VAttribute', 'VDirectiveKey', 'VDocumentFragment', 'VElement', 'VEndTag', 'VExpressionContainer', 'VForExpression', 'VIdentifier', 'VLiteral', 'VOnExpression', 'VStartTag', 'VText']) +const KNOWN_NODES = new Set(['ArrayExpression', 'ArrayPattern', 'ArrowFunctionExpression', 'AssignmentExpression', 'AssignmentPattern', 'AwaitExpression', 'BinaryExpression', 'BlockStatement', 'BreakStatement', 'CallExpression', 'CatchClause', 'ClassBody', 'ClassDeclaration', 'ClassExpression', 'ConditionalExpression', 'ContinueStatement', 'DebuggerStatement', 'DoWhileStatement', 'EmptyStatement', 'ExperimentalRestProperty', 'ExperimentalSpreadProperty', 'ExportAllDeclaration', 'ExportDefaultDeclaration', 'ExportNamedDeclaration', 'ExportSpecifier', 'ExpressionStatement', 'ForInStatement', 'ForOfStatement', 'ForStatement', 'FunctionDeclaration', 'FunctionExpression', 'Identifier', 'IfStatement', 'ImportDeclaration', 'ImportDefaultSpecifier', 'ImportNamespaceSpecifier', 'ImportSpecifier', 'LabeledStatement', 'Literal', 'LogicalExpression', 'MemberExpression', 'MetaProperty', 'MethodDefinition', 'NewExpression', 'ObjectExpression', 'ObjectPattern', 'Program', 'Property', 'RestElement', 'ReturnStatement', 'SequenceExpression', 'SpreadElement', 'Super', 'SwitchCase', 'SwitchStatement', 'TaggedTemplateExpression', 'TemplateElement', 'TemplateLiteral', 'ThisExpression', 'ThrowStatement', 'TryStatement', 'UnaryExpression', 'UpdateExpression', 'VariableDeclaration', 'VariableDeclarator', 'WhileStatement', 'WithStatement', 'YieldExpression', 'VAttribute', 'VDirectiveKey', 'VDocumentFragment', 'VElement', 'VEndTag', 'VExpressionContainer', 'VForExpression', 'VIdentifier', 'VLiteral', 'VOnExpression', 'VSlotScopeExpression', 'VStartTag', 'VText']) const LT_CHAR = /[\r\n\u2028\u2029]/ const LINES = /[^\r\n\u2028\u2029]+(?:$|\r\n|[\r\n\u2028\u2029])/g const BLOCK_COMMENT_PREFIX = /^\s*\*/ @@ -845,7 +845,7 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti if (node.expression != null && node.range[0] !== node.expression.range[0]) { const startQuoteToken = tokenStore.getFirstToken(node) const endQuoteToken = tokenStore.getLastToken(node) - const childToken = tokenStore.getFirstToken(node.expression) + const childToken = tokenStore.getTokenAfter(startQuoteToken) setOffset(childToken, 1, startQuoteToken) setOffset(endQuoteToken, 0, startQuoteToken) diff --git a/package.json b/package.json index e295c0148..d88ca41e9 100644 --- a/package.json +++ b/package.json @@ -38,24 +38,24 @@ "url": "https://github.com/vuejs/eslint-plugin-vue/issues" }, "engines": { - "node": ">=4" + "node": ">=6.5" }, "peerDependencies": { - "eslint": "^3.18.0 || ^4.0.0" + "eslint": "^5.0.0" }, "dependencies": { - "vue-eslint-parser": "^2.0.3" + "vue-eslint-parser": "^3.2.1" }, "devDependencies": { "@types/node": "^4.2.16", "babel-eslint": "^8.2.2", "chai": "^4.1.0", - "eslint": "^4.14.0", - "eslint-plugin-eslint-plugin": "^0.8.0", + "eslint": "^5.2.0", + "eslint-plugin-eslint-plugin": "^1.4.0", "eslint-plugin-html": "^4.0.1", - "eslint-plugin-vue-libs": "^2.0.0", + "eslint-plugin-vue-libs": "^3.0.0", "lodash": "^4.17.4", - "mocha": "^3.2.0", - "nyc": "^11.1.0" + "mocha": "^5.2.0", + "nyc": "^12.0.2" } } diff --git a/tests/fixtures/html-indent/binary-expression-10.vue b/tests/fixtures/html-indent/binary-expression-10.vue index 0ecd1e897..6dd5e6f34 100644 --- a/tests/fixtures/html-indent/binary-expression-10.vue +++ b/tests/fixtures/html-indent/binary-expression-10.vue @@ -1,13 +1,13 @@ diff --git a/tests/fixtures/html-indent/sequence-expression-01.vue b/tests/fixtures/html-indent/sequence-expression-01.vue index 9d3db5f79..74307fb26 100644 --- a/tests/fixtures/html-indent/sequence-expression-01.vue +++ b/tests/fixtures/html-indent/sequence-expression-01.vue @@ -1,12 +1,12 @@ diff --git a/tests/fixtures/html-indent/sequence-expression-02.vue b/tests/fixtures/html-indent/sequence-expression-02.vue index fdb4bee70..93ae519ee 100644 --- a/tests/fixtures/html-indent/sequence-expression-02.vue +++ b/tests/fixtures/html-indent/sequence-expression-02.vue @@ -1,10 +1,10 @@ diff --git a/tests/fixtures/html-indent/sequence-expression-03.vue b/tests/fixtures/html-indent/sequence-expression-03.vue index f9c4b68ab..0d8aaa85b 100644 --- a/tests/fixtures/html-indent/sequence-expression-03.vue +++ b/tests/fixtures/html-indent/sequence-expression-03.vue @@ -1,10 +1,10 @@ diff --git a/tests/fixtures/html-indent/sequence-expression-04.vue b/tests/fixtures/html-indent/sequence-expression-04.vue index c9a2d9845..5fbd60215 100644 --- a/tests/fixtures/html-indent/sequence-expression-04.vue +++ b/tests/fixtures/html-indent/sequence-expression-04.vue @@ -1,8 +1,8 @@ \ No newline at end of file + )}} + diff --git a/tests/fixtures/html-indent/slot-scope-01.vue b/tests/fixtures/html-indent/slot-scope-01.vue new file mode 100644 index 000000000..f66533ec6 --- /dev/null +++ b/tests/fixtures/html-indent/slot-scope-01.vue @@ -0,0 +1,17 @@ + + diff --git a/tests/lib/rules/name-property-casing.js b/tests/lib/rules/name-property-casing.js index d5d833352..1bdeb8769 100644 --- a/tests/lib/rules/name-property-casing.js +++ b/tests/lib/rules/name-property-casing.js @@ -16,9 +16,8 @@ const RuleTester = require('eslint').RuleTester // ------------------------------------------------------------------------------ const parserOptions = { - ecmaVersion: 6, - sourceType: 'module', - ecmaFeatures: { experimentalObjectRestSpread: true } + ecmaVersion: 2018, + sourceType: 'module' } const ruleTester = new RuleTester() diff --git a/tests/lib/rules/no-async-in-computed-properties.js b/tests/lib/rules/no-async-in-computed-properties.js index 2e7c27882..23f59965b 100644 --- a/tests/lib/rules/no-async-in-computed-properties.js +++ b/tests/lib/rules/no-async-in-computed-properties.js @@ -12,15 +12,8 @@ const rule = require('../../../lib/rules/no-async-in-computed-properties') const RuleTester = require('eslint').RuleTester const parserOptions = { - ecmaVersion: 6, - sourceType: 'module', - ecmaFeatures: { experimentalObjectRestSpread: true } -} - -const parserOptions8 = { - ecmaVersion: 8, - sourceType: 'module', - ecmaFeatures: { experimentalObjectRestSpread: true } + ecmaVersion: 2018, + sourceType: 'module' } // ------------------------------------------------------------------------------ @@ -77,7 +70,7 @@ ruleTester.run('no-async-in-computed-properties', rule, { })); } `, - parserOptions: parserOptions8 + parserOptions } ], @@ -93,7 +86,7 @@ ruleTester.run('no-async-in-computed-properties', rule, { } } `, - parserOptions: parserOptions8, + parserOptions, errors: [{ message: 'Unexpected async function declaration in "foo" computed property.', line: 4 @@ -113,7 +106,7 @@ ruleTester.run('no-async-in-computed-properties', rule, { } } `, - parserOptions: parserOptions8, + parserOptions, errors: [{ message: 'Unexpected async function declaration in "foo" computed property.', line: 4 diff --git a/tests/lib/rules/no-dupe-keys.js b/tests/lib/rules/no-dupe-keys.js index f9031d1e6..1abb67642 100644 --- a/tests/lib/rules/no-dupe-keys.js +++ b/tests/lib/rules/no-dupe-keys.js @@ -79,7 +79,7 @@ ruleTester.run('no-dupe-keys', rule, { }, } `, - parserOptions: { ecmaVersion: 8, sourceType: 'module', ecmaFeatures: { experimentalObjectRestSpread: true }} + parserOptions: { ecmaVersion: 2018, sourceType: 'module' } }, { diff --git a/tests/lib/rules/no-parsing-error.js b/tests/lib/rules/no-parsing-error.js index fcb4c351a..365bbb09e 100644 --- a/tests/lib/rules/no-parsing-error.js +++ b/tests/lib/rules/no-parsing-error.js @@ -207,7 +207,8 @@ tester.run('no-parsing-error', rule, { options: [{ 'x-invalid-namespace': false }] }, '', - '' + '', + '' ], invalid: [ { @@ -230,13 +231,6 @@ tester.run('no-parsing-error', rule, { code: '', errors: ['Parsing error: Unexpected token ;.'] }, - { - filename: 'test.vue', - code: '', - errors: [ - { message: 'Parsing error: Expected to be an expression, but got empty.', column: 18 } - ] - }, { filename: 'test.vue', code: '', diff --git a/tests/lib/rules/no-reserved-keys.js b/tests/lib/rules/no-reserved-keys.js index cc116f1dc..08c7f244c 100644 --- a/tests/lib/rules/no-reserved-keys.js +++ b/tests/lib/rules/no-reserved-keys.js @@ -12,9 +12,8 @@ const rule = require('../../../lib/rules/no-reserved-keys') const RuleTester = require('eslint').RuleTester const parserOptions = { - ecmaVersion: 7, - sourceType: 'module', - ecmaFeatures: { experimentalObjectRestSpread: true } + ecmaVersion: 2018, + sourceType: 'module' } // ------------------------------------------------------------------------------ diff --git a/tests/lib/rules/no-shared-component-data.js b/tests/lib/rules/no-shared-component-data.js index d1616dd37..ce0e0062b 100644 --- a/tests/lib/rules/no-shared-component-data.js +++ b/tests/lib/rules/no-shared-component-data.js @@ -13,9 +13,8 @@ const rule = require('../../../lib/rules/no-shared-component-data') const RuleTester = require('eslint').RuleTester const parserOptions = { - ecmaVersion: 7, - sourceType: 'module', - ecmaFeatures: { experimentalObjectRestSpread: true } + ecmaVersion: 2018, + sourceType: 'module' } // ------------------------------------------------------------------------------ diff --git a/tests/lib/rules/no-side-effects-in-computed-properties.js b/tests/lib/rules/no-side-effects-in-computed-properties.js index 3eadc45c0..55df66734 100644 --- a/tests/lib/rules/no-side-effects-in-computed-properties.js +++ b/tests/lib/rules/no-side-effects-in-computed-properties.js @@ -12,9 +12,8 @@ const rule = require('../../../lib/rules/no-side-effects-in-computed-properties' const RuleTester = require('eslint').RuleTester const parserOptions = { - ecmaVersion: 6, - sourceType: 'module', - ecmaFeatures: { experimentalObjectRestSpread: true } + ecmaVersion: 2018, + sourceType: 'module' } // ------------------------------------------------------------------------------ diff --git a/tests/lib/rules/order-in-components.js b/tests/lib/rules/order-in-components.js index 2eff407ec..236524e88 100644 --- a/tests/lib/rules/order-in-components.js +++ b/tests/lib/rules/order-in-components.js @@ -10,9 +10,8 @@ const RuleTester = require('eslint').RuleTester const ruleTester = new RuleTester() const parserOptions = { - ecmaVersion: 6, - sourceType: 'module', - ecmaFeatures: { experimentalObjectRestSpread: true } + ecmaVersion: 2018, + sourceType: 'module' } ruleTester.run('order-in-components', rule, { diff --git a/tests/lib/rules/prop-name-casing.js b/tests/lib/rules/prop-name-casing.js index cfeeaf8e8..d9a23a466 100644 --- a/tests/lib/rules/prop-name-casing.js +++ b/tests/lib/rules/prop-name-casing.js @@ -16,9 +16,8 @@ const RuleTester = require('eslint').RuleTester // ------------------------------------------------------------------------------ const parserOptions = { - ecmaVersion: 6, - sourceType: 'module', - ecmaFeatures: { experimentalObjectRestSpread: true } + ecmaVersion: 2018, + sourceType: 'module' } const ruleTester = new RuleTester() diff --git a/tests/lib/rules/require-default-prop.js b/tests/lib/rules/require-default-prop.js index df5fc0afc..efc714410 100644 --- a/tests/lib/rules/require-default-prop.js +++ b/tests/lib/rules/require-default-prop.js @@ -11,8 +11,7 @@ const rule = require('../../../lib/rules/require-default-prop') const RuleTester = require('eslint').RuleTester const parserOptions = { - ecmaVersion: 6, - ecmaFeatures: { experimentalObjectRestSpread: true }, + ecmaVersion: 2018, sourceType: 'module' } diff --git a/tests/lib/rules/require-prop-types.js b/tests/lib/rules/require-prop-types.js index 683e8a5bb..326fbd56b 100644 --- a/tests/lib/rules/require-prop-types.js +++ b/tests/lib/rules/require-prop-types.js @@ -31,7 +31,7 @@ ruleTester.run('require-prop-types', rule, { } } `, - parserOptions: { ecmaVersion: 6, sourceType: 'module', ecmaFeatures: { experimentalObjectRestSpread: true }} + parserOptions: { ecmaVersion: 2018, sourceType: 'module' } }, { filename: 'test.vue', diff --git a/tests/lib/rules/require-render-return.js b/tests/lib/rules/require-render-return.js index c12910ff7..38132b287 100644 --- a/tests/lib/rules/require-render-return.js +++ b/tests/lib/rules/require-render-return.js @@ -12,9 +12,9 @@ const rule = require('../../../lib/rules/require-render-return') const RuleTester = require('eslint').RuleTester const parserOptions = { - ecmaVersion: 6, + ecmaVersion: 2018, sourceType: 'module', - ecmaFeatures: { experimentalObjectRestSpread: true, jsx: true } + ecmaFeatures: { jsx: true } } // ------------------------------------------------------------------------------ diff --git a/tests/lib/rules/require-valid-default-prop.js b/tests/lib/rules/require-valid-default-prop.js index b8794fbfb..241b7ff06 100644 --- a/tests/lib/rules/require-valid-default-prop.js +++ b/tests/lib/rules/require-valid-default-prop.js @@ -12,9 +12,9 @@ const rule = require('../../../lib/rules/require-valid-default-prop') const RuleTester = require('eslint').RuleTester const parserOptions = { - ecmaVersion: 6, + ecmaVersion: 2018, sourceType: 'module', - ecmaFeatures: { experimentalObjectRestSpread: true, jsx: true } + ecmaFeatures: { jsx: true } } function errorMessage (type) { diff --git a/tests/lib/rules/valid-v-on.js b/tests/lib/rules/valid-v-on.js index 46dd8b4ee..3c02be86f 100644 --- a/tests/lib/rules/valid-v-on.js +++ b/tests/lib/rules/valid-v-on.js @@ -82,6 +82,10 @@ tester.run('valid-v-on', rule, { { filename: 'test.vue', code: '' + }, + { + filename: 'test.vue', + code: '' } ], invalid: [