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

Error E0718 is not an actual error #1199

Closed Danny-06 closed 5 months ago

Danny-06 commented 6 months ago

The error as documented in the official docs https://quick-lint-js.com/errors/E0718/ implies that the following scenario should throw an error:

const bug = { milestone: null };
console.log(bug.milestone);               // null
console.log(bug.milestone?.name);         // undefined
console.log(bug.milestone?.name.trim());  // throws an error

But the actual output when running the code is:

const bug = { milestone: null };
console.log(bug.milestone);               // null
console.log(bug.milestone?.name);         // undefined
console.log(bug.milestone?.name.trim());  // undefined

Is there a good reason for this error to be listed or should be removed?

tomocrafter commented 6 months ago

I faced exact same error and it should be removed imo. eslint's no-unnecessary-condition rule https://typescript-eslint.io/rules/no-unnecessary-condition/ enforces ?. to be . after ?. and It sounds reasonable since above code won't raise an error.

strager commented 6 months ago

Is there a good reason for this error to be listed or should be removed?

This diagnostic should be removed. In fact, it is removed in master (#1192). I will ship the fix in version 3.2.

tomocrafter commented 6 months ago

@strager Thank you! now I wonder why it is introduced first, like was it actually occurs the error?

strager commented 5 months ago

now I wonder why it is introduced first, like was it actually occurs the error?

Nah, my brain just wasn't working. 😄

strager commented 5 months ago

Fix released in version 3.2.0.