eslint-plugin-ember
eslint-plugin-ember copied to clipboard
no-assignment-of-untracked-properties-used-in-tracking-contexts causing false positives in constructor
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?
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.
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 🤔
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.