Add linter error for `!x` conditions that can't be `undefined` or `null` or `string`
Created by: olafurpg
Issue type
Internal request
Problem description
Our current linter rules don't error on the following pattern
const x: string[] = []
if (!x) { ... }
It would be nice if our linter setup reported an error that the !x
condition cannot be false because empty arrays are truthy in JavaScript.
Context
https://sourcegraph.slack.com/archives/C01LTKUHRL3/p1661336245339599
Steps to reproduce
No response
Impact
The PR #40610 introduced a regression causing an incident on sourcegraph.com where syntax highlighting stopped working (see INC-140). The PR included a change that was supposed to be a refactoring of how we parse a string | undefined
into a Occurrence[]
data structure, but the refactoring broke syntax highlighting because the value of occurrences
in a condition if (!occurrences)
changed from undefined
to []
.
Additional details
No response
Assigning labels
-
If this issue will require input from designers in order to complete, please assign the label needs-design
.
/cc @taylorsperry @jasongornall