`error-message` believes that a joined array is empty when elements are conditionally pushed
jakebailey opened this issue · comments
Jake Bailey commented
Code like the below appears in TypeScript's test runner; an array is used to collect error messages, which are joined and thrown when non-empty. But, error-message
thinks that this error list could be empty (though the length is checked) and errors.
const errs = [];
if (someCondition) {
errs.push("hello");
}
if (errs.length) {
throw new Error(errs.join("\n "));
}
(Personally, I think that this check is a little too strong; it's not clear that a linter can really "prove" that an array is or isn't empty, so using that info in the lint feels iffy. But, there's a length check, which is theoretically enough for this case.)