Skip to content

no_leading_underscores_for_local_identifiers doesn't complain about local functions #58715

Closed
dart-archive/linter
#3361

Description

@goderbauer

The following code does not produce a no_leading_underscores_for_local_identifiers lint, even though I would have expected it to complain about _bar:

int foo() {
  int _bar() { // Why no no_leading_underscores_for_local_identifiers lint here?
    return 10;
  }
  return _bar();
}

Complaining here would also seem to be in line with "Effective Dart" [1] (emphasize mine):

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.

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

Activity

  1. goderbauer commented on Apr 25, 2022

    @goderbauer
    ContributorAuthor

    For extra context, I noticed this while reviewing flutter/flutter#102419. The tests there use local functions with leading underscores and our analysis check is green with the no_leading_underscores_for_local_identifiers enabled.

  2. pq commented on Apr 25, 2022

    @pq
    Member

    100% agreed. This one was just an oversight. Fixing now.

    Thanks!

  3. self-assigned this
    on Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

devexp-linterIssues with the analyzer's support for the linter packagelegacy-area-analyzerUse area-devexp instead.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions