Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wildcard Variables][lint] consider a no_unused_parameters lint #4972

Open
Tracked by #4969
pq opened this issue May 16, 2024 · 1 comment
Open
Tracked by #4969

[Wildcard Variables][lint] consider a no_unused_parameters lint #4972

pq opened this issue May 16, 2024 · 1 comment
Labels
lint-proposal new-language-feature P2 A bug or feature request we're likely to work on status-pending type-enhancement A request for a change that isn't a bug

Comments

@pq
Copy link
Member

pq commented May 16, 2024

With wildcard variables, we have a proper way to mark unused parameters as intentionally unused. Given that, we might consider a lint that flags unused parameters with the expectation that intentionally unused params should either be removed or converted to wildcards.

For example:

BAD

int f(int x) => 42;

abstract class A {
  int f(int x);
}

class A extends C {
  @override
  int f(int x) => 42;
}

GOOD

int f(int x) => x;
int f() => 42;
int f(int _) => 42;


abstract class A {
  int f(int x);
}

class A extends C {
  @override
  int f(int x) => x;
}

class A extends C {
  @override
  int f(int _) => 42;
}

/fyi @kallentu @lrhn @munificent

@pq pq added lint-proposal status-pending P2 A bug or feature request we're likely to work on new-language-feature labels May 16, 2024
@lrhn
Copy link
Member

lrhn commented May 16, 2024

As described here, the lint would conflict with avoid_renaming_method_parameters for instance methods. That lint is there for several reasons, one being to ensure that inherited documentation stays correct.

Generally, there can be good reasons for having a name for a parameter that is not used, if the function is publicly visible. The parameter is there for a reason, its name may describe that reason.
Even for private function declarations, it may be more useful to know the names of parameters that aren't used by this particular function implementation. If the parameter is there, it's probably because it means something, so if we can't remove the entire parameter, there can be reasons for the name.

Not always, it's also fine to decide that you don't care, or that you know that nobody will see this seemingly public function.

For function literals, used as a callback, it makes much more sense, because that's not also exposed as something you can call.

@kallentu kallentu changed the title [wildcards] consider a no_unusued_parameters lint [Wildcard Variables][lint] consider a no_unused_parameters lint May 16, 2024
@srawlins srawlins added the type-enhancement A request for a change that isn't a bug label May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lint-proposal new-language-feature P2 A bug or feature request we're likely to work on status-pending type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants