Skip to content

Commit e3c0875

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

11 files changed

+62
-60
lines changed

Diff for: 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

Diff for: 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()

Diff for: 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
)

Diff for: 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' ||

Diff for: 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
}

Diff for: 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

Diff for: lib/rules/require-default-prop.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ module.exports = {
123123
* @return {Boolean}
124124
*/
125125
function isBooleanProp(prop) {
126-
const value = utils.unwrapTypes(prop.value)
126+
const value = utils.skipTSAsExpression(prop.value)
127127

128128
return (
129129
isValueNodeOfBooleanType(value) ||

Diff for: 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)

Diff for: 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
}

Diff for: 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 (

Diff for: 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
})
@@ -754,15 +754,15 @@ module.exports = {
754754
type: 'object',
755755
key: prop.key,
756756
emitName,
757-
value: unwrapTypes(prop.value),
757+
value: skipTSAsExpression(prop.value),
758758
node: prop
759759
}
760760
}
761761
return {
762762
type: 'object',
763763
key: null,
764764
emitName: null,
765-
value: unwrapTypes(prop.value),
765+
value: skipTSAsExpression(prop.value),
766766
node: prop
767767
}
768768
})
@@ -823,7 +823,7 @@ module.exports = {
823823
.map((cp) => {
824824
const key = getStaticPropertyName(cp)
825825
/** @type {Expression} */
826-
const propValue = unwrapTypes(cp.value)
826+
const propValue = skipTSAsExpression(cp.value)
827827
/** @type {BlockStatement | null} */
828828
let value = null
829829

@@ -1017,7 +1017,7 @@ module.exports = {
10171017
const callee = callExpr.callee
10181018

10191019
if (callee.type === 'MemberExpression') {
1020-
const calleeObject = unwrapTypes(callee.object)
1020+
const calleeObject = skipTSAsExpression(callee.object)
10211021

10221022
if (
10231023
calleeObject.type === 'Identifier' &&
@@ -1271,11 +1271,11 @@ module.exports = {
12711271
getMemberChaining(node) {
12721272
/** @type {MemberExpression[]} */
12731273
const nodes = []
1274-
let n = unwrapChainExpression(node)
1274+
let n = skipChainExpression(node)
12751275

12761276
while (n.type === 'MemberExpression') {
12771277
nodes.push(n)
1278-
n = unwrapChainExpression(n.object)
1278+
n = skipChainExpression(n.object)
12791279
}
12801280

12811281
return [n, ...nodes.reverse()]
@@ -1339,24 +1339,17 @@ module.exports = {
13391339
*/
13401340
isPropertyChain,
13411341
/**
1342-
* Unwrap typescript types like "X as F"
1343-
* @template T
1344-
* @param {T} node
1345-
* @return {T}
1342+
* Retrieve `TSAsExpression#expression` value if the given node a `TSAsExpression` node. Otherwise, pass through it.
13461343
*/
1347-
unwrapTypes,
1344+
skipTSAsExpression,
13481345
/**
1349-
* Unwrap AssignmentPattern like "(a = 1) => ret"
1350-
* @param { AssignmentPattern | RestElement | ArrayPattern | ObjectPattern | Identifier } node
1351-
* @return { RestElement | ArrayPattern | ObjectPattern | Identifier}
1346+
* Retrieve `AssignmentPattern#left` value if the given node a `AssignmentPattern` node. Otherwise, pass through it.
13521347
*/
1353-
unwrapAssignmentPattern,
1348+
skipDefaultParamValue,
13541349
/**
1355-
* Unwrap ChainExpression like "(a?.b)"
1356-
* @param { Expression | Super } node
1357-
* @return { Expression | Super }
1350+
* Retrieve `ChainExpression#expression` value if the given node a `ChainExpression` node. Otherwise, pass through it.
13581351
*/
1359-
unwrapChainExpression,
1352+
skipChainExpression,
13601353

13611354
/**
13621355
* Check whether the given node is `this` or variable that stores `this`.
@@ -1617,20 +1610,21 @@ function isVElement(node) {
16171610
}
16181611

16191612
/**
1620-
* Unwrap typescript types like "X as F"
1621-
* @template T
1622-
* @param {T} node
1623-
* @return {T}
1613+
* Retrieve `TSAsExpression#expression` value if the given node a `TSAsExpression` node. Otherwise, pass through it.
1614+
* @template T Node type
1615+
* @param {T | TSAsExpression} node The node to address.
1616+
* @returns {T} The `TSAsExpression#expression` value if the node is a `TSAsExpression` node. Otherwise, the node.
16241617
*/
1625-
function unwrapTypes(node) {
1618+
function skipTSAsExpression(node) {
16261619
if (!node) {
16271620
return node
16281621
}
16291622
// @ts-expect-error
16301623
if (node.type === 'TSAsExpression') {
16311624
// @ts-expect-error
1632-
return unwrapTypes(node.expression)
1625+
return skipTSAsExpression(node.expression)
16331626
}
1627+
// @ts-expect-error
16341628
return node
16351629
}
16361630

@@ -1661,36 +1655,40 @@ function isPropertyChain(prop, node) {
16611655
}
16621656

16631657
/**
1664-
* Unwrap AssignmentPattern like "(a = 1) => ret"
1665-
* @param { AssignmentPattern | RestElement | ArrayPattern | ObjectPattern | Identifier } node
1666-
* @return { RestElement | ArrayPattern | ObjectPattern | Identifier }
1658+
* Retrieve `AssignmentPattern#left` value if the given node a `AssignmentPattern` node. Otherwise, pass through it.
1659+
* @template T Node type
1660+
* @param {T | AssignmentPattern} node The node to address.
1661+
* @return {T} The `AssignmentPattern#left` value if the node is a `AssignmentPattern` node. Otherwise, the node.
16671662
*/
1668-
function unwrapAssignmentPattern(node) {
1663+
function skipDefaultParamValue(node) {
16691664
if (!node) {
16701665
return node
16711666
}
1667+
// @ts-expect-error
16721668
if (node.type === 'AssignmentPattern') {
16731669
// @ts-expect-error
1674-
return unwrapAssignmentPattern(node.left)
1670+
return skipDefaultParamValue(node.left)
16751671
}
1672+
// @ts-expect-error
16761673
return node
16771674
}
16781675

16791676
/**
1680-
* Unwrap ChainExpression like "(a?.b)"
1681-
* @template T
1682-
* @param {T} node
1683-
* @return {T}
1677+
* Retrieve `ChainExpression#expression` value if the given node a `ChainExpression` node. Otherwise, pass through it.
1678+
* @template T Node type
1679+
* @param {T | ChainExpression} node The node to address.
1680+
* @returns {T} The `ChainExpression#expression` value if the node is a `ChainExpression` node. Otherwise, the node.
16841681
*/
1685-
function unwrapChainExpression(node) {
1682+
function skipChainExpression(node) {
16861683
if (!node) {
16871684
return node
16881685
}
16891686
// @ts-expect-error
16901687
if (node.type === 'ChainExpression') {
16911688
// @ts-expect-error
1692-
return unwrapChainExpression(node.expression)
1689+
return skipChainExpression(node.expression)
16931690
}
1691+
// @ts-expect-error
16941692
return node
16951693
}
16961694

@@ -1792,7 +1790,7 @@ function isVueComponent(node) {
17921790
const callee = node.callee
17931791

17941792
if (callee.type === 'MemberExpression') {
1795-
const calleeObject = unwrapTypes(callee.object)
1793+
const calleeObject = skipTSAsExpression(callee.object)
17961794

17971795
if (calleeObject.type === 'Identifier') {
17981796
const propName = getStaticPropertyName(callee)
@@ -1846,7 +1844,8 @@ function isVueComponent(node) {
18461844
function isObjectArgument(node) {
18471845
return (
18481846
node.arguments.length > 0 &&
1849-
unwrapTypes(node.arguments.slice(-1)[0]).type === 'ObjectExpression'
1847+
skipTSAsExpression(node.arguments.slice(-1)[0]).type ===
1848+
'ObjectExpression'
18501849
)
18511850
}
18521851
}
@@ -1864,7 +1863,7 @@ function isVueInstance(node) {
18641863
callee.type === 'Identifier' &&
18651864
callee.name === 'Vue' &&
18661865
node.arguments.length &&
1867-
unwrapTypes(node.arguments[0]).type === 'ObjectExpression'
1866+
skipTSAsExpression(node.arguments[0]).type === 'ObjectExpression'
18681867
)
18691868
}
18701869

@@ -1884,21 +1883,24 @@ function getVueObjectType(context, node) {
18841883
const filePath = context.getFilename()
18851884
if (
18861885
isVueComponentFile(parent, filePath) &&
1887-
unwrapTypes(parent.declaration) === node
1886+
skipTSAsExpression(parent.declaration) === node
18881887
) {
18891888
return 'export'
18901889
}
18911890
} else if (parent.type === 'CallExpression') {
18921891
// Vue.component('xxx', {}) || component('xxx', {})
18931892
if (
18941893
isVueComponent(parent) &&
1895-
unwrapTypes(parent.arguments.slice(-1)[0]) === node
1894+
skipTSAsExpression(parent.arguments.slice(-1)[0]) === node
18961895
) {
18971896
return 'definition'
18981897
}
18991898
} else if (parent.type === 'NewExpression') {
19001899
// new Vue({})
1901-
if (isVueInstance(parent) && unwrapTypes(parent.arguments[0]) === node) {
1900+
if (
1901+
isVueInstance(parent) &&
1902+
skipTSAsExpression(parent.arguments[0]) === node
1903+
) {
19021904
return 'instance'
19031905
}
19041906
}

0 commit comments

Comments
 (0)