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.

comma-dangle inside promises is weird

See original GitHub issue

Sadly, .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:closed
  • Created 7 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mysticateacommented, Dec 19, 2016

@felixsanz

1reaction
felixsanzcommented, Dec 18, 2016

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Document comma-dangle: functions: always-multiline ... - GitHub
The behaviour of always-multiline comma dangle in promises isn't clearly documented. As In comma-dangle inside promises is weird #7786 ...
Read more >
comma-dangle - 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 >
Why are dangling commas still a thing? - Stack Overflow
To go even further, there would be good reason to add them in case they didn't already exist. They are useful. Indeed, trailing...
Read more >
Code review question about trailing comma's : r/node - Reddit
So I am doing code reviews for a client. Their programmer consequently uses a trailing comma in the const like this: const {someconst,...
Read more >
comma-dangle | typescript-eslint
Require or disallow trailing commas.
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