Rule proposal: Don't pass default values to functions
See original GitHub issuePlease describe what the rule should do:
Warn about using function parameters that are already set by the function’s defaults.
What category of rule is this? (place an “X” next to just one item)
[ ] Warns about a potential error (problem) [ ] Suggests an alternate way of doing something (suggestion) [ ] Enforces code style (layout) [x] Other (please specify:) Reduces code
Provide 2-3 code examples that this rule will warn about:
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
)
Why should this rule be included in ESLint (instead of a plugin)?
I think this is something you should tell me, I don’t know about your reasoning about what belongs to ESLint and what doesn’t. Could you include that in GitHub’s Issue template?
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (7 by maintainers)
You forgot to specify the HTTP status here, then: https://github.com/ljharb/tc39-ipr-check/blob/cc15bb5e28e8d7cbb8ee2f6f6d244c72920f90db/src/http/get-index/index.js#L32-L40
Why didn’t you set
statusCode: 200
if you prefer it? That’s a default.I agree with this comment from @ljharb, it looks like this rule wouldn’t provide much value since it would be limited to function calls in the same file where the function is defined.
Users could reasonably expect that it also works on imported/global functions and might see a lack of warnings as false negatives.