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.28k stars 1.58k forks source link

proposal: avoid_shadowing_core_libraries_identifiers #59566

Open mateusfccp opened 2 weeks ago

mateusfccp commented 2 weeks ago

avoid_shadowing_core_libraries_identifiers

Description

Avoid shadowing identifiers provided by core (dart:*) libraries.

Details

It's not an error to shadow identifiers provided by core libraries.

For instance, one can define a class named Type and no error will be emitted.

Even though the identifier is present in the scope, there's an exception that allows a declaration from a non-system library to shadow declarations from system libraries.

This is usually undesired, and may be done without the programmer realizing that he is shadowing a core identifier.

Kind

Guard against errors.

Bad Examples

// Bad
class Type {}

Good Examples

// Good
class MyType {}

Discussion

Similar to dart-lang/sdk#58326 (the cause is the same, but while the mentioned issue is related to importing, this one is related to the declaration of the identifiers themselves).