question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New: enforce default param be the last

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
aladdin-addcommented, Feb 9, 2019

The rest parameter must be last – code like function foo(...rest, p1 = ""){} will throw an error. I think we just need to ignore rest parameters.

0reactions
horntacommented, Apr 26, 2019

@g-plane perhaps default-params-end

Read more comments on GitHub >

github_iconTop Results From Across the Web

default-param-last - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
enforce default parameters to be last (default-param-last)
Putting default parameter at last allows function calls to omit optional tail arguments.
Read more >
default-param-last | typescript-eslint
Enforce default parameters to be last. ... This rule extends the base eslint/default-param-last rule. It adds support for optional parameters.
Read more >
reactjs - React Redux error: default parameters should be last ...
The default-param-last eslint rule just means that in this case you need to specify a default on both params or disable the rule...
Read more >
Default parameters - JavaScript - MDN Web Docs
In JavaScript, function parameters default to undefined . However, it's often useful to set a different default value. This is where default ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found