src/content/docs/linter/rules/use-block-statements.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/style/useBlockStatements`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Same as [`curly`](https://eslint.org/docs/latest/rules/curly){
"linter": {
"rules": {
"style": {
"useBlockStatements": "error"
}
}
}
}
Requires following curly brace conventions.
JavaScript allows the omission of curly braces when a block contains only one statement. However, it is considered by many to be best practice to never omit curly braces around blocks, even when they are optional, because it can lead to bugs and reduces code clarity.
if (x) x;
if (x) {
x;
} else y;
if (x) {
x;
} else if (y) y;
for (;;);
for (p in obj);
for (x of xs);
do;
while (x);
while (x);