You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
unused-parameter: Support configuring parameter names to ignore #5741
enhancementIdeas for improvements of existing features and rules.good first issueIssue to be taken up by new contributors yet unfamiliar with the project.
The rule has a large number of violations where you either cannot change or remove the parameters. The most common case are delegate methods. It would be useful to be able to specify a list of parameter names to ignore. That would silence a lot of the most common cases.
Personally, I would add coder, sender, and context.
You can always replace the parameter with _ which is what the rule suggests as an alternative. A list of names feels like a too broad way of excluding cases.
The problem with replacing the parameter name with _ is that it will often be unclear what it was for, and if I ever need it again, I will have to look it up.
How about allowing prefixing the parameter with _ to ignore it? That's how it works with TypeScript. Then it's clear it's unused, while still being readable and easy to use again when needed.
I pretty much want to ignore the context for all of these. Maybe it could also allow specifying the type name, to be more specific, or maybe a selector.
The problem with replacing the parameter name with _ is that it will often be unclear what it was for, and if I ever need it again, I will have to look it up.
If the function satisfies a protocol requirement or overrides a method from a super class, the parameter can anyway not be omitted. Thus, its name is still there. It cannot be replaced with just _, but its internal name can be _. All other functions should not have unused parameters. That's the whole purpose of the rule. 😉
How about allowing prefixing the parameter with _ to ignore it? That's how it works with TypeScript. Then it's clear it's unused, while still being readable and easy to use again when needed.
You say func f(x _: Int) {} is ugly and func f(x _x: Int) {} is better? I don't really see this, but adding an option to consider variables starting with an underscore as admissibly unused should be doable.
Here's an example of where I would almost never use context but I cannot change it (other than adding a internal _ label, but that's ugly):
I pretty much want to ignore the context for all of these. Maybe it could also allow specifying the type name, to be more specific, or maybe a selector.
I get that. However, the rule can be run with --fix so that the many places will be automatically silenced. Wouldn't it be confusing if the rule wasn't to trigger on a special set of parameters names? Including the type is also too vague considering Self, typealias, generics, ...
What about excluding whole functions by name from the analysis given that this is typically annoying for a defined set of framework methods?
You say func f(x _: Int) {} is ugly and func f(x _x: Int) {} is better? I don't really see this, but adding an option to consider variables starting with an underscore as admissibly unused should be doable.
You generally have func f(x: Int) or func f(for x: Int) type signatures. For the former, I agree that func f(x _: Int) is the best choice, but for func f(for x: Int), it becomes unclear what it means if you convert the x to _, and func f(for _x: Int) would be better then.
You say func f(x _: Int) {} is ugly and func f(x _x: Int) {} is better? I don't really see this, but adding an option to consider variables starting with an underscore as admissibly unused should be doable.
You generally have func f(x: Int) or func f(for x: Int) type signatures. For the former, I agree that func f(x _: Int) is the best choice, but for func f(for x: Int), it becomes unclear what it means if you convert the x to _, and func f(for _x: Int) would be better then.
Fair enough. An option to support this style should be fine then.
What about excluding whole functions by name from the analysis given that this is typically annoying for a defined set of framework methods?
Just the function name can have the same problem with being too broad as you argued with just using the parameter name.
Indeed. Glad you mention it. 😅 Up to now, I don't really see an elegant solution.
I added an opt-in allow_underscore_prefixed_names option (default false) so underscore-prefixed parameter names can be treated as intentionally unused when teams prefer that style.
enhancementIdeas for improvements of existing features and rules.good first issueIssue to be taken up by new contributors yet unfamiliar with the project.
Activity
SimplyDanny commentedon Aug 9, 2024
You can always replace the parameter with
_which is what the rule suggests as an alternative. A list of names feels like a too broad way of excluding cases.sindresorhus commentedon Aug 9, 2024
The problem with replacing the parameter name with
_is that it will often be unclear what it was for, and if I ever need it again, I will have to look it up.How about allowing prefixing the parameter with
_to ignore it? That's how it works with TypeScript. Then it's clear it's unused, while still being readable and easy to use again when needed.sindresorhus commentedon Aug 9, 2024
Here's an example of where I would almost never use
contextbut I cannot change it (other than adding a internal_label, but that's ugly):I pretty much want to ignore the
contextfor all of these. Maybe it could also allow specifying the type name, to be more specific, or maybe a selector.SimplyDanny commentedon Aug 9, 2024
If the function satisfies a protocol requirement or overrides a method from a super class, the parameter can anyway not be omitted. Thus, its name is still there. It cannot be replaced with just
_, but its internal name can be_. All other functions should not have unused parameters. That's the whole purpose of the rule. 😉You say
func f(x _: Int) {}is ugly andfunc f(x _x: Int) {}is better? I don't really see this, but adding an option to consider variables starting with an underscore as admissibly unused should be doable.I get that. However, the rule can be run with
--fixso that the many places will be automatically silenced. Wouldn't it be confusing if the rule wasn't to trigger on a special set of parameters names? Including the type is also too vague consideringSelf,typealias, generics, ...What about excluding whole functions by name from the analysis given that this is typically annoying for a defined set of framework methods?
sindresorhus commentedon Aug 9, 2024
You generally have
func f(x: Int)orfunc f(for x: Int)type signatures. For the former, I agree thatfunc f(x _: Int)is the best choice, but forfunc f(for x: Int), it becomes unclear what it means if you convert thexto_, andfunc f(for _x: Int)would be better then.sindresorhus commentedon Aug 9, 2024
Just the function name can have the same problem with being too broad as you argued with just using the parameter name.
SimplyDanny commentedon Aug 10, 2024
Fair enough. An option to support this style should be fine then.
Indeed. Glad you mention it. 😅 Up to now, I don't really see an elegant solution.
theamodhshetty commentedon Feb 24, 2026
Implemented this in #6509.
I added an opt-in
allow_underscore_prefixed_namesoption (defaultfalse) so underscore-prefixed parameter names can be treated as intentionally unused when teams prefer that style.