Skip to content

avoid_setters_without_getters false positive for Angular components #58039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
davidmorgan opened this issue Oct 24, 2019 · 5 comments
Open
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. customer-google3 devexp-linter Issues with the analyzer's support for the linter package linter-false-positive P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@davidmorgan
Copy link
Contributor

https://dart-lang.github.io/linter/lints/avoid_setters_without_getters.html corresponds to https://dart.dev/guides/language/effective-dart/design#dont-define-a-setter-without-a-corresponding-getter, except that the Effective Dart rule has an exception for Angular components.

We could avoid those false positives by allowing setters without getters when there is an annotation Component.

What do you think, please?

@pq
Copy link
Member

pq commented Oct 24, 2019

Sounds reasonable to me.

@MichaelRFairhurst : any thoughts?

@pq pq added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) customer-google3 linter-false-positive labels Oct 24, 2019
@MichaelRFairhurst
Copy link
Contributor

I'd recommend looking for an @input on the setter itself over an @component (or don't forget @directive) on the class.

However, @input annotations can be inherited, so if you don't want those false positives, and don't want to look up the inheritance tree, then @Component/@directive is probably best.

@pq
Copy link
Member

pq commented Oct 25, 2019

Thanks! Could you give me a concrete test case? That'd help a lot. 👍

@davidmorgan
Copy link
Contributor Author

@matanlurey what do you think, please? Proposal is to make avoid_setters_without_getters ignore Angular components, and the discussion is the best way to identify those Angular setters :)

@MichaelRFairhurst
Copy link
Contributor

Some test cases:

import "package:angular/angular.dart";

@Component(selector: "concrete-comp", template: "")
class ConcreteComponent extends AbstractComponent {
  @Input()
  set classInput(int v) {}
}

@Directive(selector: "[directive]")
class ConcreteDirective extends AbstractDirective {
  @Input()
  set classInput(int v) {}
}

class AbstractComponent {
  @Input()
  set inheritedInput(int v) {}
}

class AbstractDirective {
  @Input()
  set inheritedInput(int v) {}
}

There are also some negative cases I could draw here (positive cases? where the lint should still flag).

import "package:angular/angular.dart";

@Component(selector: "concrete-comp", template: "")
class ConcreteComponent extends AbstractComponent {
  // not an @Input, could/should be flagged
  set classInput(int v) {}
}

@Directive(selector: "[directive]")
class ConcreteDirective extends AbstractDirective {
  // not an @Input, could/should be flagged
  set classInput(int v) {}
}

class AbstractComponent {
  @Input()
  set inheritedInput(int v) {}

  // not an @Input, could/should be flagged
  set rogueSetter(int v) {}
}

class AbstractDirective {
  @Input()
  set inheritedInput(int v) {}

  // not an @Input, could/should be flagged
  set rogueSetter(int v) {}
}

Thinking more on it, there are other fields than @Input to consider too. Like @ContentChild, @ContentChildren, @ViewChild, @ViewChildren. Same concepts apply.

@srawlins srawlins added the P3 A lower priority bug or feature request label Sep 27, 2022
@srawlins srawlins changed the title avoid_setters_without_getters false positives avoid_setters_without_getters false positive for Angular components Nov 11, 2022
@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 18, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 18, 2024
@bwilkerson bwilkerson added area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. and removed legacy-area-analyzer Use area-devexp instead. labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. customer-google3 devexp-linter Issues with the analyzer's support for the linter package linter-false-positive P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

6 participants