quick-lint-js
quick-lint-js copied to clipboard
10$: warn on array equality check
example code:
let arr = [];
if (arr === []) {
// this can never happen
}
saw someone on twitch make this mistake in their code, when what they really wanted was arr.length === 0
maybe quicklint should warn that the expression arr === []
here is always false?
This diagnostic is a good idea. === {}
is similar.
broader question: should it just complain for any array or object literal?
Yes. The comparison will always fail.
can i still work on this and what folder or file should I open to make the changes
can i still work on this
Yes.
what folder or file should I open to make the changes
In test/test-parse-warning.cpp
there are tests for similar cases. You can copy-paste and tweak as needed.
In src/quick-lint-js/fe/parse.cpp
there's a parser::error_on_sketchy_condition
function. That might be a good place to write the implementation.
src/quick-lint-js/fe/expression.h
contains definitions for expression classes.
I think this now duplicates https://github.com/quick-lint/quick-lint-js/issues/821
@cgsdev0 Oh, you're right!
@nebulahh You haven't showed progress on this task, and @Rebraws wrote a PR fixing this. I'm going to close this duplicate task and leave @Rebraws assigned.
Sorry for the confusion. I hope you didn't put in too much work already. =X