Skip to content

Commit f00e872

Browse files
mysticateamichalsnik
authored andcommitted
Chore: update vue-eslint-parser to v4 (#692)
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.
1 parent 6ef20aa commit f00e872

8 files changed

+87
-2
lines changed

Diff for: lib/utils/indent-common.js

+38-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const assert = require('assert')
1414
// Helpers
1515
// ------------------------------------------------------------------------------
1616

17-
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'])
17+
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'])
1818
const LT_CHAR = /[\r\n\u2028\u2029]/
1919
const LINES = /[^\r\n\u2028\u2029]+(?:$|\r\n|[\r\n\u2028\u2029])/g
2020
const BLOCK_COMMENT_PREFIX = /^\s*\*/
@@ -205,6 +205,15 @@ function isNotEmptyTextNode (node) {
205205
return !(node.type === 'VText' && node.value.trim() === '')
206206
}
207207

208+
/**
209+
* Check whether the given token is a pipe operator.
210+
* @param {Token} token The token to check.
211+
* @returns {boolean} `true` if the token is a pipe operator.
212+
*/
213+
function isPipeOperator (token) {
214+
return token != null && token.type === 'Punctuator' && token.value === '|'
215+
}
216+
208217
/**
209218
* Get the last element.
210219
* @param {Array} xs The array to get the last element.
@@ -915,6 +924,34 @@ module.exports.defineVisitor = function create (context, tokenStore, defaultOpti
915924
}
916925
},
917926

927+
VFilter (node) {
928+
const idToken = tokenStore.getFirstToken(node)
929+
const lastToken = tokenStore.getLastToken(node)
930+
if (isRightParen(lastToken)) {
931+
const leftParenToken = tokenStore.getTokenAfter(node.callee)
932+
setOffset(leftParenToken, 1, idToken)
933+
processNodeList(node.arguments, leftParenToken, lastToken, 1)
934+
}
935+
},
936+
937+
VFilterSequenceExpression (node) {
938+
if (node.filters.length === 0) {
939+
return
940+
}
941+
942+
const firstToken = tokenStore.getFirstToken(node)
943+
const tokens = []
944+
945+
for (const filter of node.filters) {
946+
tokens.push(
947+
tokenStore.getTokenBefore(filter, isPipeOperator),
948+
tokenStore.getFirstToken(filter)
949+
)
950+
}
951+
952+
setOffset(tokens, 1, firstToken)
953+
},
954+
918955
VForExpression (node) {
919956
const firstToken = tokenStore.getFirstToken(node)
920957
const lastOfLeft = last(node.left) || firstToken

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"eslint": "^5.0.0"
4545
},
4646
"dependencies": {
47-
"vue-eslint-parser": "^3.2.1"
47+
"vue-eslint-parser": "^4.0.2"
4848
},
4949
"devDependencies": {
5050
"@types/node": "^4.2.16",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!--{}-->
2+
<template>
3+
<div :attr="
4+
value
5+
|
6+
filter
7+
" />
8+
</template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!--{}-->
2+
<template>
3+
<div :attr="
4+
value
5+
| filter1
6+
| filter2
7+
| filter3
8+
" />
9+
</template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!--{}-->
2+
<template>
3+
<div :attr="
4+
value |
5+
filter1 |
6+
filter2 |
7+
filter3
8+
" />
9+
</template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!--{}-->
2+
<template>
3+
<div :attr="
4+
value | filter(
5+
a,
6+
b
7+
)
8+
" />
9+
</template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!--{}-->
2+
<template>
3+
<div :attr="
4+
value | filter(a, b)
5+
" />
6+
</template>

Diff for: tests/lib/rules/no-unused-vars.js

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ tester.run('no-unused-vars', rule, {
4646
},
4747
{
4848
code: '<template><div v-for="(v, i, c) in foo">{{c}}</div></template>'
49+
},
50+
{
51+
code: '<template><div v-for="x in foo">{{value | f(x)}}</div></template>'
4952
}
5053
],
5154
invalid: [
@@ -80,6 +83,10 @@ tester.run('no-unused-vars', rule, {
8083
{
8184
code: '<template><div v-for="(item, key) in items" :key="item.id">{{item.name}}</div></template>',
8285
errors: ["'key' is defined but never used."]
86+
},
87+
{
88+
code: '<template><div v-for="x in items">{{value | x}}</div></template>',
89+
errors: ["'x' is defined but never used."]
8390
}
8491
]
8592
})

0 commit comments

Comments
 (0)