Is there a way to get a compiler or linter error or warning for the following code:
const isValid = myValue.includes("substrA" || "substrB");
The "substrA" || "substrB" part always evaluates to "substrA" so I can't imagine when someone would write this code intentionally. In my particular case, the intended code was:
const isValid = myValue.includes("substrA") || myValue.includes("substrB");
Of course, you can catch such an error with tests. It would be even better if a warning was generated for it by the TypeScript compiler or by ESLint.
As expected, the compiler doesn't complain because it's perfectly valid JavaScript/TypeScript code. However, I couldn't find an ESlint rule for it either.
Is there a way have a warning generated for the code in the first code snippet above?