src/content/docs/linter/rules/use-single-var-declarator.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/useSingleVarDeclarator`](/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 [**information**](/reference/diagnostics#information). - Sources: - Same as [`one-var`](https://eslint.org/docs/latest/rules/one-var){
"linter": {
"rules": {
"style": {
"useSingleVarDeclarator": "error"
}
}
}
}
Disallow multiple variable declarations in the same variable statement
In JavaScript, multiple variables can be declared within a single var, const or let declaration.
It is often considered a best practice to declare every variable separately.
That is what this rule enforces.
let foo = 0, bar, baz;
const foo = 0;
let bar;
let baz;
for (let i = 0, x = 1; i < arr.length; i++) {}