sindresorhus/eslint-plugin-unicorn

Rule proposal: `no-unused-reassignment`

Fechada

#991 aberto em 2 de jan. de 2021

 (3 comentários) (3 reações) (0 responsável)JavaScript (468 forks)user submission
help wantednew rule

Métricas do repositório

Stars
 (5.022 estrelas)
Métricas de merge de PR
 (Mesclagem média 4h 30m) (26 fundiu PRs em 30d)

Description

Prevent accidentally reassigning a variable and not using the result. It would only handle variables and reassignments in the same scope.

This is similar to no-unused-vars, but that rule doesn't handle this case.

It cannot auto-fix as getUnicorn() could be impure. We should at least provide a suggestion.

Fail

function foo() {
	let unicorn = getUnicorn();

	if (unicorn) {
		handleUnicorn(unicorn);
	}

	// …

	unicorn = getUnicorn();
}
let foo = 1;

// …

foo = 2;

// …

foo = 3;

console.log(foo);

Pass

function foo() {
	let unicorn = getUnicorn();

	if (unicorn) {
		handleUnicorn(unicorn);
	}
}
let foo = 1;

console.log(foo);

Guia do colaborador