comma-dangle inside promises is weird
See original GitHub issueSadly, .then()
can accept multiple arguments (the second being the catch
function). But none should really use .then()
with more than one argument (right? 😝 )
In this example eslint complains about comma-dangle rule:
y.then(x => x
.replace('asdasdsdsda', '123213213')
.replace('cxvcxvcxvcx', '546546546')
.replace('ewrewrewrew', '877876876'), // <- this is confusing as hell. And useless comma!
)
I had problems trying to understand it at first because i wasn’t thinking that the comma belongs to the .then()
arguments. I thought the comma was part of the replace
chain and it was a bit hard to spot the problem 😞
A workaround could be:
y.then(x => (x
.replace('asdasdsdsda', '123213213')
.replace('cxvcxvcxvcx', '546546546')
.replace('ewrewrewrew', '877876876')
))
But this is ugly because the extra parens should be only added when eslint complains to the rule no-confusing-arrow. I mean, this is not a confusing arrow, so it shouldn’t need parens.
I think the comma-dangle rule should be removed from inside .then()
functions, or at least have an option to relax the rule there, because this seemed like a bug at first.
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (5 by maintainers)
@felixsanz
comma-dangle
rule withfunctions: 'always-multiline'
option. Thealways-multiline
option requires dangling commas if the closing parenthesis is not on the same line of the last argument. (This is not default.)comma-dangle
requires the dangling comma.@ljharb Here it is: https://github.com/airbnb/javascript#arrows--paren-wrap
I didn’t know that (it’s hard to remember all the style guide by memory). So it’s fine now i think. Probably my fault (but it’s so confusing if you don’t know this recommendation!)
I’m gonna close this, re-open if neccesary. Thx