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

New Rule: no-self-referencing-properties

Open runspired opened this issue 4 years ago • 2 comments

This rule would catch the issue that led to the bug in #1118

This rule would lint all macros as well as computed properties and getters for self-referential behavior. It would be applied to classic syntax as well as native syntax.

import Component from '@ember/component';
import { computed } from '@ember/object';
import { reads } from '@ember/object/computed';

export default MyComponent extends Component {
  // BAD
  get foo() {
    return this.foo;
  }
  
  // BAD
  @computed('bar')
  get bar() {
    return this.bar;
  }
  
  // BAD
  @computed('not-biz')
  get biz() {
    return this.biz;
  }
  
  // BAD
  @reads('baz') baz;
}

runspired avatar Mar 29 '21 23:03 runspired

Seems good, though I'm not 100% sure this belongs in eslint-plugin-ember. It doesn't really seem like an "ember thing", it seems like a generate JavaScript best practice thing...

rwjblue avatar Apr 12 '21 17:04 rwjblue

@rwjblue confirm, though since macros have this issue too there will be at least a component of it that pertains to us.

runspired avatar Apr 12 '21 18:04 runspired