sindresorhus/eslint-plugin-unicorn
Rule proposal: `no-unused-reassignment`
Chiusa
#991 aperta il 2 gen 2021
help wantednew rule
Metriche repository
- Star
- (5022 stelle)
- Metriche merge PR
- (Merge medio 4h 30m) (26 PR mergiate in 30 g)
Descrizione
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);