diff --git a/lib/rules/no-unused-properties.js b/lib/rules/no-unused-properties.js index d09aca5c2..7eb7eb75d 100644 --- a/lib/rules/no-unused-properties.js +++ b/lib/rules/no-unused-properties.js @@ -496,12 +496,16 @@ module.exports = { let groupName = null if (/^mapMutations|mapActions$/u.test(node.callee.name)) { groupName = 'methods' - } else if (/^mapState|mapGetters$/u.test(node.callee.name)) { + } else if ( + /^mapState|mapGetters|mapWritableState$/u.test(node.callee.name) + ) { groupName = 'computed' } if (!groupName || node.arguments.length === 0) return - const arg = node.arguments[0] + // On Pinia the store is always the first argument + const arg = + node.arguments.length === 2 ? node.arguments[1] : node.arguments[0] if (arg.type === 'ObjectExpression') { // e.g. // `mapMutations({ add: 'increment' })` diff --git a/tests/lib/rules/no-unused-properties.js b/tests/lib/rules/no-unused-properties.js index 65b185298..64e858d31 100644 --- a/tests/lib/rules/no-unused-properties.js +++ b/tests/lib/rules/no-unused-properties.js @@ -53,6 +53,7 @@ const unreferencedOptions = { tester.run('no-unused-properties', rule, { valid: [ + // vuex getters { filename: 'test.vue', code: ` @@ -74,6 +75,68 @@ tester.run('no-unused-properties', rule, { `, options: allOptions }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + { + filename: 'test.vue', + code: ` + + + ` + }, + + // vuex mutations { filename: 'test.vue', code: ` @@ -136,6 +199,8 @@ tester.run('no-unused-properties', rule, { ` }, + + // vuex actions { filename: 'test.vue', code: ` @@ -196,6 +261,8 @@ tester.run('no-unused-properties', rule, { ` }, + + // vuex state { filename: 'test.vue', code: ` @@ -251,7 +318,7 @@ tester.run('no-unused-properties', rule, { @@ -260,27 +327,37 @@ tester.run('no-unused-properties', rule, { ` }, + + // pinia getters { filename: 'test.vue', code: ` - ` + `, + options: allOptions }, { filename: 'test.vue', code: `