dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.11k stars 1.56k forks source link

Lint idea: top-level `final`/`const` variable defined without explicit type #56805

Open GregoryConrad opened 1 day ago

GregoryConrad commented 1 day ago

This would be a nice-to-have opt-in lint. Can helpful when handling more complex types.

GOOD:

const int i = 0;
final ComplexType foo = createThing();

BAD:

const i = 0;
final foo = createThing();

Rationale: increases code readability (especially for code reviews, when you don't have an IDE handy) by having type information specified explicitly in the source code. While it is sometimes obvious (like in the case of the const int i = 0 above), it is fairly useful when dealing with non-obvious types.

dart-github-bot commented 1 day ago

Summary: The issue proposes a new lint rule that flags top-level final and const variables without explicit type declarations. This rule aims to improve code readability by encouraging explicit type annotations, especially for complex types.