noUnusedVariables (since v0.9.0)
This rule is recommended by Rome.
Disallow unused variables.
Examples
Invalid
const a = 4; error[js/noUnusedVariables]: This variable is unused.
┌─ js/noUnusedVariables.js:1:7
│
1 │ const a = 4;
│ ^
= note: Unused variables usually are result of incomplete refactoring, typos and other source of bugs.
let a = 4; error[js/noUnusedVariables]: This variable is unused.
┌─ js/noUnusedVariables.js:1:5
│
1 │ let a = 4;
│ ^
= note: Unused variables usually are result of incomplete refactoring, typos and other source of bugs.
function foo() {
}; error[js/noUnusedVariables]: This function is unused.
┌─ js/noUnusedVariables.js:1:10
│
1 │ function foo() {
│ ^^^
= note: Unused variables usually are result of incomplete refactoring, typos and other source of bugs.
function foo(myVar) {
console.log('foo');
}
foo(); error[js/noUnusedVariables]: This parameter is unused.
┌─ js/noUnusedVariables.js:1:14
│
1 │ function foo(myVar) {
│ ^^^^^
= note: Unused variables usually are result of incomplete refactoring, typos and other source of bugs.
const foo = () => {
}; error[js/noUnusedVariables]: This variable is unused.
┌─ js/noUnusedVariables.js:1:7
│
1 │ const foo = () => {
│ ^^^
= note: Unused variables usually are result of incomplete refactoring, typos and other source of bugs.
function foo() {
foo();
} error[js/noUnusedVariables]: This function is unused.
┌─ js/noUnusedVariables.js:1:10
│
1 │ function foo() {
│ ^^^
= note: Unused variables usually are result of incomplete refactoring, typos and other source of bugs.
const foo = () => {
foo();
console.log(this);
}; error[js/noUnusedVariables]: This variable is unused.
┌─ js/noUnusedVariables.js:1:7
│
1 │ const foo = () => {
│ ^^^
= note: Unused variables usually are result of incomplete refactoring, typos and other source of bugs.
Valid
function foo(b) {
console.log(b)
};
foo(); function foo(_unused) {
};
foo(); import React from 'react';
function foo() {
return <div />;
};
foo(); function used_overloaded(): number;
function used_overloaded(s: string): string;
function used_overloaded(s?: string) {
return s;
}
used_overloaded();