From 0796d6050c37ed6e8862559459166d3f2cbd4cbc Mon Sep 17 00:00:00 2001 From: Akhmedov Farid Date: Thu, 17 Aug 2023 01:31:39 +0700 Subject: [PATCH 1/7] Add Vuex's mapX functions to no-unused-properties --- lib/rules/no-unused-properties.js | 171 +++++++ tests/lib/rules/no-unused-properties.js | 641 ++++++++++++++++++++++++ 2 files changed, 812 insertions(+) diff --git a/lib/rules/no-unused-properties.js b/lib/rules/no-unused-properties.js index fd9b0df2c..d86607519 100644 --- a/lib/rules/no-unused-properties.js +++ b/lib/rules/no-unused-properties.js @@ -453,6 +453,176 @@ module.exports = { } }), utils.defineVueVisitor(context, { + /* + methods: mapMutations({ + add: 'increment' + }) + + methods: { + ...mapMutations({ + add: 'increment' + }) + } + */ + 'CallExpression[callee.name=mapMutations][arguments] ObjectExpression Property[key.name]'( + node + ) { + const container = getVueComponentPropertiesContainer(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 + ) { + const container = getVueComponentPropertiesContainer(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 + ) { + const container = getVueComponentPropertiesContainer(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 + ) { + const container = getVueComponentPropertiesContainer(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 + ) { + const container = getVueComponentPropertiesContainer(node) + + container.properties.push({ + type: 'array', + name: node.key.name, + groupName: 'props', + node + }) + }, + 'CallExpression[callee.name=mapState][arguments] ArrayExpression Literal[value]'( + node + ) { + const container = getVueComponentPropertiesContainer(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 + ) { + const container = getVueComponentPropertiesContainer(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 + ) { + const container = getVueComponentPropertiesContainer(node) + + container.properties.push({ + type: 'array', + name: node.name, + groupName: 'props', + node + }) + }, + onVueObjectEnter(node) { const container = getVueComponentPropertiesContainer(node) @@ -497,6 +667,7 @@ module.exports = { } container.properties.push(...utils.iterateProperties(node, groups)) }, + /** @param { (FunctionExpression | ArrowFunctionExpression) & { parent: Property }} node */ 'ObjectExpression > Property > :function[params.length>0]'( node, diff --git a/tests/lib/rules/no-unused-properties.js b/tests/lib/rules/no-unused-properties.js index 0139559b1..1ab5918d4 100644 --- a/tests/lib/rules/no-unused-properties.js +++ b/tests/lib/rules/no-unused-properties.js @@ -53,6 +53,267 @@ const unreferencedOptions = { tester.run('no-unused-properties', rule, { valid: [ + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, // a property used in a script expression { filename: 'test.vue', @@ -1730,6 +1991,386 @@ tester.run('no-unused-properties', rule, { } ], invalid: [ + { + filename: 'test.vue', + code: ` + + + `, + errors: [ + { + message: "'add2' of method found, but never used.", + line: 5 + } + ] + }, + { + filename: 'test.vue', + code: ` + + + `, + errors: [ + { + message: "'add2' of method found, but never used.", + line: 6 + } + ] + }, + { + filename: 'test.vue', + code: ` + + + `, + errors: [ + { + message: "'add2' of method found, but never used.", + line: 4 + } + ] + }, + { + filename: 'test.vue', + code: ` + + + `, + errors: [ + { + message: "'add2' of method found, but never used.", + line: 6 + } + ] + }, + { + filename: 'test.vue', + code: ` + + + `, + errors: [ + { + message: "'add2' of method found, but never used.", + line: 6 + } + ] + }, + { + filename: 'test.vue', + code: ` + + + `, + errors: [ + { + message: "'add2' of method found, but never used.", + line: 5 + } + ] + }, + { + filename: 'test.vue', + code: ` + + + `, + errors: [ + { + message: "'add2' of method found, but never used.", + line: 4 + } + ] + }, + { + filename: 'test.vue', + code: ` + + + `, + errors: [ + { + message: "'add2' of method found, but never used.", + line: 5 + } + ] + }, + { + filename: 'test.vue', + code: ` + + + `, + errors: [ + { + message: "'count2' of property found, but never used.", + line: 5 + } + ] + }, + { + filename: 'test.vue', + code: ` + + + `, + errors: [ + { + message: "'count2' of property found, but never used.", + line: 6 + } + ] + }, + { + filename: 'test.vue', + code: ` + + + `, + errors: [ + { + message: "'count2' of property found, but never used.", + line: 5 + } + ] + }, + { + filename: 'test.vue', + code: ` + + + `, + errors: [ + { + message: "'count2' of property found, but never used.", + line: 5 + } + ] + }, + { + filename: 'test.vue', + code: ` + + + `, + errors: [ + { + message: "'count' of property found, but never used.", + line: 4 + } + ] + }, + { + filename: 'test.vue', + code: ` + + + `, + errors: [ + { + message: "'count2' of property found, but never used.", + line: 5 + } + ] + }, + { + filename: 'test.vue', + code: ` + + + `, + errors: [ + { + message: "'count3' of property found, but never used.", + line: 7 + } + ] + }, + + // vuex unused state + { + filename: 'test.vue', + code: ` + + + `, + errors: [ + { + message: "'count' of property found, but never used.", + line: 5 + } + ] + }, + + // vuex unused state + { + filename: 'test.vue', + code: ` + + + `, + errors: [ + { + message: "'additional' of property found, but never used.", + line: 5 + } + ] + }, + // unused property { filename: 'test.vue', From 281e06ae3381b8134e8a6aaf3b784cb840ad0df3 Mon Sep 17 00:00:00 2001 From: Akhmedov Farid Date: Thu, 17 Aug 2023 01:33:31 +0700 Subject: [PATCH 2/7] 9.17.1 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index eb3750f4a..52c4c6df6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-vue", - "version": "9.17.0", + "version": "9.17.1", "description": "Official ESLint plugin for Vue.js", "main": "lib/index.js", "scripts": { @@ -93,4 +93,4 @@ "typescript": "^5.1.6", "vitepress": "^1.0.0-beta.6" } -} +} \ No newline at end of file From d832570e71f1efeb4584a8d6634b1efe9d7964cd Mon Sep 17 00:00:00 2001 From: Akhmedov Farid Date: Thu, 17 Aug 2023 02:28:31 +0700 Subject: [PATCH 3/7] Fix vuex node matching for no-unused-properties --- lib/rules/no-unused-properties.js | 47 +++++++++++++++---------- tests/lib/rules/no-unused-properties.js | 21 +++++++++++ 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/lib/rules/no-unused-properties.js b/lib/rules/no-unused-properties.js index d86607519..48eff05bb 100644 --- a/lib/rules/no-unused-properties.js +++ b/lib/rules/no-unused-properties.js @@ -268,6 +268,7 @@ module.exports = { } return container } + /** * @param {string[]} segments * @param {Expression} propertyValue @@ -350,6 +351,7 @@ module.exports = { ) { continue } + if (propertyReferences.hasProperty(property.name)) { // used if ( @@ -465,9 +467,10 @@ module.exports = { } */ 'CallExpression[callee.name=mapMutations][arguments] ObjectExpression Property[key.name]'( - node + node, + vueNode ) { - const container = getVueComponentPropertiesContainer(node) + const container = getVueComponentPropertiesContainer(vueNode.node) container.properties.push({ type: 'array', @@ -484,9 +487,10 @@ module.exports = { } */ 'CallExpression[callee.name=mapMutations][arguments] ArrayExpression Literal[value]'( - node + node, + vueNode ) { - const container = getVueComponentPropertiesContainer(node) + const container = getVueComponentPropertiesContainer(vueNode.node) container.properties.push({ type: 'array', @@ -507,9 +511,10 @@ module.exports = { } */ 'CallExpression[callee.name=mapActions][arguments] ObjectExpression Property[key.name]'( - node + node, + vueNode ) { - const container = getVueComponentPropertiesContainer(node) + const container = getVueComponentPropertiesContainer(vueNode.node) container.properties.push({ type: 'array', @@ -527,9 +532,10 @@ module.exports = { } */ 'CallExpression[callee.name=mapActions][arguments] ArrayExpression Literal[value]'( - node + node, + vueNode ) { - const container = getVueComponentPropertiesContainer(node) + const container = getVueComponentPropertiesContainer(vueNode.node) container.properties.push({ type: 'array', @@ -557,9 +563,10 @@ module.exports = { }) */ 'CallExpression[callee.name=mapState][arguments] ObjectExpression Property[key.name]'( - node + node, + vueNode ) { - const container = getVueComponentPropertiesContainer(node) + const container = getVueComponentPropertiesContainer(vueNode.node) container.properties.push({ type: 'array', @@ -569,9 +576,10 @@ module.exports = { }) }, 'CallExpression[callee.name=mapState][arguments] ArrayExpression Literal[value]'( - node + node, + vueNode ) { - const container = getVueComponentPropertiesContainer(node) + const container = getVueComponentPropertiesContainer(vueNode.node) container.properties.push({ type: 'array', @@ -588,9 +596,10 @@ module.exports = { } */ 'CallExpression[callee.name=mapGetters][arguments] ArrayExpression Literal[value]'( - node + node, + vueNode ) { - const container = getVueComponentPropertiesContainer(node) + const container = getVueComponentPropertiesContainer(vueNode.node) container.properties.push({ type: 'array', @@ -611,9 +620,10 @@ module.exports = { } */ 'CallExpression[callee.name=mapGetters][arguments] ObjectExpression Identifier[name]'( - node + node, + vueNode ) { - const container = getVueComponentPropertiesContainer(node) + const container = getVueComponentPropertiesContainer(vueNode.node) container.properties.push({ type: 'array', @@ -623,8 +633,8 @@ module.exports = { }) }, - onVueObjectEnter(node) { - const container = getVueComponentPropertiesContainer(node) + onVueObjectEnter(node, vueNode) { + const container = getVueComponentPropertiesContainer(vueNode.node) for (const watcherOrExpose of utils.iterateProperties( node, @@ -665,6 +675,7 @@ module.exports = { ) } } + container.properties.push(...utils.iterateProperties(node, groups)) }, diff --git a/tests/lib/rules/no-unused-properties.js b/tests/lib/rules/no-unused-properties.js index 1ab5918d4..2189a90b4 100644 --- a/tests/lib/rules/no-unused-properties.js +++ b/tests/lib/rules/no-unused-properties.js @@ -53,6 +53,27 @@ const unreferencedOptions = { tester.run('no-unused-properties', rule, { valid: [ + { + filename: 'test.vue', + code: ` + + + `, + options: allOptions + }, { filename: 'test.vue', code: ` From 63e7dac2483b67ab7d4453da30cd7014e52f472b Mon Sep 17 00:00:00 2001 From: Akhmedov Farid Date: Thu, 17 Aug 2023 02:28:35 +0700 Subject: [PATCH 4/7] 9.17.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 52c4c6df6..6ef49687d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-vue", - "version": "9.17.1", + "version": "9.17.2", "description": "Official ESLint plugin for Vue.js", "main": "lib/index.js", "scripts": { From 98dcf4867f806c4199148c68b5e694dc9b16d59d Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Fri, 15 Sep 2023 17:19:11 +0200 Subject: [PATCH 5/7] Discard changes to package.json --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6ef49687d..eb3750f4a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-vue", - "version": "9.17.2", + "version": "9.17.0", "description": "Official ESLint plugin for Vue.js", "main": "lib/index.js", "scripts": { @@ -93,4 +93,4 @@ "typescript": "^5.1.6", "vitepress": "^1.0.0-beta.6" } -} \ No newline at end of file +} From 12797d7a31ac50ae681c4504327505e144d422af Mon Sep 17 00:00:00 2001 From: Akhmedov Farid Date: Fri, 17 Nov 2023 23:32:21 +0700 Subject: [PATCH 6/7] Resolve review issues - reduce duplicated code - improve error message - remove duplicated test --- lib/rules/no-unused-properties.js | 108 ++++-------------------- tests/lib/rules/no-unused-properties.js | 57 +++++++------ 2 files changed, 49 insertions(+), 116 deletions(-) diff --git a/lib/rules/no-unused-properties.js b/lib/rules/no-unused-properties.js index 48eff05bb..eb0589f3a 100644 --- a/lib/rules/no-unused-properties.js +++ b/lib/rules/no-unused-properties.js @@ -456,17 +456,15 @@ module.exports = { }), utils.defineVueVisitor(context, { /* - methods: mapMutations({ - add: 'increment' - }) + mapActions or mapMutations. + + methods: mapMutations({ add: 'increment' }) methods: { - ...mapMutations({ - add: 'increment' - }) + ...mapMutations({ add: 'increment' }) } */ - 'CallExpression[callee.name=mapMutations][arguments] ObjectExpression Property[key.name]'( + 'CallExpression[callee.name=/^(mapMutations|mapActions)$/][arguments] ObjectExpression Property[key.name]'( node, vueNode ) { @@ -479,14 +477,17 @@ module.exports = { node }) }, + /* + mapActions or mapMutations. + methods: mapMutations(['add']) methods: { ...mapMutations(['add']) } */ - 'CallExpression[callee.name=mapMutations][arguments] ArrayExpression Literal[value]'( + 'CallExpression[callee.name=/^(mapMutations|mapActions)$/][arguments] ArrayExpression Literal[value]'( node, vueNode ) { @@ -499,53 +500,10 @@ module.exports = { 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']) + mapState or mapGetters. - 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 }) @@ -562,7 +520,7 @@ module.exports = { } }) */ - 'CallExpression[callee.name=mapState][arguments] ObjectExpression Property[key.name]'( + 'CallExpression[callee.name=/^(mapState|mapGetters)$/][arguments] ObjectExpression Property[key.name]'( node, vueNode ) { @@ -571,31 +529,21 @@ module.exports = { container.properties.push({ type: 'array', name: node.key.name, - groupName: 'props', + groupName: 'computed', 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 - }) - }, /* + mapState or mapGetters. + computed: mapGetters(['count1', 'count2']) computed: { ...mapGetters(['count']), } */ - 'CallExpression[callee.name=mapGetters][arguments] ArrayExpression Literal[value]'( + 'CallExpression[callee.name=/^(mapState|mapGetters)$/][arguments] ArrayExpression Literal[value]'( node, vueNode ) { @@ -604,31 +552,7 @@ module.exports = { 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', + groupName: 'computed', node }) }, diff --git a/tests/lib/rules/no-unused-properties.js b/tests/lib/rules/no-unused-properties.js index 2189a90b4..da4b5e926 100644 --- a/tests/lib/rules/no-unused-properties.js +++ b/tests/lib/rules/no-unused-properties.js @@ -320,21 +320,6 @@ tester.run('no-unused-properties', rule, { ` }, - { - filename: 'test.vue', - code: ` - - - ` - }, // a property used in a script expression { filename: 'test.vue', @@ -2203,7 +2188,7 @@ tester.run('no-unused-properties', rule, { `, errors: [ { - message: "'count2' of property found, but never used.", + message: "'count2' of computed property found, but never used.", line: 5 } ] @@ -2227,7 +2212,7 @@ tester.run('no-unused-properties', rule, { `, errors: [ { - message: "'count2' of property found, but never used.", + message: "'count2' of computed property found, but never used.", line: 6 } ] @@ -2254,7 +2239,7 @@ tester.run('no-unused-properties', rule, { `, errors: [ { - message: "'count2' of property found, but never used.", + message: "'count2' of computed property found, but never used.", line: 5 } ] @@ -2275,7 +2260,7 @@ tester.run('no-unused-properties', rule, { `, errors: [ { - message: "'count2' of property found, but never used.", + message: "'count2' of computed property found, but never used.", line: 5 } ] @@ -2294,7 +2279,7 @@ tester.run('no-unused-properties', rule, { `, errors: [ { - message: "'count' of property found, but never used.", + message: "'count' of computed property found, but never used.", line: 4 } ] @@ -2316,7 +2301,7 @@ tester.run('no-unused-properties', rule, { `, errors: [ { - message: "'count2' of property found, but never used.", + message: "'count2' of computed property found, but never used.", line: 5 } ] @@ -2340,7 +2325,7 @@ tester.run('no-unused-properties', rule, { `, errors: [ { - message: "'count3' of property found, but never used.", + message: "'count3' of computed property found, but never used.", line: 7 } ] @@ -2363,12 +2348,36 @@ tester.run('no-unused-properties', rule, { `, errors: [ { - message: "'count' of property found, but never used.", + message: "'count' of computed property found, but never used.", line: 5 } ] }, + // vuex unused state + { + filename: 'test.vue', + code: ` + + + `, + errors: [ + { + message: "'count2' of computed property found, but never used.", + line: 6 + } + ] + }, + // vuex unused state { filename: 'test.vue', @@ -2386,7 +2395,7 @@ tester.run('no-unused-properties', rule, { `, errors: [ { - message: "'additional' of property found, but never used.", + message: "'additional' of computed property found, but never used.", line: 5 } ] From 22eaa378bcc153e15defa812f53a5914dc5b258c Mon Sep 17 00:00:00 2001 From: Akhmedov Farid Date: Fri, 17 Nov 2023 23:32:21 +0700 Subject: [PATCH 7/7] Resolve review issues - add jsdoc - reuse code from utils --- lib/rules/no-unused-properties.js | 98 ++++++++++++------------------- 1 file changed, 36 insertions(+), 62 deletions(-) diff --git a/lib/rules/no-unused-properties.js b/lib/rules/no-unused-properties.js index eb0589f3a..b64c42d36 100644 --- a/lib/rules/no-unused-properties.js +++ b/lib/rules/no-unused-properties.js @@ -455,103 +455,77 @@ module.exports = { } }), utils.defineVueVisitor(context, { - /* - mapActions or mapMutations. - - methods: mapMutations({ add: 'increment' }) - - methods: { - ...mapMutations({ add: 'increment' }) - } - */ - 'CallExpression[callee.name=/^(mapMutations|mapActions)$/][arguments] ObjectExpression Property[key.name]'( + /** + * e.g. `mapMutations({ add: 'increment' })` + * @param {Property} node + * @param {VueObjectData} vueData + */ + 'CallExpression[callee.name=/^(mapMutations|mapActions)$/][arguments] ObjectExpression Property'( node, - vueNode + vueData ) { - const container = getVueComponentPropertiesContainer(vueNode.node) + const container = getVueComponentPropertiesContainer(vueData.node) container.properties.push({ type: 'array', - name: node.key.name, + name: utils.getStaticPropertyName(node), groupName: 'methods', node }) }, - /* - mapActions or mapMutations. - - methods: mapMutations(['add']) - - methods: { - ...mapMutations(['add']) - } - */ - 'CallExpression[callee.name=/^(mapMutations|mapActions)$/][arguments] ArrayExpression Literal[value]'( + /** + * e.g. `mapMutations(['add'])` + * @param {Literal} node + * @param {VueObjectData} vueData + */ + 'CallExpression[callee.name=/^(mapMutations|mapActions)$/][arguments] ArrayExpression Literal'( node, - vueNode + vueData ) { - const container = getVueComponentPropertiesContainer(vueNode.node) + const container = getVueComponentPropertiesContainer(vueData.node) container.properties.push({ type: 'array', - name: node.value, + name: utils.getStringLiteralValue(node), 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]'( + /** + * e.g. `mapState({ count: state => state.todosCount })` + * @param {Property} node + * @param {VueObjectData} vueData + */ + 'CallExpression[callee.name=/^(mapState|mapGetters)$/][arguments] ObjectExpression Property'( node, - vueNode + vueData ) { - const container = getVueComponentPropertiesContainer(vueNode.node) + const container = getVueComponentPropertiesContainer(vueData.node) container.properties.push({ type: 'array', - name: node.key.name, + name: utils.getStaticPropertyName(node), groupName: 'computed', node }) }, - /* - mapState or mapGetters. - - computed: mapGetters(['count1', 'count2']) - - computed: { - ...mapGetters(['count']), - } - */ - 'CallExpression[callee.name=/^(mapState|mapGetters)$/][arguments] ArrayExpression Literal[value]'( + /** + * e.g. `mapState(['count'])` + * @param {Literal} node + * @param {VueObjectData} vueData + */ + 'CallExpression[callee.name=/^(mapState|mapGetters)$/][arguments] ArrayExpression Literal'( node, - vueNode + vueData ) { - const container = getVueComponentPropertiesContainer(vueNode.node) + const container = getVueComponentPropertiesContainer(vueData.node) container.properties.push({ type: 'array', - name: node.value, + name: utils.getStringLiteralValue(node), groupName: 'computed', node })