Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 895fc9c

Browse files
Fix type errors caused by TypeScript (#2361)
1 parent 66bf635 commit 895fc9c

File tree

5 files changed

+107
-71
lines changed

5 files changed

+107
-71
lines changed

‎lib/rules/enforce-style-attribute.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function isPlain(componentBlock) {
3434
return !isScoped(componentBlock) && !isModule(componentBlock)
3535
}
3636

37+
/** @param {RuleContext} context */
3738
function getUserDefinedAllowedAttrs(context) {
3839
if (context.options[0] && context.options[0].allow) {
3940
return context.options[0].allow

‎lib/rules/no-mutating-props.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ module.exports = {
212212
case 'ArrayPattern': {
213213
for (let index = 0; index < param.elements.length; index++) {
214214
const element = param.elements[index]
215-
yield* iteratePatternProperties(element, [...path, `${index}`])
215+
if (element)
216+
yield* iteratePatternProperties(element, [...path, `${index}`])
216217
}
217218
break
218219
}

‎lib/rules/no-template-shadow.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const GROUP_NAMES = [
2020
'setup'
2121
]
2222

23+
/**
24+
* @param {RuleContext} context
25+
* @param {string} variableName
26+
*/
2327
function isAllowedVarName(context, variableName) {
2428
if (context.options[0] && context.options[0].allow) {
2529
return context.options[0].allow.includes(variableName)

‎lib/rules/no-unused-properties.js

Lines changed: 53 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -487,79 +487,62 @@ module.exports = {
487487
}),
488488
utils.defineVueVisitor(context, {
489489
/**
490-
* e.g. `mapMutations({ add: 'increment' })`
491-
* @param {Property} node
490+
* @param {CallExpression} node
492491
* @param {VueObjectData} vueData
493492
*/
494-
'CallExpression[callee.name=/^(mapMutations|mapActions)$/][arguments] ObjectExpression Property'(
495-
node,
496-
vueData
497-
) {
498-
const container = getVueComponentPropertiesContainer(vueData.node)
499-
500-
container.properties.push({
501-
type: 'array',
502-
name: utils.getStaticPropertyName(node),
503-
groupName: 'methods',
504-
node
505-
})
506-
},
507-
508-
/**
509-
* e.g. `mapMutations(['add'])`
510-
* @param {Literal} node
511-
* @param {VueObjectData} vueData
512-
*/
513-
'CallExpression[callee.name=/^(mapMutations|mapActions)$/][arguments] ArrayExpression Literal'(
514-
node,
515-
vueData
516-
) {
517-
const container = getVueComponentPropertiesContainer(vueData.node)
518-
519-
container.properties.push({
520-
type: 'array',
521-
name: utils.getStringLiteralValue(node),
522-
groupName: 'methods',
523-
node
524-
})
525-
},
526-
527-
/**
528-
* e.g. `mapState({ count: state => state.todosCount })`
529-
* @param {Property} node
530-
* @param {VueObjectData} vueData
531-
*/
532-
'CallExpression[callee.name=/^(mapState|mapGetters)$/][arguments] ObjectExpression Property'(
533-
node,
534-
vueData
535-
) {
536-
const container = getVueComponentPropertiesContainer(vueData.node)
537-
538-
container.properties.push({
539-
type: 'array',
540-
name: utils.getStaticPropertyName(node),
541-
groupName: 'computed',
542-
node
543-
})
544-
},
545-
546-
/**
547-
* e.g. `mapState(['count'])`
548-
* @param {Literal} node
549-
* @param {VueObjectData} vueData
550-
*/
551-
'CallExpression[callee.name=/^(mapState|mapGetters)$/][arguments] ArrayExpression Literal'(
552-
node,
553-
vueData
554-
) {
555-
const container = getVueComponentPropertiesContainer(vueData.node)
493+
CallExpression(node, vueData) {
494+
if (node.callee.type !== 'Identifier') return
495+
/** @type {'methods'|'computed'|null} */
496+
let groupName = null
497+
if (/^mapMutations|mapActions$/u.test(node.callee.name)) {
498+
groupName = 'methods'
499+
} else if (/^mapState|mapGetters$/u.test(node.callee.name)) {
500+
groupName = 'computed'
501+
}
556502

557-
container.properties.push({
558-
type: 'array',
559-
name: utils.getStringLiteralValue(node),
560-
groupName: 'computed',
561-
node
562-
})
503+
if (!groupName || node.arguments.length === 0) return
504+
const arg = node.arguments[0]
505+
if (arg.type === 'ObjectExpression') {
506+
// e.g.
507+
// `mapMutations({ add: 'increment' })`
508+
// `mapState({ count: state => state.todosCount })`
509+
const container = getVueComponentPropertiesContainer(vueData.node)
510+
for (const prop of arg.properties) {
511+
const name =
512+
prop.type === 'SpreadElement'
513+
? null
514+
: utils.getStaticPropertyName(prop)
515+
if (name) {
516+
container.properties.push({
517+
type: 'array',
518+
name,
519+
groupName,
520+
node: prop
521+
})
522+
}
523+
}
524+
} else if (arg.type === 'ArrayExpression') {
525+
// e.g. `mapMutations(['add'])`
526+
const container = getVueComponentPropertiesContainer(vueData.node)
527+
for (const element of arg.elements) {
528+
if (
529+
!element ||
530+
(element.type !== 'Literal' &&
531+
element.type !== 'TemplateLiteral')
532+
) {
533+
continue
534+
}
535+
const name = utils.getStringLiteralValue(element)
536+
if (name) {
537+
container.properties.push({
538+
type: 'array',
539+
name,
540+
groupName,
541+
node: element
542+
})
543+
}
544+
}
545+
}
563546
},
564547

565548
onVueObjectEnter(node, vueNode) {

‎tests/lib/rules/no-unused-properties.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2501,6 +2501,53 @@ tester.run('no-unused-properties', rule, {
25012501
}
25022502
]
25032503
},
2504+
{
2505+
filename: 'test.vue',
2506+
code: `
2507+
<script>
2508+
export default {
2509+
computed: {
2510+
...mapGetters({
2511+
a: { b :'c' }, // This is an invalid definition, but it does not use "a".
2512+
})
2513+
}
2514+
}
2515+
</script>
2516+
<template>
2517+
{{ count }}
2518+
</template>
2519+
`,
2520+
errors: [
2521+
{
2522+
message: "'a' of computed property found, but never used.",
2523+
line: 6
2524+
}
2525+
]
2526+
},
2527+
{
2528+
filename: 'test.vue',
2529+
code: `
2530+
<script>
2531+
export default {
2532+
computed: {
2533+
...mapGetters([
2534+
"a",
2535+
a['foo'] // cannot be inferred.
2536+
])
2537+
}
2538+
}
2539+
</script>
2540+
<template>
2541+
{{ count }}
2542+
</template>
2543+
`,
2544+
errors: [
2545+
{
2546+
message: "'a' of computed property found, but never used.",
2547+
line: 6
2548+
}
2549+
]
2550+
},
25042551

25052552
// vuex unused state
25062553
{

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /