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

Replace no-ternary check with no-nested-ternary #62

Closed
wants to merge 1 commit into from

Conversation

filipesperandio
Copy link
Contributor

Special in the view, it seems to make sense to have simple ternaries, while
we still don't want for complex ternaries to show up.

Copy link
Contributor

@maxjacobson maxjacobson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I like that you found that other rule, which I think more accurately reflects our tastes here.

I'm not 100% sure what our process is for amending these. Is one approval enough? cc @ale7714 @wfleming

@wfleming
Copy link
Contributor

wfleming commented Jan 30, 2019

Is one approval enough

Not usually, no. https://handbook.codeclimate.net/engineering/style_guide/#style-guide-prs

I'm against this change, personally. I still think ternarys are too easily/frequently abused and should be avoided since they tend to make for difficult to read code. Making that an enforced part of the style guide is easier overall than getting into nit-picky discussions about whether a particular ternary expression is acceptable. When cases come up where there is a good reason to break a style guide rule, that can always be done by simply ignoring the CC issue (or marking it with an appropriate status) and getting a human approval on the PR, but I do think the default should continue to be to avoid them.

@maxjacobson maxjacobson requested a review from a team January 30, 2019 16:08
@filipesperandio
Copy link
Contributor Author

IMO, If we ignore issues way too frequently it is a sign that the rule should be changed.

I think when it comes to view, ternaries makes sense, one example is that jsx will allow those expressions that would not be possible to inline through an if statement.
Also considering that this only changes js, not ruby.

@wfleming
Copy link
Contributor

FWIW @filipesperandio you can also mark specific lines in the source as ignored overall or for certain checks with comments: https://eslint.org/docs/user-guide/command-line-interface#inline-configuration-comments

e.g. put // eslint-disable-next-line the line before in JSX where you think the ternary is appropriate.

@eutopian
Copy link

I'm also favoring this in a way because of how React actually recommends ternaries for certain cases:

https://reactjs.org/docs/conditional-rendering.html#inline-if-else-with-conditional-operator

@filipesperandio
Copy link
Contributor Author

filipesperandio commented Jan 31, 2019

@eutopian That's what I was trying to refer to 👍

Also thinking more about this no-ternary rule and wondering if that might actually be a clue to extract the expression into a function and then use proper if/else there... maybe it is even better this way.

e.g. put // eslint-disable-next-line the line before in JSX where you think the ternary is appropriate.

@wfleming That I feel awful about, I think having the rule in, don't violate it.

@filipesperandio filipesperandio deleted the fe/nested-ternary branch March 13, 2019 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants