Skip to content

Commit

Permalink
Chore: update vue-eslint-parser to v4 (#692)
Browse files Browse the repository at this point in the history
This update fixes some bugs:

- fixes #687
- fixes no-unused-vars that filter names don't use varaibles

And add the new node support to indent rules.
  • Loading branch information
mysticatea authored and michalsnik committed Dec 3, 2018
1 parent 6ef20aa commit f00e872
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 2 deletions.
39 changes: 38 additions & 1 deletion lib/utils/indent-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', 'VSlotScopeExpression', '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', 'VFilter', 'VFilterSequenceExpression', '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*\*/
Expand Down Expand Up @@ -205,6 +205,15 @@ function isNotEmptyTextNode (node) {
return !(node.type === 'VText' && node.value.trim() === '')
}

/**
* Check whether the given token is a pipe operator.
* @param {Token} token The token to check.
* @returns {boolean} `true` if the token is a pipe operator.
*/
function isPipeOperator (token) {
return token != null && token.type === 'Punctuator' && token.value === '|'
}

/**
* Get the last element.
* @param {Array} xs The array to get the last element.
Expand Down Expand Up @@ -915,6 +924,34 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
}
},

VFilter (node) {
const idToken = tokenStore.getFirstToken(node)
const lastToken = tokenStore.getLastToken(node)
if (isRightParen(lastToken)) {
const leftParenToken = tokenStore.getTokenAfter(node.callee)
setOffset(leftParenToken, 1, idToken)
processNodeList(node.arguments, leftParenToken, lastToken, 1)
}
},

VFilterSequenceExpression (node) {
if (node.filters.length === 0) {
return
}

const firstToken = tokenStore.getFirstToken(node)
const tokens = []

for (const filter of node.filters) {
tokens.push(
tokenStore.getTokenBefore(filter, isPipeOperator),
tokenStore.getFirstToken(filter)
)
}

setOffset(tokens, 1, firstToken)
},

VForExpression (node) {
const firstToken = tokenStore.getFirstToken(node)
const lastOfLeft = last(node.left) || firstToken
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"eslint": "^5.0.0"
},
"dependencies": {
"vue-eslint-parser": "^3.2.1"
"vue-eslint-parser": "^4.0.2"
},
"devDependencies": {
"@types/node": "^4.2.16",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!--{}-->
<template>
<div :attr="
value
|
filter
" />
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!--{}-->
<template>
<div :attr="
value
| filter1
| filter2
| filter3
" />
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!--{}-->
<template>
<div :attr="
value |
filter1 |
filter2 |
filter3
" />
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!--{}-->
<template>
<div :attr="
value | filter(
a,
b
)
" />
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!--{}-->
<template>
<div :attr="
value | filter(a, b)
" />
</template>
7 changes: 7 additions & 0 deletions tests/lib/rules/no-unused-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ tester.run('no-unused-vars', rule, {
},
{
code: '<template><div v-for="(v, i, c) in foo">{{c}}</div></template>'
},
{
code: '<template><div v-for="x in foo">{{value | f(x)}}</div></template>'
}
],
invalid: [
Expand Down Expand Up @@ -80,6 +83,10 @@ tester.run('no-unused-vars', rule, {
{
code: '<template><div v-for="(item, key) in items" :key="item.id">{{item.name}}</div></template>',
errors: ["'key' is defined but never used."]
},
{
code: '<template><div v-for="x in items">{{value | x}}</div></template>',
errors: ["'x' is defined but never used."]
}
]
})

0 comments on commit f00e872

Please sign in to comment.