Skip to content

Fix type errors caused by TypeScript #2361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/rules/enforce-style-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function isPlain(componentBlock) {
return !isScoped(componentBlock) && !isModule(componentBlock)
}

/** @param {RuleContext} context */
function getUserDefinedAllowedAttrs(context) {
if (context.options[0] && context.options[0].allow) {
return context.options[0].allow
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-mutating-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ module.exports = {
case 'ArrayPattern': {
for (let index = 0; index < param.elements.length; index++) {
const element = param.elements[index]
yield* iteratePatternProperties(element, [...path, `${index}`])
if (element)
yield* iteratePatternProperties(element, [...path, `${index}`])
}
break
}
Expand Down
4 changes: 4 additions & 0 deletions lib/rules/no-template-shadow.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const GROUP_NAMES = [
'setup'
]

/**
* @param {RuleContext} context
* @param {string} variableName
*/
function isAllowedVarName(context, variableName) {
if (context.options[0] && context.options[0].allow) {
return context.options[0].allow.includes(variableName)
Expand Down
123 changes: 53 additions & 70 deletions lib/rules/no-unused-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,79 +487,62 @@ module.exports = {
}),
utils.defineVueVisitor(context, {
/**
* e.g. `mapMutations({ add: 'increment' })`
* @param {Property} node
* @param {CallExpression} node
* @param {VueObjectData} vueData
*/
'CallExpression[callee.name=/^(mapMutations|mapActions)$/][arguments] ObjectExpression Property'(
node,
vueData
) {
const container = getVueComponentPropertiesContainer(vueData.node)

container.properties.push({
type: 'array',
name: utils.getStaticPropertyName(node),
groupName: 'methods',
node
})
},

/**
* e.g. `mapMutations(['add'])`
* @param {Literal} node
* @param {VueObjectData} vueData
*/
'CallExpression[callee.name=/^(mapMutations|mapActions)$/][arguments] ArrayExpression Literal'(
node,
vueData
) {
const container = getVueComponentPropertiesContainer(vueData.node)

container.properties.push({
type: 'array',
name: utils.getStringLiteralValue(node),
groupName: 'methods',
node
})
},

/**
* e.g. `mapState({ count: state => state.todosCount })`
* @param {Property} node
* @param {VueObjectData} vueData
*/
'CallExpression[callee.name=/^(mapState|mapGetters)$/][arguments] ObjectExpression Property'(
node,
vueData
) {
const container = getVueComponentPropertiesContainer(vueData.node)

container.properties.push({
type: 'array',
name: utils.getStaticPropertyName(node),
groupName: 'computed',
node
})
},

/**
* e.g. `mapState(['count'])`
* @param {Literal} node
* @param {VueObjectData} vueData
*/
'CallExpression[callee.name=/^(mapState|mapGetters)$/][arguments] ArrayExpression Literal'(
node,
vueData
) {
const container = getVueComponentPropertiesContainer(vueData.node)
CallExpression(node, vueData) {
if (node.callee.type !== 'Identifier') return
/** @type {'methods'|'computed'|null} */
let groupName = null
if (/^mapMutations|mapActions$/u.test(node.callee.name)) {
groupName = 'methods'
} else if (/^mapState|mapGetters$/u.test(node.callee.name)) {
groupName = 'computed'
}

container.properties.push({
type: 'array',
name: utils.getStringLiteralValue(node),
groupName: 'computed',
node
})
if (!groupName || node.arguments.length === 0) return
const arg = node.arguments[0]
if (arg.type === 'ObjectExpression') {
// e.g.
// `mapMutations({ add: 'increment' })`
// `mapState({ count: state => state.todosCount })`
const container = getVueComponentPropertiesContainer(vueData.node)
for (const prop of arg.properties) {
const name =
prop.type === 'SpreadElement'
? null
: utils.getStaticPropertyName(prop)
if (name) {
container.properties.push({
type: 'array',
name,
groupName,
node: prop
})
}
}
} else if (arg.type === 'ArrayExpression') {
// e.g. `mapMutations(['add'])`
const container = getVueComponentPropertiesContainer(vueData.node)
for (const element of arg.elements) {
if (
!element ||
(element.type !== 'Literal' &&
element.type !== 'TemplateLiteral')
) {
continue
}
const name = utils.getStringLiteralValue(element)
if (name) {
container.properties.push({
type: 'array',
name,
groupName,
node: element
})
}
}
}
},

onVueObjectEnter(node, vueNode) {
Expand Down
47 changes: 47 additions & 0 deletions tests/lib/rules/no-unused-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -2501,6 +2501,53 @@ tester.run('no-unused-properties', rule, {
}
]
},
{
filename: 'test.vue',
code: `
<script>
export default {
computed: {
...mapGetters({
a: { b :'c' }, // This is an invalid definition, but it does not use "a".
})
}
}
</script>
<template>
{{ count }}
</template>
`,
errors: [
{
message: "'a' of computed property found, but never used.",
line: 6
}
]
},
{
filename: 'test.vue',
code: `
<script>
export default {
computed: {
...mapGetters([
"a",
a['foo'] // cannot be inferred.
])
}
}
</script>
<template>
{{ count }}
</template>
`,
errors: [
{
message: "'a' of computed property found, but never used.",
line: 6
}
]
},

// vuex unused state
{
Expand Down