Skip to content
84 changes: 82 additions & 2 deletions lib/rules/no-unused-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ module.exports = {
}
return container
}

/**
* @param {string[]} segments
* @param {Expression} propertyValue
Expand Down Expand Up @@ -350,6 +351,7 @@ module.exports = {
) {
continue
}

if (propertyReferences.hasProperty(property.name)) {
// used
if (
Expand Down Expand Up @@ -453,8 +455,84 @@ module.exports = {
}
}),
utils.defineVueVisitor(context, {
onVueObjectEnter(node) {
const container = getVueComponentPropertiesContainer(node)
/**
* e.g. `mapMutations({ add: 'increment' })`
* @param {Property} 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)

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

onVueObjectEnter(node, vueNode) {
const container = getVueComponentPropertiesContainer(vueNode.node)

for (const watcherOrExpose of utils.iterateProperties(
node,
Expand Down Expand Up @@ -495,8 +573,10 @@ module.exports = {
)
}
}

container.properties.push(...utils.iterateProperties(node, groups))
},

/** @param { (FunctionExpression | ArrowFunctionExpression) & { parent: Property }} node */
'ObjectExpression > Property > :function[params.length>0]'(
node,
Expand Down
Loading