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
Rule proposal: no-useless-undefined
#683
Comments
Yes |
This is accepted. |
I think this rule is a great idea, but how are we supposed to mark a formal parameter as optional if the following form is disallowed ? function foo(bar = undefined) {
if (typeof bar !== "undefined") {
// Do something with 'bar'
}
}
This information can of course be expressed in annotations, but I would prefer to be able to also keep it in the code. |
We are not removing parameter function foo(bar = undefined) {
if (typeof bar !== "undefined") {
// Do something with 'bar'
}
} To function foo(bar) {
if (typeof bar !== "undefined") {
// Do something with 'bar'
}
} Is this breaking something? |
It does not break anything per se, but it still removes the visual indication that the |
How about function foo(bar /* optional */) {} |
Yes this is an interesting solution, I might give it a try if nothing else changes - thank you for your time. Although I am not sure about how to consistently enforce the presence and the exact formatting of this inline comment, as I currently do not know of any linter rule that does this. |
Not sure which one better, but all seems clear function foo(bar, baz /* optional */) {} function foo(bar, /* optional */ baz) {} |
I see several valid usecases for using "useless" `undefined`: - declaring parameters as optional (this also affects code behavior and IDE hints) - declaring properties as optional when using parameter destructuring (affects IDE hints) - passing `undefined` to functions (affects code behavior when it depends on `arguments.length`) - passing `undefined` to functions in tests for explicitness See discussions: - sindresorhus/eslint-plugin-unicorn#731 - sindresorhus/eslint-plugin-unicorn#683
reopen by accident. |
Fail
Pass
Discussion #636 (comment)
Not sure about this,
The text was updated successfully, but these errors were encountered: