Skip to content

[Wildcard Variables][lint] no_wildcard_variable_uses and the new wildcard variables feature. #59470

@kallentu

Description

@kallentu

Changes to make

(Updated May 14th 2024)

  1. Change the documentation of the lint to something like: Wildcard parameters and local variables (whose name is '_' by definition) will become non-binding in a future version of the Dart language.
  2. This lint should WARN on _ (not __ etc) if it's being used.
  3. UNUSED_VARIABLE will have an additional fix to suggest converting to _.

As mentioned from dart-lang/language#3785 (comment).

https://dart.dev/tools/linter-rules/no_wildcard_variable_uses
no_wildcard_variable_uses reports all named underscores, which is more than what we want.

This lint will flag usages of names of the form __, ___ and so on, in addition to _. Does it give rise to unnecessary churn to flag all the names that have more than one underscore, given that they will keep their status as regular (non-wildcard) identifiers? For example, if someone really wants to use local variables with the name _ then they might switch to __ just because it's similar, and not overly long, and they might be unhappy if they still get the lint message.

In the context of implementing the new wildcard variables feature (spec), what changes, if any, do we want to make to the no_wildcard_variable_uses lint?

1. Migration/Breakage

One purpose of this existing lint is for an easier migration/breakage: which since it's enabled in the core lint set, should make the breakages across projects pretty small.

2. Wildcard variables feature

However, once the wildcard variables feature ships, we will most likely need to make a new lint and remove/deprecate(?)/change this one (because wildcards can be used :) ).

As @eernstg said, add a new lint that "targets the cases where _ resolves to a declaration which would be wildcarded when that feature is enabled."

cc. @pq

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packagelinter-new-language-featurelinter-set-coretype-questionA question about expected behavior or functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions