src/content/docs/linter/rules/no-unused-variables.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/correctness/noUnusedVariables`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Same as [`no-unused-vars`](https://eslint.org/docs/latest/rules/no-unused-vars) - Same as [`@typescript-eslint/no-unused-vars`](https://typescript-eslint.io/rules/no-unused-vars) - Same as [`unused-imports/no-unused-vars`](https://github.com/sweepline/eslint-plugin-unused-imports/blob/master/docs/rules/no-unused-vars.md){
"linter": {
"rules": {
"correctness": {
"noUnusedVariables": "error"
}
}
}
}
Disallow unused variables.
There is an exception to this rule: variables that start with underscore, e.g. let _something;.
The pattern of having an underscore as a prefix of a variable is a very diffuse pattern among programmers, and Biome follows it.
This rule won't report unused imports. If you want to report unused imports, enable noUnusedImports.
let a = 4;
a++;
function foo() {}
function foo() {
foo();
}
const foo = () => {
foo();
};
export function f<T>() {}
const { brand } = car;
function foo(b) {
console.log(b)
};
foo();
export function foo(_unused) {}
function used_overloaded(): number;
function used_overloaded(s: string): string;
function used_overloaded(s?: string) {
return s;
}
used_overloaded();
By default, unused variables declared inside destructured objects are ignored if the destructuring pattern also contains a rest property. (See the rule options if you want to enable these checks).
const car = { brand: "Tesla", year: 2019, countryCode: "US" };
const { brand, ...rest } = car;
console.log(rest);
In Astro files, a top-level interface or a type alias named Props is always ignored
as it's implicitly read by the framework.
---
interface Props {
name: string;
greeting?: string;
}
const { name, greeting } = Astro.props;
---
ignoreRestSiblingsWhether to ignore unused variables declared inside destructured objects
containing rest properties (such as const { a, b, ...rest } = obj.
Default: true
{
"linter": {
"rules": {
"correctness": {
"noUnusedVariables": {
"options": {
"ignoreRestSiblings": false
}
}
}
}
}
}
const car = { brand: "Tesla", year: 2019, countryCode: "US" };
const { brand, ...other } = car;
console.log(other);
const car = { brand: "Tesla", year: 2019, countryCode: "US" };
const { brand: _, ...other } = car;
console.log(other);