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

Consider omit_local_variable_types for inclusion #24

Open
mit-mit opened this issue May 12, 2021 · 3 comments
Open

Consider omit_local_variable_types for inclusion #24

mit-mit opened this issue May 12, 2021 · 3 comments

Comments

@mit-mit
Copy link
Member

mit-mit commented May 12, 2021

The Dart style guide has long recommended omit_local_variable_types. This however is somewhat in conflict with Flutter samples and style.

We should consider the path forward here, and if this can be included in recommended lints.

@eernstg
Copy link
Member

eernstg commented May 12, 2021

How about considering a variant of omit_local_variable_types that only flags local variables with a declared type when the variable has an initializing expression whose type is trivial?

There is no need to work on perfecting the notion of 'trivial' here, we just need to recognize some specific cases, e.g.:

  • A non-collection literal (var x = 1; var y = true; var z = #foo;).
  • A collection literal with explicit type arguments (var x = <int>[17, 18]; var y = <String, String>{};).
  • A non-empty collection literal whose elements have the same trivial type (var xs = [1, 2]; but not var ys = [1, 1.5];).
  • An instance creation, and if generic: with explicit type arguments (var x = C<int>();).

Surely we could add more elements to this list, but again: It is not required that we get a perfect list of trivial types, we just want a useful one.

For a local variable with any other initializing expression a declared type would be tolerated (not required), we just want to get rid of the ones that are actually useless, and that is not true for some of the cases that are currently flagged by omit_local_variable_types (cf. dart-lang/linter#1586).

@goderbauer
Copy link
Contributor

Currently, omit_local_variable_types is too strict and removes too many useful type information whose omission makes it harder to read the code and requires more context switching to collect type information from various parts of the code base to understand what's going on.

A scaled back version of that lint that only removes obvious types is an interesting idea, though...

@pq
Copy link
Member

pq commented May 12, 2021

See also dart-lang/linter#2591 for discussion along the lines of @eernstg's proposal above.

@mit-mit mit-mit added this to Triage backlog in Lints triage Jan 10, 2022
@mit-mit mit-mit self-assigned this Jan 11, 2022
@mit-mit mit-mit moved this from Triage backlog to Icebox in Lints triage Jan 11, 2022
@devoncarew devoncarew changed the title Consider 'omit_local_variable_types' for inclusion Consider omit_local_variable_types for inclusion Jun 1, 2023
@mit-mit mit-mit removed their assignment Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: More investigation needed
Lints triage
Needs work/investigation
Development

No branches or pull requests

4 participants