Skip to main content

js/noUnusedVariables

disallow unused variables

ESLint Equivalent: no-unused-vars

Examples

Invalid

const a = 4;

 file.ts:1:6 lint/js/noUnusedVariables(a) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  The const variable a is unused.

    const a = 4;
          ^

  Unused variables are dead code and usually the result of incomplete
    refactoring.


let a = 4;

 file.ts:1:4 lint/js/noUnusedVariables(a) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  The let variable a is unused.

    let a = 4;
        ^

  Unused variables are dead code and usually the result of incomplete
    refactoring.


function foo(myVar) {
	console.log('foo');
};

 file.ts:1:13 lint/js/noUnusedVariables(myVar) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  The parameter variable myVar is unused.

  > 1function foo(myVar) {
                  ^^^^^
    2  console.log('foo');
    3};

  Unused variables are dead code and usually the result of incomplete
    refactoring.

 file.ts:1:9 lint/js/noUnusedVariables(foo) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  The function variable foo is unused.

  > 1function foo(myVar) {
              ^^^
    2  console.log('foo');
    3};

  Unused variables are dead code and usually the result of incomplete
    refactoring.


function foo(myVar) {
	console.log('foo');
}
foo();

 file.ts:1:13 lint/js/noUnusedVariables(myVar) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  The parameter variable myVar is unused.

  > 1function foo(myVar) {
                  ^^^^^
    2  console.log('foo');
    3}

  Unused variables are dead code and usually the result of incomplete
    refactoring.


const foo = (b) => {
	console.log('foo');
};

 file.ts:1:13 lint/js/noUnusedVariables(b) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  The parameter variable b is unused.

  > 1const foo = (b) => {
                  ^
    2  console.log('foo');
    3};

  Unused variables are dead code and usually the result of incomplete
    refactoring.

 file.ts:1:6 lint/js/noUnusedVariables(foo) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  The const variable foo is unused.

  > 1const foo = (b) => {
           ^^^
    2  console.log('foo');
    3};

  Unused variables are dead code and usually the result of incomplete
    refactoring.


function foo() {
	foo();
}

 file.ts:1:9 lint/js/noUnusedVariables(foo) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  The function variable foo is unused.

  > 1function foo() {
              ^^^
    2  foo();
    3}

  Unused variables are dead code and usually the result of incomplete
    refactoring.


const foo = () => {
	foo();
	console.log(this);
};

 file.ts:1:6 lint/js/noUnusedVariables(foo) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  The const variable foo is unused.

  > 1const foo = () => {
           ^^^
    2  foo();
    3  console.log(this);

  Unused variables are dead code and usually the result of incomplete
    refactoring.


function foo(): typeof foo {
		return function () {
				return foo;
		};
}

 file.ts:1:9 lint/js/noUnusedVariables(foo) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  The function variable foo is unused.

  > 1function foo(): typeof foo {
              ^^^
    2    return function () {
    3        return foo;

  Unused variables are dead code and usually the result of incomplete
    refactoring.


class Foo {
		init() {
			this._foo = new Foo();
		}
}

 file.ts:1:6 lint/js/noUnusedVariables(Foo) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  The class variable Foo is unused.

  > 1class Foo {
           ^^^
    2    init() {
    3      this._foo = new Foo();

  Unused variables are dead code and usually the result of incomplete
    refactoring.

Valid

function foo(_, b) {
	console.log(b)
};
foo();
const foo = (_, b) => {
	console.log(b)
};
foo();
foo();
function foo() {
	foo();
}
class Foo {
		init() {
			this._foo = new Foo();
		}
}
const foo = new Foo();
foo.init();