quick-lint / quick-lint-js

quick-lint-js finds bugs in JavaScript programs
https://quick-lint-js.com
GNU General Public License v3.0
1.52k stars 191 forks source link

10$: Warn on let ({x} = y); #1203

Closed strager closed 5 months ago

strager commented 6 months ago

Before refactor:

let x;
({x} = y);

After refactor:

let ({x} = y);  // Bug! This uses an undeclared variable 'x' and calls a function named 'let'.

Conditions for this diagnostic:

msharipov commented 6 months ago

@strager Shouldn't this be considered an error? Code like this crashes in Node.js on line 5:

const y = {x: 45, z: "helloworld"};
let z;
({z} = y);
console.log(z);
let ({x} = y);
console.log(x);
strager commented 5 months ago

@msharipov This doesn't crash:

const y = {x: 45, z: "helloworld"};
let z;
({z} = y);
console.log(z);

function let(arg) {
  console.log("let", arg);
}
let x;
let ({x} = y);
console.log(x);
msharipov commented 5 months ago

@strager Ah, I see. Could you please assign this to me?

Nyx1on commented 5 months ago

I claim this for-hire task. I expect payment after I complete this task. I will email the quick-lint-js team if I am assigned this task.

strager commented 5 months ago

@Nyx1on Someone else already claimed this task. If @msharipov is unresponsive, I'll give the task you @Nyx1on.

msharipov commented 5 months ago

I'm still working on this, it's just taking a while.