-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Allowed unused parameters before used ones #12139
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
Allowed unused parameters before used ones #12139
Conversation
A running tally of unused parameters is kept durin checking unused locals. It's reset to `[]` whenever a used parameter is found. If any are left after done checking a scope they're logged as errors.
Added a third parameter existing tests that previously had an unused and a used parameter in that order.
Hi @JoshuaKGoldberg, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
TTYL, MSBOT; |
} | ||
|
||
function checkUnusedParameterLocals(locals: Map<Symbol>): void { | ||
let unusedParameterLocals: Symbol[] | undefined = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a performance perspective I was hesitant to make a new [] no matter what. Hence the slight added complexity.
} | ||
} | ||
} | ||
|
||
if (unusedParameterLocals) { | ||
forEach(unusedParameterLocals, local => error(local.valueDeclaration.name, Diagnostics._0_is_declared_but_never_used, local.name)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should unusedParameterLocals
be sorted? Map
guarantees iteration in insertion order, but does TS guarantee locals be in inserted order? Do we want to rely on that guarantee?
In my experience, it's useful to know when you aren't using a parameter, regardless of where that parameter appears. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not believe this is needed. we do have support for _
as a special case for this purpose.
Moreover this change does not have a matching issue. Please file issues to discuss the design first.
This PR addresses concerns listed in #9458 by removing errors logged for any unused parameters, particularly from @KnisterPeter and myself. Errors are now skipped for unused parameters that come before used parameters.
Asking for
_
-prefixed variable names as the primary method of marking variables as unused can be non-optimal for several reasons: