Skip to content

Commit 520d31a

Browse files
committed
Update
1 parent bf0a8e5 commit 520d31a

File tree

7 files changed

+35
-16
lines changed

7 files changed

+35
-16
lines changed

lib/rules/custom-event-name-casing.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,14 @@ module.exports = {
116116
utils.compositingVisitors(
117117
utils.defineVueVisitor(context, {
118118
onSetupFunctionEnter(node, { node: vueNode }) {
119-
const contextParam = node.params[1]
119+
const contextParam = utils.unwrapAssignmentPattern(node.params[1])
120120
if (!contextParam) {
121121
// no arguments
122122
return
123123
}
124124
if (
125125
contextParam.type === 'RestElement' ||
126-
contextParam.type === 'ArrayPattern' ||
127-
contextParam.type === 'MemberExpression' ||
128-
contextParam.type === 'AssignmentPattern'
126+
contextParam.type === 'ArrayPattern'
129127
) {
130128
// cannot check
131129
return

lib/rules/no-mutating-props.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ module.exports = {
179179
}
180180
},
181181
onSetupFunctionEnter(node) {
182-
/** @type {Pattern} */
183182
const propsParam = node.params[0]
184183
if (!propsParam) {
185184
// no arguments

lib/rules/no-setup-props-destructure.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,12 @@ module.exports = {
8181
scopeStack = { upper: scopeStack, functionNode: node }
8282
},
8383
onSetupFunctionEnter(node) {
84-
const propsParam = node.params[0]
84+
const propsParam = utils.unwrapAssignmentPattern(node.params[0])
8585
if (!propsParam) {
8686
// no arguments
8787
return
8888
}
89-
if (
90-
propsParam.type === 'RestElement' ||
91-
propsParam.type === 'MemberExpression' ||
92-
propsParam.type === 'AssignmentPattern'
93-
) {
89+
if (propsParam.type === 'RestElement') {
9490
// cannot check
9591
return
9692
}

lib/rules/no-unused-properties.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ class ParamUsedProps extends UsedProps {
330330
*/
331331
constructor(paramNode, context) {
332332
super()
333-
if (paramNode.type === 'AssignmentPattern') {
333+
while (paramNode.type === 'AssignmentPattern') {
334334
paramNode = paramNode.left
335335
}
336336
if (paramNode.type === 'RestElement' || paramNode.type === 'ArrayPattern') {

lib/utils/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,7 @@ module.exports = {
14181418
* @return {T}
14191419
*/
14201420
unwrapTypes,
1421+
unwrapAssignmentPattern,
14211422

14221423
/**
14231424
* Check whether the given node is `this` or variable that stores `this`.
@@ -1566,6 +1567,22 @@ function unwrapTypes(node) {
15661567
return node
15671568
}
15681569

1570+
/**
1571+
* Unwrap AssignmentPattern like "(a = 1) => ret"
1572+
* @param { AssignmentPattern | RestElement | ArrayPattern | ObjectPattern | Identifier } node
1573+
* @return { RestElement | ArrayPattern | ObjectPattern | Identifier}
1574+
*/
1575+
function unwrapAssignmentPattern(node) {
1576+
if (!node) {
1577+
return node
1578+
}
1579+
if (node.type === 'AssignmentPattern') {
1580+
// @ts-ignore
1581+
return unwrapAssignmentPattern(node.left)
1582+
}
1583+
return node
1584+
}
1585+
15691586
/**
15701587
* Gets the property name of a given node.
15711588
* @param {Property|AssignmentProperty|MethodDefinition|MemberExpression} node - The node to get.

typings/eslint-plugin-vue/util-types/ast/es-ast.d.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export interface FunctionDeclaration extends HasParentNode {
159159
async: boolean
160160
generator: boolean
161161
id: Identifier | null
162-
params: Pattern[]
162+
params: _FunctionParameter[]
163163
body: BlockStatement
164164
}
165165
export interface VariableDeclaration extends HasParentNode {
@@ -305,7 +305,7 @@ export interface FunctionExpression extends HasParentNode {
305305
async: boolean
306306
generator: boolean
307307
id: Identifier | null
308-
params: Pattern[]
308+
params: _FunctionParameter[]
309309
body: BlockStatement
310310
}
311311

@@ -314,7 +314,7 @@ interface ArrowFunctionExpressionHasBlock extends HasParentNode {
314314
async: boolean
315315
generator: boolean
316316
id: Identifier | null
317-
params: Pattern[]
317+
params: _FunctionParameter[]
318318
body: BlockStatement
319319
expression: false
320320
}
@@ -324,7 +324,7 @@ interface ArrowFunctionExpressionNoBlock extends HasParentNode {
324324
async: boolean
325325
generator: boolean
326326
id: Identifier | null
327-
params: Pattern[]
327+
params: _FunctionParameter[]
328328
body: Expression
329329
expression: true
330330
}
@@ -503,3 +503,11 @@ export interface AssignmentPattern extends HasParentNode {
503503
left: Pattern
504504
right: Expression
505505
}
506+
507+
type _FunctionParameter =
508+
| AssignmentPattern
509+
| RestElement
510+
| ArrayPattern
511+
| ObjectPattern
512+
| Identifier
513+
// | TSParameterProperty;

typings/eslint-plugin-vue/util-types/ast/ts-ast.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { HasParentNode } from '../node'
22
import * as ES from './es-ast'
33
export type TSNode = TSAsExpression
4+
45
export interface TSAsExpression extends HasParentNode {
56
type: 'TSAsExpression'
67
expression: ES.Expression

0 commit comments

Comments
 (0)