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

changes to prefer_final_locals breaking flutter analyze trybot #1342

Closed
pq opened this issue Jan 3, 2019 · 8 comments
Closed

changes to prefer_final_locals breaking flutter analyze trybot #1342

pq opened this issue Jan 3, 2019 · 8 comments
Labels
customer-flutter type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@pq
Copy link
Member

pq commented Jan 3, 2019

https://ci.chromium.org/p/dart/builders/luci.dart.ci.sandbox/flutter-analyze/107

841 issues like this:

   info • Prefer final for variable declaration if reference is not reassigned • dev/benchmarks/microbenchmarks/lib/common.dart:54:27 • prefer_final_locals
   info • Prefer final for variable declaration if reference is not reassigned • dev/benchmarks/microbenchmarks/lib/common.dart:62:27 • prefer_final_locals
   info • Prefer final for variable declaration if reference is not reassigned • dev/benchmarks/microbenchmarks/lib/gestures/velocity_tracker_bench.dart:18:23 • prefer_final_locals
   info • Prefer final for variable declaration if reference is not reassigned • dev/bots/analyze-sample-code.dart:148:17 • prefer_final_locals
   info • Prefer final for variable declaration if reference is not reassigned • dev/bots/analyze-sample-code.dart:171:21 • prefer_final_locals
   info • Prefer final for variable declaration if reference is not reassigned • dev/bots/analyze-sample-code.dart:255:15 • prefer_final_locals
   info • Prefer final for variable declaration if reference is not reassigned • dev/bots/analyze-sample-code.dart:268:19 • prefer_final_locals
   info • Prefer final for variable declaration if reference is not reassigned • dev/bots/analyze-sample-code.dart:379:18 • prefer_final_locals
   info • Prefer final for variable declaration if reference is not reassigned • dev/bots/analyze-sample-code.dart:382:18 • prefer_final_locals
   info • Prefer final for variable declaration if reference is not reassigned • dev/bots/analyze-sample-code.dart:519:17 • prefer_final_locals
   info • Prefer final for variable declaration if reference is not reassigned • dev/bots/analyze-sample-code.dart:734:18 • prefer_final_locals
   info • Prefer final for variable declaration if reference is not reassigned • dev/bots/analyze-sample-code.dart:794:17 • prefer_final_locals

...

Addressing these warnings blocks integration of 0.1.77. A few options:

  1. fix flutter code to produce warnings
  2. disable the lint in flutter
  3. revert the change to the rule and re-publish

Regardless of what we decide we should probably start w/

  1. review the new warnings to see if they're adding value (or possibly false positives)

/cc @srawlins

@pq pq added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) customer-flutter labels Jan 3, 2019
@srawlins
Copy link
Member

srawlins commented Jan 3, 2019

I think that whatever value is provided by prefer_final_locals is also provided when applying it to for-each loop variables. It's definitely not in most people's muscle memory, but if a team wants the benefits that this rule provides, I think it should be applied to for-each loop variables as well.

@pq
Copy link
Member Author

pq commented Jan 3, 2019

Thanks! I guess the question now becomes whether these new semantics line up with what Flutter wants from the rule.

@Hixie, curious how you feel. With Sam's fix, the follow code now lints:

  for (var i in [1, 2, 3]) { // LINT
    print(i);
  }

and should read:

  for (final i in [1, 2, 3]) { // OK
    print(i);
  }

If you're OK with that change, we can put together a PR to fix up the Flutter codebase.

@srawlins
Copy link
Member

srawlins commented Jan 3, 2019

I think the more egregious / non-muscle-memory changes are when an explicit type is provided, like:

for (final _BenchmarkResult result in _results) {
  results[result.name] = result.value;
}

@Hixie
Copy link

Hixie commented Jan 3, 2019

Yeah, as much as I like final, I'd really rather we just change the language to (as a file-level opt-in, maybe?) default everything to final unless you explicitly say var, than having final in for loop declarations and argument declarations and everything. It's pretty verbose already as it is.

@pq
Copy link
Member Author

pq commented Jan 3, 2019

I'd really rather we just change the language

I agree with this. As a general rule I think mutability is the degenerate case and not the other way around.

That said, we do have a decision to make here. I think our choices are probably down to:

  1. lumping it and verbosifying flutter code to remove warnings
  2. disable the lint in flutter
  3. revert the change to the rule and re-publish

If we opt for 3, it may make sense to add a new rule (sigh) for this case specifically (something like prefer_final_iterators... 😬 ).

/cc @bwilkerson FYI

@Hixie
Copy link

Hixie commented Jan 3, 2019

I definitely would go for 3b (have separate lints for variable declarations, parameters, for loop variables, etc).

@pq
Copy link
Member Author

pq commented Jan 4, 2019

I agree w/ @Hixie. Lets roll this back and break it out into a separate lint as proposed by @srawlins in #1346.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-flutter type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants