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.

Rule proposal: Don't pass default values to functions

See original GitHub issue

Fail

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:closed
  • Created 3 years ago
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
fregantecommented, Apr 9, 2020

I never mentioned pay. It’s all about exposure.

2reactions
papbcommented, Apr 9, 2020

@fregante You forgot to fix it in the ESLint issue 😅

Read more comments on GitHub >

github_iconTop 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 >

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