Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major bug-risk Should not have unused variables #4

Open
philipjonsen opened this issue Feb 18, 2024 · 0 comments
Open

Major bug-risk Should not have unused variables #4

philipjonsen opened this issue Feb 18, 2024 · 0 comments

Comments

@philipjonsen
Copy link

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant