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

False positives for `ember/use-ember-get-and-set`

Open firebluetom opened this issue 3 years ago • 3 comments

When using structures that like TrackedMap or URLSearchParams, which have getters, the lint rule identifies this as a violation. Ex:

ember/use-ember-get-and-set

import { TrackedMap } from 'tracked-built-ins'; // https://www.npmjs.com/package/tracked-built-ins

class CustomNavigationContextRouterService extends Service {
  someMap = new TrackedMap();
  
  @service('router')
  router;

  someMapMethod() {
    const value =  someMap.get('someKey'); // violation
    // do stuff
  }

  someURLParamsMethod() {
    const urlParamString = this.router.currentURL.split('?').pop();
    const urlParams = new URLSearchParams(urlParamString);
    const value = urlParams.get('someParamKey'); // violation
    // do stuff
  }
}

firebluetom avatar Jul 15 '22 19:07 firebluetom

What rule?

bmish avatar Jul 15 '22 20:07 bmish

What rule?

ember/use-ember-get-and-set

firebluetom avatar Jul 15 '22 21:07 firebluetom

There are a few related issues like #243 if you search the issues in this repo for the rule name.

It seems like this rule could potentially be smarter and ignore variables where we can tell they are initialized to an irrelevant class.

Two eslint-utils helpers that could help with this detection (for usage examples, see the codebase of eslint-plugin-eslint-plugin):

  • https://eslint-utils.mysticatea.dev/api/ast-utils.html#getstaticvalue
  • https://eslint-utils.mysticatea.dev/api/scope-utils.html#findvariable

bmish avatar Jul 15 '22 21:07 bmish