Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cuddled "else" ? #88

Closed
NadyaNayme opened this issue Mar 26, 2015 · 7 comments

Comments

@NadyaNayme
Copy link

commented Mar 26, 2015

Standard currently doesn't hold an opinion on:

if (foo) {
  bar()
} else {
  qux()
}

vs

if (foo) {
  bar()
}
else {
  qux()
}

The Mozilla Style Guide suggests not to cuddle. Examples given by standard use cuddled else.

Personally I prefer a cuddled else as I find it far more readable. However, I'm raising this issue as the goal of standard is to be highly opinionated on stylistic matters.

Edit:
Same thing for Try/Catch

@jprichardson

This comment has been minimized.

Copy link
Member

commented Mar 26, 2015

While I prefer the 2nd over the 1st, I'm pretty sure that standard has complained in the past and so I have to correct to the 1st. So, I'm 99% sure standard prefers the 1st.

@NadyaNayme

This comment has been minimized.

Copy link
Author

commented Mar 26, 2015

@jprichardson
Well well well... I should have tested real quick before posting this! However, it isn't mentioned in the readme, so should be added. Or the "and more goodness" should be expanded elsewhere to mention smaller details like this.

You are correct that standard prefers the 1st over the 2nd.

@yoshuawuyts

This comment has been minimized.

Copy link
Contributor

commented Mar 26, 2015

Fun fact: standard uses standard to lint standard. If you're curious how some rule is used, there's a chance there's an example in source.

@NadyaNayme

This comment has been minimized.

Copy link
Author

commented Mar 27, 2015

@yoshuawuyts
Without testing it myself I would have no way to know if standard raised an error on cuddled else or not. I would just know, as I mentioned, that standard example files use a cuddled else.

I'm now confused though. The formatter I use implements rules to fix uncuddled else, but it doesn't seem to be within standard itself, which leads me to believe they differ and that I'm correct that standard does not care (as seen by the lack of 1tbs in the eslint rules) but my Sublime Text plugin does care. This should be corrected by adding a rule for 1tbs so that standard holds an opinion which way is correct (which, by the way, is cuddled else).

@jprichardson
Are you sure standard threw a fit? Or are you using an editor plugin?

@dcousens

This comment has been minimized.

Copy link
Member

commented Mar 27, 2015

@kyokou

The error given by standard for a non-cuddled else:

Closing curly brace does not appear on the same line as the subsequent block.

@maxogden maybe just add something to the README, otherwise, I think this is good to close.

@NadyaNayme

This comment has been minimized.

Copy link
Author

commented Mar 27, 2015

Thank you @dcousens for giving the error.

That rule is unmentioned, and I agree once something is added to the readme (or the " and other goodness" is expanded upon elsewhere) this is good to close.

@feross

This comment has been minimized.

Copy link
Member

commented Mar 29, 2015

Right now, only a few rules are actually mentioned in the readme. Most aren't listed explicitly because there are just too many. The .eslintrc file is already approaching 200 lines!

Let's try to enumerate all the rules over on the wiki: https://github.com/feross/standard/wiki for those who learn better that way. Please help out as you discover rules that aren't mentioned!

@feross feross closed this Mar 29, 2015

@lock lock bot locked as resolved and limited conversation to collaborators May 11, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
5 participants
You can’t perform that action at this time.