Skip to content

Commit a1e75b8

Browse files
committed
Refactored to resemble eslint core util function naming. e.g. unwrap -> skip
1 parent 0e6a0db commit a1e75b8

11 files changed

+62
-60
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function getNameParamNode(node) {
4848
* @param {CallExpression} node CallExpression
4949
*/
5050
function getCalleeMemberNode(node) {
51-
const callee = utils.unwrapChainExpression(node.callee)
51+
const callee = utils.skipChainExpression(node.callee)
5252

5353
if (callee.type === 'MemberExpression') {
5454
const name = utils.getStaticPropertyName(callee)
@@ -116,7 +116,7 @@ module.exports = {
116116
utils.compositingVisitors(
117117
utils.defineVueVisitor(context, {
118118
onSetupFunctionEnter(node, { node: vueNode }) {
119-
const contextParam = utils.unwrapAssignmentPattern(node.params[1])
119+
const contextParam = utils.skipDefaultParamValue(node.params[1])
120120
if (!contextParam) {
121121
// no arguments
122122
return

lib/rules/no-async-in-computed-properties.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const TIMED_FUNCTIONS = [
2626
* @param {CallExpression} node
2727
*/
2828
function isTimedFunction(node) {
29-
const callee = utils.unwrapChainExpression(node.callee)
29+
const callee = utils.skipChainExpression(node.callee)
3030
return (
3131
((node.type === 'CallExpression' &&
3232
callee.type === 'Identifier' &&
@@ -45,7 +45,7 @@ function isTimedFunction(node) {
4545
* @param {CallExpression} node
4646
*/
4747
function isPromise(node) {
48-
const callee = utils.unwrapChainExpression(node.callee)
48+
const callee = utils.skipChainExpression(node.callee)
4949
if (node.type === 'CallExpression' && callee.type === 'MemberExpression') {
5050
return (
5151
// hello.PROMISE_FUNCTION()

lib/rules/no-deprecated-events-api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = {
4848
}
4949

5050
if (
51-
utils.unwrapChainExpression(call.callee) !== node ||
51+
utils.skipChainExpression(call.callee) !== node ||
5252
!['$on', '$off', '$once'].includes(
5353
utils.getStaticPropertyName(node) || ''
5454
)

lib/rules/no-deprecated-vue-config-keycodes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = {
3333
"MemberExpression[property.type='Identifier'][property.name='keyCodes']"(
3434
node
3535
) {
36-
const config = utils.unwrapChainExpression(node.object)
36+
const config = utils.skipChainExpression(node.object)
3737
if (
3838
config.type !== 'MemberExpression' ||
3939
config.property.type !== 'Identifier' ||

lib/rules/no-multiple-slot-args.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ module.exports = {
100100
return utils.defineVueVisitor(context, {
101101
/** @param {MemberExpression} node */
102102
MemberExpression(node) {
103-
const object = utils.unwrapChainExpression(node.object)
103+
const object = utils.skipChainExpression(node.object)
104104
if (object.type !== 'MemberExpression') {
105105
return
106106
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = {
4949
return
5050
}
5151

52-
const rightNode = utils.unwrapChainExpression(right)
52+
const rightNode = utils.skipChainExpression(right)
5353
if (
5454
left.type !== 'ArrayPattern' &&
5555
left.type !== 'ObjectPattern' &&
@@ -60,7 +60,7 @@ module.exports = {
6060
/** @type {Expression | Super} */
6161
let rightId = rightNode
6262
while (rightId.type === 'MemberExpression') {
63-
rightId = utils.unwrapChainExpression(rightId.object)
63+
rightId = utils.skipChainExpression(rightId.object)
6464
}
6565
if (rightId.type === 'Identifier' && propsReferenceIds.has(rightId)) {
6666
report(left, 'getProperty')
@@ -84,7 +84,7 @@ module.exports = {
8484
}
8585
},
8686
onSetupFunctionEnter(node) {
87-
const propsParam = utils.unwrapAssignmentPattern(node.params[0])
87+
const propsParam = utils.skipDefaultParamValue(node.params[0])
8888
if (!propsParam) {
8989
// no arguments
9090
return

lib/rules/require-default-prop.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ module.exports = {
129129
* @return {Boolean}
130130
*/
131131
function isBooleanProp(prop) {
132-
const value = utils.unwrapTypes(prop.value)
132+
const value = utils.skipTSAsExpression(prop.value)
133133

134134
return (
135135
isValueNodeOfBooleanType(value) ||

lib/rules/require-explicit-emits.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ module.exports = {
261261
* @param {VueObjectData} data
262262
*/
263263
'CallExpression[arguments.0.type=Literal]'(node, { node: vueNode }) {
264-
const callee = utils.unwrapChainExpression(node.callee)
264+
const callee = utils.skipChainExpression(node.callee)
265265
const nameLiteralNode = node.arguments[0]
266266
if (!nameLiteralNode || typeof nameLiteralNode.value !== 'string') {
267267
// cannot check
@@ -288,7 +288,7 @@ module.exports = {
288288
// verify setup(props,{emit}) {emit()}
289289
verify(emitsDeclarations, nameLiteralNode, vueNode)
290290
} else if (emit && emit.name === 'emit') {
291-
const memObject = utils.unwrapChainExpression(emit.member.object)
291+
const memObject = utils.skipChainExpression(emit.member.object)
292292
if (
293293
memObject.type === 'Identifier' &&
294294
contextReferenceIds.has(memObject)
@@ -301,7 +301,7 @@ module.exports = {
301301

302302
// verify $emit
303303
if (emit && emit.name === '$emit') {
304-
const memObject = utils.unwrapChainExpression(emit.member.object)
304+
const memObject = utils.skipChainExpression(emit.member.object)
305305
if (utils.isThis(memObject, context)) {
306306
// verify this.$emit()
307307
verify(emitsDeclarations, nameLiteralNode, vueNode)

lib/rules/require-slots-as-functions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ module.exports = {
103103
return utils.defineVueVisitor(context, {
104104
/** @param {MemberExpression} node */
105105
MemberExpression(node) {
106-
const object = utils.unwrapChainExpression(node.object)
106+
const object = utils.skipChainExpression(node.object)
107107
if (object.type !== 'MemberExpression') {
108108
return
109109
}

lib/rules/require-valid-default-prop.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ module.exports = {
126126
* @returns { StandardValueType | FunctionExprValueType | FunctionValueType | null }
127127
*/
128128
function getValueType(targetNode) {
129-
const node = utils.unwrapChainExpression(targetNode)
129+
const node = utils.skipChainExpression(targetNode)
130130
if (node.type === 'CallExpression') {
131131
// Symbol(), Number() ...
132132
if (

lib/utils/index.js

+46-44
Original file line numberDiff line numberDiff line change
@@ -681,15 +681,15 @@ module.exports = {
681681
type: 'object',
682682
key: prop.key,
683683
propName,
684-
value: unwrapTypes(prop.value),
684+
value: skipTSAsExpression(prop.value),
685685
node: prop
686686
}
687687
}
688688
return {
689689
type: 'object',
690690
key: null,
691691
propName: null,
692-
value: unwrapTypes(prop.value),
692+
value: skipTSAsExpression(prop.value),
693693
node: prop
694694
}
695695
})
@@ -752,15 +752,15 @@ module.exports = {
752752
type: 'object',
753753
key: prop.key,
754754
emitName,
755-
value: unwrapTypes(prop.value),
755+
value: skipTSAsExpression(prop.value),
756756
node: prop
757757
}
758758
}
759759
return {
760760
type: 'object',
761761
key: null,
762762
emitName: null,
763-
value: unwrapTypes(prop.value),
763+
value: skipTSAsExpression(prop.value),
764764
node: prop
765765
}
766766
})
@@ -819,7 +819,7 @@ module.exports = {
819819
.map((cp) => {
820820
const key = getStaticPropertyName(cp)
821821
/** @type {Expression} */
822-
const propValue = unwrapTypes(cp.value)
822+
const propValue = skipTSAsExpression(cp.value)
823823
/** @type {BlockStatement | null} */
824824
let value = null
825825

@@ -1013,7 +1013,7 @@ module.exports = {
10131013
const callee = callExpr.callee
10141014

10151015
if (callee.type === 'MemberExpression') {
1016-
const calleeObject = unwrapTypes(callee.object)
1016+
const calleeObject = skipTSAsExpression(callee.object)
10171017

10181018
if (
10191019
calleeObject.type === 'Identifier' &&
@@ -1270,11 +1270,11 @@ module.exports = {
12701270
getMemberChaining(node) {
12711271
/** @type {MemberExpression[]} */
12721272
const nodes = []
1273-
let n = unwrapChainExpression(node)
1273+
let n = skipChainExpression(node)
12741274

12751275
while (n.type === 'MemberExpression') {
12761276
nodes.push(n)
1277-
n = unwrapChainExpression(n.object)
1277+
n = skipChainExpression(n.object)
12781278
}
12791279

12801280
return [n, ...nodes.reverse()]
@@ -1338,24 +1338,17 @@ module.exports = {
13381338
*/
13391339
isPropertyChain,
13401340
/**
1341-
* Unwrap typescript types like "X as F"
1342-
* @template T
1343-
* @param {T} node
1344-
* @return {T}
1341+
* Retrieve `TSAsExpression#expression` value if the given node a `TSAsExpression` node. Otherwise, pass through it.
13451342
*/
1346-
unwrapTypes,
1343+
skipTSAsExpression,
13471344
/**
1348-
* Unwrap AssignmentPattern like "(a = 1) => ret"
1349-
* @param { AssignmentPattern | RestElement | ArrayPattern | ObjectPattern | Identifier } node
1350-
* @return { RestElement | ArrayPattern | ObjectPattern | Identifier}
1345+
* Retrieve `AssignmentPattern#left` value if the given node a `AssignmentPattern` node. Otherwise, pass through it.
13511346
*/
1352-
unwrapAssignmentPattern,
1347+
skipDefaultParamValue,
13531348
/**
1354-
* Unwrap ChainExpression like "(a?.b)"
1355-
* @param { Expression | Super } node
1356-
* @return { Expression | Super }
1349+
* Retrieve `ChainExpression#expression` value if the given node a `ChainExpression` node. Otherwise, pass through it.
13571350
*/
1358-
unwrapChainExpression,
1351+
skipChainExpression,
13591352

13601353
/**
13611354
* Check whether the given node is `this` or variable that stores `this`.
@@ -1651,20 +1644,21 @@ function isVElement(node) {
16511644
}
16521645

16531646
/**
1654-
* Unwrap typescript types like "X as F"
1655-
* @template T
1656-
* @param {T} node
1657-
* @return {T}
1647+
* Retrieve `TSAsExpression#expression` value if the given node a `TSAsExpression` node. Otherwise, pass through it.
1648+
* @template T Node type
1649+
* @param {T | TSAsExpression} node The node to address.
1650+
* @returns {T} The `TSAsExpression#expression` value if the node is a `TSAsExpression` node. Otherwise, the node.
16581651
*/
1659-
function unwrapTypes(node) {
1652+
function skipTSAsExpression(node) {
16601653
if (!node) {
16611654
return node
16621655
}
16631656
// @ts-expect-error
16641657
if (node.type === 'TSAsExpression') {
16651658
// @ts-expect-error
1666-
return unwrapTypes(node.expression)
1659+
return skipTSAsExpression(node.expression)
16671660
}
1661+
// @ts-expect-error
16681662
return node
16691663
}
16701664

@@ -1695,36 +1689,40 @@ function isPropertyChain(prop, node) {
16951689
}
16961690

16971691
/**
1698-
* Unwrap AssignmentPattern like "(a = 1) => ret"
1699-
* @param { AssignmentPattern | RestElement | ArrayPattern | ObjectPattern | Identifier } node
1700-
* @return { RestElement | ArrayPattern | ObjectPattern | Identifier }
1692+
* Retrieve `AssignmentPattern#left` value if the given node a `AssignmentPattern` node. Otherwise, pass through it.
1693+
* @template T Node type
1694+
* @param {T | AssignmentPattern} node The node to address.
1695+
* @return {T} The `AssignmentPattern#left` value if the node is a `AssignmentPattern` node. Otherwise, the node.
17011696
*/
1702-
function unwrapAssignmentPattern(node) {
1697+
function skipDefaultParamValue(node) {
17031698
if (!node) {
17041699
return node
17051700
}
1701+
// @ts-expect-error
17061702
if (node.type === 'AssignmentPattern') {
17071703
// @ts-expect-error
1708-
return unwrapAssignmentPattern(node.left)
1704+
return skipDefaultParamValue(node.left)
17091705
}
1706+
// @ts-expect-error
17101707
return node
17111708
}
17121709

17131710
/**
1714-
* Unwrap ChainExpression like "(a?.b)"
1715-
* @template T
1716-
* @param {T} node
1717-
* @return {T}
1711+
* Retrieve `ChainExpression#expression` value if the given node a `ChainExpression` node. Otherwise, pass through it.
1712+
* @template T Node type
1713+
* @param {T | ChainExpression} node The node to address.
1714+
* @returns {T} The `ChainExpression#expression` value if the node is a `ChainExpression` node. Otherwise, the node.
17181715
*/
1719-
function unwrapChainExpression(node) {
1716+
function skipChainExpression(node) {
17201717
if (!node) {
17211718
return node
17221719
}
17231720
// @ts-expect-error
17241721
if (node.type === 'ChainExpression') {
17251722
// @ts-expect-error
1726-
return unwrapChainExpression(node.expression)
1723+
return skipChainExpression(node.expression)
17271724
}
1725+
// @ts-expect-error
17281726
return node
17291727
}
17301728

@@ -1826,7 +1824,7 @@ function isVueComponent(node) {
18261824
const callee = node.callee
18271825

18281826
if (callee.type === 'MemberExpression') {
1829-
const calleeObject = unwrapTypes(callee.object)
1827+
const calleeObject = skipTSAsExpression(callee.object)
18301828

18311829
if (calleeObject.type === 'Identifier') {
18321830
const propName = getStaticPropertyName(callee)
@@ -1880,7 +1878,8 @@ function isVueComponent(node) {
18801878
function isObjectArgument(node) {
18811879
return (
18821880
node.arguments.length > 0 &&
1883-
unwrapTypes(node.arguments.slice(-1)[0]).type === 'ObjectExpression'
1881+
skipTSAsExpression(node.arguments.slice(-1)[0]).type ===
1882+
'ObjectExpression'
18841883
)
18851884
}
18861885
}
@@ -1898,7 +1897,7 @@ function isVueInstance(node) {
18981897
callee.type === 'Identifier' &&
18991898
callee.name === 'Vue' &&
19001899
node.arguments.length &&
1901-
unwrapTypes(node.arguments[0]).type === 'ObjectExpression'
1900+
skipTSAsExpression(node.arguments[0]).type === 'ObjectExpression'
19021901
)
19031902
}
19041903

@@ -1918,21 +1917,24 @@ function getVueObjectType(context, node) {
19181917
const filePath = context.getFilename()
19191918
if (
19201919
isVueComponentFile(parent, filePath) &&
1921-
unwrapTypes(parent.declaration) === node
1920+
skipTSAsExpression(parent.declaration) === node
19221921
) {
19231922
return 'export'
19241923
}
19251924
} else if (parent.type === 'CallExpression') {
19261925
// Vue.component('xxx', {}) || component('xxx', {})
19271926
if (
19281927
isVueComponent(parent) &&
1929-
unwrapTypes(parent.arguments.slice(-1)[0]) === node
1928+
skipTSAsExpression(parent.arguments.slice(-1)[0]) === node
19301929
) {
19311930
return 'definition'
19321931
}
19331932
} else if (parent.type === 'NewExpression') {
19341933
// new Vue({})
1935-
if (isVueInstance(parent) && unwrapTypes(parent.arguments[0]) === node) {
1934+
if (
1935+
isVueInstance(parent) &&
1936+
skipTSAsExpression(parent.arguments[0]) === node
1937+
) {
19361938
return 'instance'
19371939
}
19381940
}

0 commit comments

Comments
 (0)