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

no-assignment-of-untracked-properties-used-in-tracking-contexts causing false positives in constructor

Open Turbo87 opened this issue 5 years ago • 3 comments

we have something roughly like this:

export default class extends Component {
  address = null;

  @reads('address.foo') foo;

  constructor() {
    super(...arguments);
    this.address = this.args.address || this.store.createRecord('address');
  }
}

and the no-assignment-of-untracked-properties-used-in-tracking-contexts rule is flagging it as an issue. If I understand correctly, this shouldn't be a problem though, since the assignment is happening in the constructor, right?

Turbo87 avatar Sep 14 '20 07:09 Turbo87

A previous issue was filed about this in https://github.com/ember-cli/eslint-plugin-ember/issues/867. At the time, we decided to continue enforcing using set everywhere for consistency, even though it's not necessary in the constructor.

bmish avatar Sep 14 '20 15:09 bmish

hmm... this.set() is not a thing in glimmer components though, and importing the global set() just to please the lint rule seems a bit odd 🤔

Turbo87 avatar Sep 14 '20 15:09 Turbo87

If you're actively avoiding using @tracked address, I think you could do

address = this.args.address || this.store.createRecord('address');

in the initial declaration of address instead of in the constructor.

mongoose700 avatar Sep 19 '20 18:09 mongoose700