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.

newline-per-chained-call not working as expected

See original GitHub issue

What rule do you want to change? newline-per-chained-call

Does this change cause the rule to produce more or fewer warnings? More.

How will the change be implemented? (New option, new default behavior, etc.)? A new option.

Please provide some example code that this change will affect:

NOTE: D3 example copied straight from the docs.

// ignoreChainWithDepth: 1
let d3

// Currently allowed.
d3.select("body")
.selectAll("p")
.data([4, 8, 15, 16, 23, 42 ])

// What I'd expect to see.
d3
.select("body")
.selectAll("p")
.data([4, 8, 15, 16, 23, 42 ])

let someReallyLongArrayName = []

// Currently allowed.
someReallyLongArrayName.map(({
  foo,
  bar,
}) => ({
  foo,
  bar,
}))
.filter(Boolean)

// What I'd expect to see.
someReallyLongArrayName 
.map(({
  foo,
  bar,
}) => ({
  foo,
  bar,
}))
.filter(Boolean)

What does the rule currently do for this code? With the ignoreChainWithDepth value, there’s no way to say “if the chain depth is no longer ignored, all values need newlines”.

At the point that this rule is triggered, instead of allowing only the first chained prop to stay at the top, all props would be on a new line.

What will the rule do after it’s changed? It will look to see if the chain depth has been passed and if so, enforce also dropping the first value for consistency. It’s strange to have one chain not being dropped, but the rest having to be dropped.

Are you willing to submit a pull request to implement this change? Yes.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:20 (19 by maintainers)

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Mar 4, 2020

I was thinking about a non-breaking change like this:

/*eslint newline-per-chained-call: ["error", 
  { 
    "ignoreChainWithDepth": 4
    "allowLeading": 2
  }
]*/

// valid
obj.a().b().c().d();

// invalid
obj.a().b().c().d().e();

// invalid. this would be valid without allowLeading
obj.a().b().c().d()
  .e();

// invalid. this would be valid without allowLeading
obj.a().b().c()
  .d()
  .e();

// valid. the two invalid examples above would be autofixed to this
obj.a().b()
  .c()
  .d()
  .e();

// also valid
obj.a()
  .b()
  .c()
  .d()
  .e();

// also valid
obj
  .a()
  .b()
  .c()
  .d()
  .e();

allowLeading is a new option. There could be a better name, though.

If it isn’t set, the behavior is the same as the actual behavior.

"allowLeading": 0 restores behavior from v2 (only the last example would be valid).

0reactions
eslint-deprecated[bot]commented, Apr 8, 2020

Unfortunately, it looks like there wasn’t enough interest from the team or community to implement this change. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach accepted status after 21 days tend to never be accepted, and as such, we close those issues. This doesn’t mean the idea isn’t interesting or useful, just that it’s not something the team can commit to.

Thanks for contributing to ESLint and we appreciate your understanding.

Read more comments on GitHub >

github_iconTop Results From Across the Web

newline-per-chained-call - 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 >
How to correctly use Eslint rule newline-per-chained-call with ...
I get error Delete ⏎↹↹↹ eslint (prettier/prettier). in VSCode which I don't want to have. How can I fix the configuration to allow...
Read more >
newline-per-chained-call - Rule
Rule: newline-per-chained-call​​ Requires that chained method calls be broken apart onto separate lines.
Read more >
Chained method call wrapping not working as expected
Chained method call wrapping not working as expected · Go to Code Style -> Java -> Wrapping and Braces · Set Chained method...
Read more >
Airbnb JavaScript Style Guide()
3.7 Do not call Object.prototype methods directly, such as hasOwnProperty ... line is a method call, not a new statement. eslint: newline-per-chained-call ......
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