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

Rule proposal: prefer-ternary #486

Closed
jmoore914 opened this issue Dec 24, 2019 · 2 comments · Fixed by #514
Closed

Rule proposal: prefer-ternary #486

jmoore914 opened this issue Dec 24, 2019 · 2 comments · Fixed by #514

Comments

@jmoore914
Copy link
Contributor

This rule would enforce using ternary expressions to simple if/then/else statements.

Fail

if(condition){
  a = 1;
}
else{
  a = 2;
}

Pass

a = condition ? 1 : 2
if(condition){
  doSomeStuff()
  a = 1;
}
else{
  a = 2;
}

This rule could have options for whether it would be enabled for various situations (e.g. variable assignments, return statements, function calls).

I've already written this rule as a normal ESLint plugin so it would just need some minor rewriting to conform to the unicorn linting/documentation

@sindresorhus
Copy link
Owner

Accepted

@jmoore914
Copy link
Contributor Author

Progress so far: https://github.com/jmoore914/eslint-plugin-unicorn/tree/prefer-ternary

Just need to find time to add documentation which might take a while because of all the different options available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants