eslint-plugin-ember icon indicating copy to clipboard operation
eslint-plugin-ember copied to clipboard

avoid-leaking-state-in-ember-objects should rule apply to service variable as well?

Open balasiya opened this issue 2 years ago • 3 comments

Team,

avoid-leaking-state-in-ember-objects this rule is applicable to ember service as well, as service is singleton model, how this create a leak in the variable?

balasiya avatar May 26 '23 10:05 balasiya

Can you provide a code sample that you want to be caught by the rule?

bmish avatar May 26 '23 12:05 bmish

In our app we have a service named file, we have different routes where when file is set to favorite we will add it to service array favoritedFiles service sample code is below

import Service, { inject as service } from '@ember/service';

export default Service.extend({ favoritedFiles: [] });

but for this we are throwing lint error for leak state

How do we prevent this?? since service is a singleton, does this will leak?

balasiya avatar May 26 '23 13:05 balasiya

I'm not sure if that should be considered an error. You may want to post the question on the Ember Discord, and let us know what you find out. Either way, it's a good idea to move to a native class regardless.

https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/avoid-leaking-state-in-ember-objects.md

bmish avatar May 29 '23 14:05 bmish