@@ -111,6 +111,11 @@ module.exports = {
111
111
) . map ( toRegExp )
112
112
const propertyReferenceExtractor = definePropertyReferenceExtractor ( context )
113
113
const programNode = context . getSourceCode ( ) . ast
114
+ /**
115
+ * Property names identified as defined via a Vuex or Pinia helpers
116
+ * @type {Set<string> }
117
+ */
118
+ const propertiesDefinedByStoreHelpers = new Set ( )
114
119
115
120
/**
116
121
* @param {ASTNode } node
@@ -185,7 +190,8 @@ module.exports = {
185
190
report ( node , name , messageId = 'undef' ) {
186
191
if (
187
192
reserved . includes ( name ) ||
188
- ignores . some ( ( ignore ) => ignore . test ( name ) )
193
+ ignores . some ( ( ignore ) => ignore . test ( name ) ) ||
194
+ propertiesDefinedByStoreHelpers . has ( name )
189
195
) {
190
196
return
191
197
}
@@ -331,6 +337,51 @@ module.exports = {
331
337
}
332
338
} ) ,
333
339
utils . defineVueVisitor ( context , {
340
+ /**
341
+ * @param {CallExpression } node
342
+ */
343
+ CallExpression ( node ) {
344
+ if ( node . callee . type !== 'Identifier' ) return
345
+ /** @type {'methods'|'computed'|null } */
346
+ let groupName = null
347
+ if ( / ^ m a p M u t a t i o n s | m a p A c t i o n s $ / u. test ( node . callee . name ) ) {
348
+ groupName = GROUP_METHODS
349
+ } else if (
350
+ / ^ m a p S t a t e | m a p G e t t e r s | m a p W r i t a b l e S t a t e $ / u. test ( node . callee . name )
351
+ ) {
352
+ groupName = GROUP_COMPUTED_PROPERTY
353
+ }
354
+
355
+ if ( ! groupName || node . arguments . length === 0 ) return
356
+ // On Pinia the store is always the first argument
357
+ const arg =
358
+ node . arguments . length === 2 ? node . arguments [ 1 ] : node . arguments [ 0 ]
359
+ if ( arg . type === 'ObjectExpression' ) {
360
+ // e.g.
361
+ // `mapMutations({ add: 'increment' })`
362
+ // `mapState({ count: state => state.todosCount })`
363
+ for ( const prop of arg . properties ) {
364
+ const name =
365
+ prop . type === 'SpreadElement'
366
+ ? null
367
+ : utils . getStaticPropertyName ( prop )
368
+ if ( name ) {
369
+ propertiesDefinedByStoreHelpers . add ( name )
370
+ }
371
+ }
372
+ } else if ( arg . type === 'ArrayExpression' ) {
373
+ // e.g. `mapMutations(['add'])`
374
+ for ( const element of arg . elements ) {
375
+ if ( ! element || ! utils . isStringLiteral ( element ) ) {
376
+ continue
377
+ }
378
+ const name = utils . getStringLiteralValue ( element )
379
+ if ( name ) {
380
+ propertiesDefinedByStoreHelpers . add ( name )
381
+ }
382
+ }
383
+ }
384
+ } ,
334
385
onVueObjectEnter ( node ) {
335
386
const ctx = getVueComponentContext ( node )
336
387
0 commit comments