Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
110 changes: 108 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,110 @@ module.exports = {
}
}),
utils.defineVueVisitor(context, {
onVueObjectEnter(node) {
const container = getVueComponentPropertiesContainer(node)
/*
mapActions or mapMutations.

methods: mapMutations({ add: 'increment' })

methods: {
...mapMutations({ add: 'increment' })
}
*/
'CallExpression[callee.name=/^(mapMutations|mapActions)$/][arguments] ObjectExpression Property[key.name]'(
node,
vueNode
) {
const container = getVueComponentPropertiesContainer(vueNode.node)

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

/*
mapActions or mapMutations.

methods: mapMutations(['add'])

methods: {
...mapMutations(['add'])
}
*/
'CallExpression[callee.name=/^(mapMutations|mapActions)$/][arguments] ArrayExpression Literal[value]'(
node,
vueNode
) {
const container = getVueComponentPropertiesContainer(vueNode.node)

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

/*
mapState or mapGetters.

computed: mapState({
count: state => state.todosCount
})

computed: {
...mapState({
count: state => state.todosCount
})
}

computed: mapState({
count (state) {
return state.todosCount
}
})
*/
'CallExpression[callee.name=/^(mapState|mapGetters)$/][arguments] ObjectExpression Property[key.name]'(
node,
vueNode
) {
const container = getVueComponentPropertiesContainer(vueNode.node)

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

/*
mapState or mapGetters.

computed: mapGetters(['count1', 'count2'])

computed: {
...mapGetters(['count']),
}
*/
'CallExpression[callee.name=/^(mapState|mapGetters)$/][arguments] ArrayExpression Literal[value]'(
node,
vueNode
) {
const container = getVueComponentPropertiesContainer(vueNode.node)

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

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

for (const watcherOrExpose of utils.iterateProperties(
node,
Expand Down Expand Up @@ -495,8 +599,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