eslint-plugin-unicorn: Rule proposal: Don't pass default values to functions
Fail
function run(always = true) {}
run(true); // Error
function run({always} = {always: true}) {}
run({always: true}); // Error
function run({always = true} = {}) {}
run({always: true}); // Error
function run(options) {
options = {
always: true,
...options
}
}
run({always: true}); // Error
function run(options) {
options = Object.assign({
always: true
}, options);
}
run({always: true}); // Error
And any other common defaults pattern (unless already blocked by other rules like prefer-object-spread
)
Pass
run(); // No parameter set
Exclude
If run
depends on arity/arguments.length
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 19 (5 by maintainers)
I never mentioned pay. It’s all about exposure.
@fregante You forgot to fix it in the ESLint issue 😅
While I like the idea of this rule, I feel it’s not that useful when constrained to a single file. @fregante Maybe you could propose it over at https://github.com/typescript-eslint/typescript-eslint ?
Actually your last example is wrong too haha, should be:
By the way, I also asked about this rule on eslint ⬇️
Your fourth example is not a “defaults pattern”… It is probably a mistake, since it overwrites the
always
option entirely… What you probably meant is: