-
-
Notifications
You must be signed in to change notification settings - Fork 506
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
feat(noUnusedFunctionParameters): add lint for unused function parameters, instead of using noUnusedVariables #2899
Conversation
6107073
to
91d7d43
Compare
CodSpeed Performance ReportMerging #2899 will not alter performanceComparing Summary
|
91d7d43
to
3ccb9f3
Compare
Rebased and fixed merge conflicts. Would someone be able to review this? |
What's the reasoning that drove you to implement the option? This reasoning will be very useful in explaining to the users why this option exists and how they can use it in their code. |
I'm using biome on a large legacy codebase, slowly migrating from ESLint. Having the option to enable I think that having unused arguments is much less of a code smell than entirely unused variables. In fact, especially when creating and passing around lambda functions, having unused arguments present can be really useful to readers so they immediately know that another argument is available if the code needs to be modified in the future. While prefixing arguments with an underscore is still an option, in my case this would require renaming thousands of parameters and introducing a non-trivial amount of line noise. One pattern that frequently comes up is: foo((a, b, c) => b); In code like this, having the option to provide useful argument names without having to prefix everything is very useful. Common examples: return new Promise((accept, reject) => { ... }); // not using `reject`
let arr = loadArr(); // `arr` has type `[string, string][]`
arr.filter(([k, v]) => v.length > 0); // `k` is unused
componentDidUpdate(prevProps: Props, prevState: State) { ... } // not using `prevState` While in many of the examples it might make sense to remove the extra argument or add an underscore, doing this thousands of times across a legacy codebase is unreasonable and shouldn't be necessary to still benefit from |
It's also worth pointing out that there are many repos on GitHub that set ESLint's |
3ccb9f3
to
1813165
Compare
I think we could go beyond and create a new rule |
I'll give making a new |
1813165
to
91598b5
Compare
91598b5
to
3cf1a4f
Compare
Alright, pretty sure I got it all working now. I've added a new nursery lint |
3cf1a4f
to
cefc988
Compare
AnyJsBindingDeclaration::TsPropertyParameter(_) => None, | ||
AnyJsBindingDeclaration::JsFormalParameter(parameter) => { | ||
if is_function_that_is_ok_parameter_not_be_used(¶meter.parent_function()) { | ||
None | ||
} else { | ||
suggestion_for_binding(binding) | ||
} | ||
} | ||
AnyJsBindingDeclaration::JsRestParameter(parameter) => { | ||
if is_function_that_is_ok_parameter_not_be_used(¶meter.parent_function()) { | ||
None | ||
} else { | ||
suggestion_for_binding(binding) | ||
} | ||
} |
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.
This changes the behaviour of the rule, and it's a breaking change. We should change this only when the new rule goes out of nursery.
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've reverted the changes to noUnusedVariables
now
/// This rule won't report unused imports. | ||
/// This rule won't report unused imports or unused function parameters. | ||
/// If you want to report unused imports, | ||
/// enable [noUnusedImports](https://biomejs.dev/linter/rules/no-unused-imports/). | ||
/// enable [noUnusedImports](https://biomejs.dev/linter/rules/no-unused-imports/); | ||
/// to report unused function parameters, enable | ||
/// [noUnusedFunctionParameters](https://biomejs.dev/linter/rules/no-unused-function-parameters/) |
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.
We can't change the documentation like this. This change will go straight to production and users will be misled. I think we should add a new paragraph like this:
From `v1.9.0`, the rule won't check unused function parameters anymore, users should switch to [noUnusedFunctionParameters](https://biomejs.dev/linter/rules/no-unused-function-parameters/)
I wrote 1.9.0
because in v1.8.0
the new rule is nursery, and we can't suggest a rule that is still in their incubation period.
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.
Updated docs as suggested
eee2e8d
to
1169038
Compare
bd770e2
to
c37f596
Compare
this is ready for another review @ematipico |
c37f596
to
bceefb3
Compare
…ters, instead of using `noUnusedVariables`
bceefb3
to
34b0b56
Compare
Summary
This adds a new lint
noUnusedFunctionParameters
that detects unused parameters. Previously these were detected bynoUnusedVariables
.Test Plan
I added tests for the new lint.