Skip to content

Commit 709807a

Browse files
Update README.md
1 parent c13e095 commit 709807a

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

README.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,47 @@
1-
# eslint-plugin-conditional-best-practices
1+
# @andreasnicolaou/eslint-plugin-conditional-best-practices
2+
This ESLint plugin includes several opinionated rules aimed at enhancing the readability, performance, and maintainability of conditionals in JavaScript.
3+
4+
These rules focus on writing clear and efficient conditional statements, so while they encourage consistency and simplicity, they may not suit every coding style. Feel free to adjust the rules based on your team's preferences.
5+
6+
# Installation
7+
8+
Install the npm package
9+
```bash
10+
# If eslint is installed globally
11+
npm install -g @andreasnicolaou/eslint-plugin-conditional-best-practices
12+
13+
# If eslint is installed locally
14+
npm install -D @andreasnicolaou/eslint-plugin-conditional-best-practices
15+
```
16+
17+
To use this plugin in your project, add it to your ESLint configuration like this:
18+
19+
```js
20+
{
21+
"plugins": ["@andreasnicolaou/conditional-best-practices"],
22+
"extends": [
23+
"plugin:@andreasnicolaou/conditional-best-practices/recommended"
24+
]
25+
}
26+
27+
```
28+
- Alternatively, you can extend individual rules if you prefer more granular control.
29+
30+
# Usage
31+
This plugin enforces the following opinionated best practices:
32+
33+
| Name                                        | Description |
34+
| :------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------- |
35+
| [no-constant-conditionals](docs/no-constant-conditionals.md) | This rule disallows conditionals that always evaluate to true or false. |
36+
| [no-duplicated-conditions](docs/no-duplicated-conditions.md) | This rule disallows duplicate conditions in if-else chains. |
37+
| [no-excessive-nested-conditionals](docs/no-excessive-nested-conditionals.md) | This rule disallows excessive nesting of conditionals in order to improve code readability. |
38+
| [no-long-else-if-chains](docs/no-long-else-if-chains.md) | This rule limits the number of consecutive else-if statements. |
39+
| [no-nested-ternary-operators](docs/no-nested-ternary-operators.md) | This rule disallows nested ternary operators. |
40+
| [no-useless-ternary](docs/no-useless-ternary.md) | This rule disallows unnecessary ternary expressions. |
41+
| [prefer-early-return](docs/prefer-early-return.md) | This rule encourages the use of early returns instead of deeply nested if-else blocks. |
42+
| [require-default-in-switch](docs/require-default-in-switch.md) | This rule ensures that switch statements include a default case and/or its not empty. |
43+
44+
45+
# Autofixing
46+
47+
Currently, this plugin does not support automatic fixes for code violations. It only detects incorrect usage and warns you, helping to maintain consistency and best practices in your codebase.

0 commit comments

Comments
 (0)