Skip to content

lint to dissallow _ prefix for non private identifiers #58371

@pq

Description

@pq

This has come up in as an issue internally for readability.

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, parameters, local functions, or library prefixes. 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.

from: https://dart.dev/guides/language/effective-dart/style#dont-use-a-leading-underscore-for-identifiers-that-arent-private

It was proposed that this could be folded into non_constant_identifiers but I worry that may hurt adoption so I suggest a new lint. Something like non_private_identifier_names?

/cc @jefflim-google @davidmorgan

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions