Eslint rules concerning ternaries
Next, install
Note: If you installed ESLint globally (using the
Then configure the rules you want to use under the rules section.
Installation
You'll first need to install ESLint:$ npm i eslint --save-dev
Next, install
eslint-plugin-ternaries
:$ npm install eslint-plugin-ternaries --save-dev
Note: If you installed ESLint globally (using the
-g
flag) then you must also install eslint-plugin-ternaries
globally.Usage
Addternaries
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:{
"plugins": [
+ "ternaries"
]
}
Then configure the rules you want to use under the rules section.
{
"rules": {
+ "ternaries/no-null-ternary": 2,
+ "ternaries/no-empty-ternary": 2
}
}
Supported Rules
- no-null-ternary - Disallows ternaries with null as either the consequent or alternate condition.
- no-empty-ternary - Disallows ternaries that have '' or "" as either condition.