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

5.2 breaks ternary operator style #246

Closed
julien-f opened this issue Sep 4, 2015 · 3 comments

Comments

@julien-f
Copy link

commented Sep 4, 2015

All my code suddenly failed to pass standard due to a change in standard 5.2 concerning the ternary operator:

const a = true ?
  1 :
  2
standard: Use JavaScript Standard Style (https://github.com/feross/standard)
  index.js:1:17: '?' should be placed at the beginning of the line.
  index.js:2:6: ':' should be placed at the beginning of the line.
@feross

This comment has been minimized.

Copy link
Member

commented Sep 8, 2015

The ternary (? :) and the 'blocks must not be padded' rules have been part of standard even though they haven't been enforced consistently due to eslint bugs and ditching jscs at one point. We temporarily lost enforcement of this rule. But now that we can enforce them again, this is basically bugfix, so it didn't get released in a major version.

Sorry that this broke your tests -- hopefully this won't happen again. I don't think we have any more of these types of changes to release. See #248 for more discussion.

@feross feross closed this Sep 8, 2015

@feross feross added the question label Sep 8, 2015

@julien-f

This comment has been minimized.

Copy link
Author

commented Sep 8, 2015

Understood, thanks.

@timdp

This comment has been minimized.

Copy link

commented Sep 8, 2015

Just wondering what the reasoning behind this is. For example:

var foo = (bar === 'test')
  ? baz()
  : quux()

If you don't look at lines 2 and 3, you don't know that foo will be assigned either baz() or quux(). Instead, it looks like the statement ends there and foo is a boolean.

My personal preference would be:

var foo = (bar === 'test') ?
  baz() :
  quux()

which bears a lot of similarity to e.g.

var foo = bar + 'test' +
  baz() +
  quux()

(You could obviously put everything on one line, but imagine longer statements ...)

@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.
3 participants
You can’t perform that action at this time.