ecomfe / eslint-config

eslint shareable config for efe
MIT License
118 stars 31 forks source link

New Rule: 默认开启 no-unneeded-ternary #73

Open SyMind opened 2 years ago

SyMind commented 2 years ago

https://eslint.org/docs/rules/no-unneeded-ternary

no-unneeded-ternary 检查非必要的三元表达式。

// Bad
var isYes = answer === 1 ? true : false;

// Good
var isYes = answer === 1;

// Bad
var isNo = answer === 1 ? false : true;

// Good
var isNo = answer !== 1;

// Bad
foo(bar ? bar : 1);

// Good
foo(bar || 1);
SyMind commented 2 years ago

@otakustay