Skip to content
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

cascade_invocations: Don't trigger on ?? assignments #57640

Closed
matanlurey opened this issue Oct 20, 2017 · 5 comments
Closed

cascade_invocations: Don't trigger on ?? assignments #57640

matanlurey opened this issue Oct 20, 2017 · 5 comments
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-false-positive type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@matanlurey
Copy link
Contributor

void log(String message, {Level severity}) {
  final Logger logger = Zone.current[_zoneKey] ?? _defaultLogger;
  // ignore: cascade_invocations
  logger.log(message, severity: severity);
}

Yeah, I could have written:

void log(String message, {Level severity}) {
  ((Zone.current[_zoneKey] ?? _defaultLogger) as Logger).log(...)
}

But that really harms readability just to play code golf.

@aemino
Copy link

aemino commented Oct 20, 2017

Given #57626 and #57631, it seems like at the present moment, the cascade_invocations rule has a lot of potential to cause false positives that lead to unwieldy code as a "solution". Perhaps simply having the rule deprecate itself in the case of assignments would solve these issues?

@aemino
Copy link

aemino commented Nov 1, 2017

@pq @bwilkerson What do you guys think about this?

@bwilkerson
Copy link
Member

Perhaps simply having the rule deprecate itself in the case of assignments would solve these issues?

I'm not sure I understand what you're suggesting here. The rule is intended to catch (among other things) code in which the first statement is an assignment. Are you suggesting that we disable the rule for all code containing an assignment (and adjust the rule's description)? (I'm not necessarily opposed, just clarifying.)

I agree that it's a problem when the assignment causes an implicit cast or when the assignment needs to happen before the cascaded expressions are executed. We ought to be able to detect the first case, but I don't think we can reliably detect the second case.

@alexeieleusis (another issue to contemplate)

@aemino
Copy link

aemino commented Nov 1, 2017

Actually, reading through these issues again, I would like to amend my previous comment. While I originally was indeed suggesting disabling the rule for assignments, I think that's a bit rash.

I think we should definitely disable the lint in the case of implicit casts. Whether we do so for assignments with ?? though, I'm still uncertain.

@pq pq added linter-false-positive type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jun 27, 2018
@matanlurey
Copy link
Contributor Author

I no longer feel passionate about this issue :)

@devoncarew devoncarew added analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Nov 18, 2024
@devoncarew devoncarew transferred this issue from dart-lang/linter Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-false-positive type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants