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
New: enforce default param be the last #11361
New: enforce default param be the last #11361
Comments
I like this idea. How it works if the last parameter is a rest element? function foo(p1 = "", ...rest){} |
The rest parameter must be last -- code like |
There are 3 upvotes now. Will this be accepted? |
Yes, it seems like this can be accepted. (In general, feel free to add the label yourself if there are 3 upvotes from team members and also a champion.) |
What will the rule name be? |
@g-plane perhaps |
* New: add rule default-param-last (fixes #11361) * Chore: fix typos * Chore: add test cases * Apply suggestion: add column for a test case * Update: change error message * Docs: add example in opening section * Add test cases about parameter destructuring
Please describe what the rule should do:
What category of rule is this? (place an "X" next to just one item)
[] Warns about a potential error (problem)
[x] Suggests an alternate way of doing something (suggestion)
[ ] Enforces code style (layout)
[ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
Why should this rule be included in ESLint (instead of a plugin)?
Default Parameter was introduced in ES6, and it was widely used in the community.
The ability to define default values for function parameters can make a function easier to use. Default parameter values allow callers to specify as many or as few arguments as they want while getting the same functionality and minimizing boilerplate, wrapper code.
But all function parameters with default values should be declared after the function parameters without default values. Otherwise, it makes it impossible for callers to take advantage of defaults; they must re-specify the defaulted values or pass undefined in order to "get to" the non-default parameters.
Are you willing to submit a pull request to implement this rule?
yes.
The text was updated successfully, but these errors were encountered: