Skip to content

Consider adding no_leading_underscores_for_local_identifiers to recommended #758

Closed
dart-archive/lints
#72
@pq

Description

@pq

no_leading_underscores_for_local_identifiers would be a good candidate for recommended if not core.

Lint Description:

DON’T use a leading underscore for identifiers that aren't private. Dart
uses a leading underscore in an identifier to mark members and top-level
declarations as private. This trains users to associate a leading underscore
with one of those kinds of declarations. They see _ and think "private".
There is no concept of "private" for local variables or parameters. When one of
those has a name that starts with an underscore, it sends a confusing signal to
the reader. To avoid that, don't use leading underscores in those names.

Exception: An unused parameter can be named _, __, ___, etc. This is
common practice in callbacks where you are passed a value but you don't need
to use it. Giving it a name that consists solely of underscores is the idiomatic
way to indicate that the value isn't used.

BAD

void print(String _name) {
  var _size = _name.length;
  ...
}

GOOD:

void print(String name) {
  var size = name.length;
  ...
}

OK:

[1,2,3].map((_) => print('Hello'));

We might also consider no_leading_underscores_for_library_prefixes.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions