Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error-message believes that a joined array is empty when elements are conditionally pushed #2265

Open
jakebailey opened this issue Jan 20, 2024 · 0 comments
Labels

Comments

@jakebailey
Copy link

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.)

@fregante fregante added the bug label Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants