Skip to content

Possible improvements on avoid_types_as_parameter_names #58453

@eernstg

Description

@eernstg

The lint avoid_types_as_parameter_names does not seem to consider a type variable as a type:

void g<X>(int X) {} // No lint.

class C<X> {
  C.name();
  factory C(X) => C.name(); // No lint.
  void m(void Function(C X) h) {} // No lint.
}

It seems equally relevant to flag type parameter names and other type names: In both cases, the shadowing makes nested code harder to read, so I would expect a lint message at all the comments above. The third one doesn't really hurt anybody, because that X is not in scope for any term, but it is likely that the use of a type variable in that kind of position would arise because the author wanted to write something else.

Another issue with this lint is the documentation: https://dart-lang.github.io/linter/lints/avoid_types_as_parameter_names.html.

On that page the BAD example m(f(int)); is given, but that could very well be an invocation of a function m with an actual argument f(int), and that doesn't involve any formal parameters whose name is a type name at all. Maybe the example could be something like void m(int) {} which is unambiguously a function declaration, and then the GOOD example could be void m(int i) {}?

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.linter-false-negativeIssues related to lint rules that fail to report a problem.linter-set-coretype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)type-documentationA request to add or improve documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions