eslint/curly Style
What it does
This rule enforces the use of curly braces {}
for all control statements (if
, else
, for
, while
, do
, etc.). It ensures that all blocks are enclosed in curly braces to improve code clarity and maintainability.
Why is this bad?
Omitting curly braces can reduce code readability and increase the likelihood of errors, especially in deeply nested or indented code. It can also lead to bugs if additional statements are added later without properly enclosing them in braces. Using curly braces consistently makes the code safer and easier to modify.
Examples
Examples of incorrect code for this rule:
js
if (foo) foo++;
for (let i = 0; i < 10; i++) doSomething(i);
while (bar) bar--;
Examples of correct code for this rule:
js
if (foo) {
foo++;
}
for (let i = 0; i < 10; i++) {
doSomething(i);
}
while (bar) {
bar--;
}
How to use
To enable this rule in the CLI or using the config file, you can use:
bash
oxlint --deny curly
json
{
"rules": {
"curly": "error"
}
}