-
-
Notifications
You must be signed in to change notification settings - Fork 738
feat(linter): add unicorn/prefer-default-parameters rule #16620
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
Conversation
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.
Pull request overview
This PR implements the unicorn/prefer-default-parameters linter rule, which encourages using default parameter syntax instead of reassignment patterns like foo = foo || 'bar'. The rule detects cases where function parameters are reassigned using logical operators with literal values and suggests using default parameters instead.
Key Changes
- Adds comprehensive logic to detect parameter reassignment patterns (
foo = foo || 'bar'andconst bar = foo || 'bar') - Validates that the reassignment is the first statement in the function body and the parameter is the last one
- Includes extensive test coverage with 53 passing cases and 9 failing cases
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/oxc_linter/src/rules/unicorn/prefer_default_parameters.rs | Implements the complete rule logic with pattern detection, validation, and comprehensive tests |
| crates/oxc_linter/src/rules.rs | Registers the new rule in the linter's rule registry |
| crates/oxc_linter/src/snapshots/unicorn_prefer_default_parameters.snap | Adds snapshot test output for the rule's diagnostic messages |
Comments suppressed due to low confidence (1)
crates/oxc_linter/src/rules/unicorn/prefer_default_parameters.rs:1
- The rule is inserted between
prefer_bigint_literalsandprefer_response_static_json, breaking the alphabetical ordering of the rules. It should be placed afterprefer_date_now(line 474/1224) to maintain alphabetical order.
use oxc_ast::{
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
crates/oxc_linter/src/rules/unicorn/prefer_default_parameters.rs
Outdated
Show resolved
Hide resolved
CodSpeed Performance ReportMerging #16620 will not alter performanceComparing Summary
Footnotes
|
1ac2762 to
0321927
Compare
camc314
left a comment
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.
Thanks for working on this! Unfortunately, it looks like the rulegen infra failed to port across some test cases. I've done them manually and updated the PR, however some tests cases are failing
crates/oxc_linter/src/rules/unicorn/prefer_default_parameters.rs
Outdated
Show resolved
Hide resolved
crates/oxc_linter/src/rules/unicorn/prefer_default_parameters.rs
Outdated
Show resolved
Hide resolved
crates/oxc_linter/src/rules/unicorn/prefer_default_parameters.rs
Outdated
Show resolved
Hide resolved
914ef72 to
b1b1d68
Compare
I'm sorry! Thank you! |
crates/oxc_linter/src/rules/unicorn/prefer_default_parameters.rs
Outdated
Show resolved
Hide resolved
crates/oxc_linter/src/rules/unicorn/prefer_default_parameters.rs
Outdated
Show resolved
Hide resolved
crates/oxc_linter/src/rules/unicorn/prefer_default_parameters.rs
Outdated
Show resolved
Hide resolved
crates/oxc_linter/src/rules/unicorn/prefer_default_parameters.rs
Outdated
Show resolved
Hide resolved
3ce569c to
6ae0227
Compare
camc314
left a comment
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.
Thank you!
80f7f99 to
e6c87db
Compare
This PR adds unicorn/prefer-default-parameters rule, issue #684 [rule doc](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v62.0.0/docs/rules/prefer-default-parameters.md) [rule source](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v62.0.0/rules/prefer-default-parameters.js) --------- Co-authored-by: Cameron Clark <[email protected]>
This PR adds unicorn/prefer-default-parameters rule, issue #684
rule doc
rule source