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.

Request for New "curly" Option: "multi-or-nest-and-exit"

See original GitHub issue

The current options for the “curly” rule are great, but it would be really nice if it was possible to express an added constraint: in order for a one-line statement to be allowed, it has to exit somehow (ie. return or break or continue). In other words, this proposed “multi-or-nest-and-exit” option would be identical to “multi-or-nest”, except that:

if (foo) bar += 1;

would be invalid. Only:

if (foo) return bar + 1;

or:

if (foo) {
    bar += 1;
}

would be allowed. The reason for this distinction comes from the purpose of the rule itself. “curly” exists because it’s very easy to misunderstand code like:

if (foo) bar += 1;
baz += 1;

It’s easy to read that code and (especially if the indentation is wrong) think that baz += 1 will only trigger if (foo). However, by limiting such one-line conditionals to exit statements, you eliminate that confusion. It’s much harder for one to misunderstand:

if (foo) return bar + 1;
baz += 1;

because the reader knows that any code after a return won’t be run.

While I’m not sure how popular this rule is, it’s used at my company and I’ve seen it used at at least one other company, so I suspect that others might appreciate this rule option also.

Thanks for your consideration.

P.S. While I don’t have a pull request ready or anything (TBH I’ve never even looked at the ESLint source), if the ESLint maintainers want to add this option I would be more than happy to either create the pull request myself or use a “bounty” to help get this implemented by someone who is more familiar with ESLint’s source code.

<bountysource-plugin>

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
BYKcommented, Apr 7, 2016

I find this a bit too specific to be part of the core.

0reactions
ilyavolodincommented, Apr 8, 2016

I agree. This is more of a personal preference. It’s a good case for a plugin though. @machineghost if you run into problems creating this, stop by our gitter channel and we’ll try to help. Also, if you do end up creating this, please post a link here in case somebody wants to use the same style.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Apply Curly Hair Products in the Right Order - YouTube
Are you confused by what order you apply curly hair products? This video shares a step-by-step curly hair wash day routine and explains...
Read more >
Fix My Curls, an Indian Curly Girl brand!
Try out our 5 Step curly girl curl collection! Transform your frizzy, dry curls into moisturised and bouncy ones! Embrace the curls.
Read more >
How to Take Care of Curly Hair: 8 Common Mistakes to Avoid
Rinsing your hair with your head back can flatten your curls, causing them to lose volume and definition. Mistake #3: Waiting Too Long...
Read more >
Different Ways to Effectively Apply Product To Curls
All product-applying methods are not created equal. One question those with curly hair usually ask is, “How can I get my curls to...
Read more >
The 25 Best Curly Hair Products of 2022 - Allure
Want a soft, defining hold to your curls without a crunchy feel? Bread Beauty Supply's Allure Readers' Choice Award-winning Hair-Cream will do ...
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