newline-per-chained-call not working as expected
See original GitHub issueWhat 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:
- Created 4 years ago
- Reactions:1
- Comments:20 (19 by maintainers)
Top GitHub Comments
I was thinking about a non-breaking change like this:
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 fromv2
(only the last example would be valid).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.