Rule proposal: Don't pass default values to functions
See original GitHub issueFail
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
)
Pass
run(); // No parameter set
Exclude
If run
depends on arity/arguments.length
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (2 by maintainers)
Top Results From Across the Web
Rule proposal: Don't pass default values to functions #2304
TypeScript deals with and tracks types of things, not values. To TypeScript, your function run has parameter {always} , which has type {always: ......
Read more >[proposal] Allow function argument type to be omitted when passing ...
I propose that function argument types could be omitted in the same way as variable and property argument types are omitted when they...
Read more >php - Using Default Arguments in a Function - Stack Overflow
I am confused about default values for PHP functions. Say I have a function like this: function foo($blah, $x = "some value", $y...
Read more >Default parameters - JavaScript - MDN Web Docs
Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
Read more >Using Python Optional Arguments When Defining Functions
In this tutorial, you'll learn about Python optional arguments and how to define functions with default values. You'll also learn how to create...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I never mentioned pay. It’s all about exposure.
@fregante You forgot to fix it in the ESLint issue 😅