Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
186 changes: 184 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,186 @@ module.exports = {
}
}),
utils.defineVueVisitor(context, {
onVueObjectEnter(node) {
const container = getVueComponentPropertiesContainer(node)
/*
methods: mapMutations({
add: 'increment'
})

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

container.properties.push({
type: 'array',
name: node.key.name,
groupName: 'methods',
node
})
},
/*
methods: mapMutations(['add'])

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

container.properties.push({
type: 'array',
name: node.value,
groupName: 'methods',
node
})
},
/*
methods: mapActions({
add: 'increment'
})

methods: {
...mapActions({
add: 'increment'
})
}
*/
'CallExpression[callee.name=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
})
},

/*
methods: mapActions(['add'])

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

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

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

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

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

container.properties.push({
type: 'array',
name: node.key.name,
groupName: 'props',
node
})
},
'CallExpression[callee.name=mapState][arguments] ArrayExpression Literal[value]'(
node,
vueNode
) {
const container = getVueComponentPropertiesContainer(vueNode.node)

container.properties.push({
type: 'array',
name: node.value,
groupName: 'props',
node
})
},
/*
computed: mapGetters(['count1', 'count2'])

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

container.properties.push({
type: 'array',
name: node.value,
groupName: 'props',
node
})
},
/*
computed: mapGetters({
count: 'todosCount'
})

computed: {
...mapGetters({
count: 'todosCount'
})
}
*/
'CallExpression[callee.name=mapGetters][arguments] ObjectExpression Identifier[name]'(
node,
vueNode
) {
const container = getVueComponentPropertiesContainer(vueNode.node)

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

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

for (const watcherOrExpose of utils.iterateProperties(
node,
Expand Down Expand Up @@ -495,8 +675,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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-vue",
"version": "9.17.0",
"version": "9.17.2",
"description": "Official ESLint plugin for Vue.js",
"main": "lib/index.js",
"scripts": {
Expand Down Expand Up @@ -93,4 +93,4 @@
"typescript": "^5.1.6",
"vitepress": "^1.0.0-beta.6"
}
}
}
Loading