question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[no-assignment-of-untracked-properties-used-in-tracking-contexts] False positive with constructors?

See original GitHub issue

Not absolutely sure about that. I’m getting that warning for some assignments in a constructor. That is, I have a native JS class that uses @computed in it and sets in the constructor some properties that are used in that @computed… should this assignment be done via Ember.set or is this a false-positive?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
bmishcommented, Jun 26, 2020

I am assuming you are talking about this example:

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

export default class MyComponent extends Component {
  constructor() {
    super();

    this.x = 123; // this should use `set` according to ember/no-assignment-of-untracked-properties-used-in-tracking-contexts
  }

  @computed('x')
  get myProp() {
    return this.x;
  }
}

Using set in the constructor seems like a good thing to do for consistency, given that we should be using set when modifying this property anywhere else in the file.

But is it actually required to use set for this property in the constructor? Probably not? So I’d be open to any of these changes to the rule:

  1. Update the rule to always ignore constructors.
  2. Add an ignoreConstructors option (default true).
  3. Add an ignoreConstructors option (default false).
  4. No change.

@rwjblue @pzuraq @mongoose700 thoughts?

0reactions
bmishcommented, Jun 30, 2020

Hmm! I’m a big fan of the consistency argument. It’s confusing to use set in some places but assignment in other places for the same property. So perhaps enforcing consistency even if set isn’t needed in the constructor is actually a feature and not a bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

False positive S1172 for constructor parameter - Sonar
A false-positive is when an issue is raised unexpectedly on code that should not trigger an issue, or where the suggested action doesn't...
Read more >
[no-useless-constructor] False positive on strictly-typed ...
constructors marked as protected / private (i.e. marking a constructor as non-public),. This rule is literally not working as expected ‍♂️ ...
Read more >
1136086 - clang's - Monorail
Issue 1136086 : clang's -Wglobal-constructors has a lot of false-positives. Reported by schedule agrieve@chromium.org agrieve@chromium.org.
Read more >
squid:S2221: False Positives for constructors - Google Groups
This works fine for methods, but it produces false-positives for constructors. Assume the following class: class ExceptionThrower {
Read more >
Constructor Description | F-Secure Labs
Constructor, Virtools. Summary. A Constructor is a malware creation toolkit that allows users with little technical knowledge to ... (a False Positive)? ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found