Skip to content

Major bug-risk Should not have unused variables #4

@philipjonsen

Description

@philipjonsen

D is defined but never used here https://github.com/philipjonsen/tenderly-fork/blob/master/create.js#L70-L70

Having unused variables are dangerous to injections and such.

Unused variables are most often the result of incomplete refactoring. They can lead to confusing code and minor performance hitches.

Easy Fix:

Bad Practice

// Write-only variables are not considered as used.
let y = 10;
y = 5;

// A variable that modifies only itself isn't considered used.
let z = 0;
z = z + 1;

// Unused argument
(function(x) {
return 5;
})();

// Unused recursive functions also raise this issue.
function fact(n) {
if (n < 2) return 1;
return n * fact(n - 1);
}

// When a function definition destructures an array,
// unused entries from the array also cause warnings.
function getY([x, y]) {
return y;
}

Recommended

let x = 10;
alert(x);

((arg1) => {
return arg1;
})();

let myFunc;
myFunc = (n) => {
// this is legal
if (n < 0) myFunc();
};

// this is also considered legal
console.log(declaredLater);
var declaredLater;

// Only the second argument from the descructured array is used.
function getY([, y]) {
return y;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions