Skip to content

New: enforce default param be the last #11361

@aladdin-add

Description

@aladdin-add

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:

function foo(p1 = "", p2){}

function foo(p1, p2 = "", p3){}

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.

Metadata

Metadata

Assignees

Labels

acceptedThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionfeatureThis change adds a new feature to ESLintruleRelates to ESLint's core rules

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions