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

Allow flatTernaryExpressions option of indent rule #1421

Closed
Alexsey opened this issue Sep 24, 2019 · 4 comments
Closed

Allow flatTernaryExpressions option of indent rule #1421

Alexsey opened this issue Sep 24, 2019 · 4 comments

Comments

@Alexsey
Copy link

Alexsey commented Sep 24, 2019

What version of this package are you using? eslint-config-standard v14.1.0

What problem do you want to solve? Because switch/case in JavaScript is broken and while pattern matching in only a proposal code pattern under flatTernaryExpressions is one of a few ways to express long but trivial if/else chains in a clear way:

const prefix = env === 'prod' ? ''
   :  env === 'local' ? 'local-'
   : 'dev-'

What do you think is the correct solution to this problem?
Set flatTernaryExpressions option of indent rule to true

Are you willing to submit a pull request to implement this change?
Yes

@mightyiam
Copy link
Contributor

Rather than relaxing the rule, I would prefer defining it better. But there doesn't seem to be an ESLint rule for indentation of ternary expressions other than the little indent has to offer.

@Alexsey just a suggestion here. Perhaps you'd like to contribute a whitespace (or at least indentation) rule to getify/eslint-plugin-proper-ternary#4 ? The maintainer labelled it as 'help wanted'.

I have just suggested that we use that plugin in Standard: #1422.

@Alexsey
Copy link
Author

Alexsey commented Sep 25, 2019

@mightyiam sorry, I have no experience with AST, so this task is probably not for me. But why do you think that relaxing the rule is not what we need here?
IMHO perfect would be to allow

const prefix =
      env === 'prod' ? ''
   :  env === 'local' ? 'local-'
   : 'dev-'

but this is not something that https://github.com/getify/eslint-plugin-proper-ternary can handle either. So relaxing the rule is the best we can have

@mightyiam
Copy link
Contributor

I'm not sure, @Alexsey.

Please see #1424.

If it is observed that the style that you requested to be able to use is the chosen style for that logic, then, relaxing might be the correct thing to do, until we have the rules available to enforce our chosen styles.

Yet, for the sake of making one developer happy, I would not mind this rule being relaxed in the way you asked, as well, @Alexsey. As long as we follow up with style decisions.

@feross
Copy link
Member

feross commented Oct 29, 2020

Ternaries are really dense, so the style we prefer in standard discourages it by requiring indentation:

const a = b
  ? c
  : d
    ? e
    : f

Or, you can use explicit if-elses:

let a = f
if (b) {
  a = c
} else if (d) {
  a = e
}

I'm not interested in reconsidering this decision at the moment, so I'm closing this issue. But feel free to continue discussion in this issue.

@feross feross closed this as completed Oct 29, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

3 participants