-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
if-statements allow multiple arguments and don't check for constant conditions after the first argument #60822
Comments
That sounds more like a linter-job, and there is a rule already: https://eslint.org/docs/latest/rules/no-sequences |
This rule seems to be very broad. For loops this behavior might make sense, I just don't see use cases for If-statements |
I'm not a TS team member, this is just my opinion: This isn't "multiple arguments"; you're objecting to the JavaScript comma operator being used inside an I agree that it seems code-smelly to write |
(typescript-eslint team member) Agreed that this is a linter-y request. You don't even need a full custom rule for the described request; you can just use no-restricted-syntax with selector "IfStatement > SequenceExpression". Our FAQ FWIW I'd just use no-sequences though and disable it where you really want them for some reason. |
Do note however that TS already checks |
I think i makes sense to handle some of the cases around comma expressions in TS, that said - an improvement for this (#60830) won't help this exact case because this exact case involves boolean literals and those are special-cased by the current syntactic truthy semantics: if (true) {} // ok We could handle those differently within comma expressions but @RyanCavanaugh would have to green light it first. |
Thank you everyone for your input! @kirkwaiblinger I'm now using the custom rule you provided, as within our code base there are instances of the comma-operator being used in other ways. My issue with it was specifically for if-statements. Thank you! |
π Search Terms
"if statement", "constant condition"
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?#code/MYewdgzgLgBBIFsCmBhAFk4BrAlmA5gGICuYwUO4MAvDABQAOAhgE5MICMAXHFC3vgA0MZmwQAmHtH4FhIBhXBMANgAVW7AMw0YfYkgCUNAHwwA3gCgY1mAHpbMACYhexAGZurNlkijEWYLos+gDcFgC+Fhb2MCoA7kwAnhAwbioQSMI+EMTKsCBucIioGNgCJGSKgfFJKTj4YCA+jhY4bnTwyOiYuAQV5JRgdABEouwcw8KjGhLDBsJpyhlGljYwEVExjkgMSGDbYPmB2bn5hZ0lPeWkA+Ct7RfdZX03VSNjnJMw02LiX4vLFZeawRIA
π» Code
π Actual behavior
Due to a mistake in my bracket placement as seen in the example, I accidentally learned that multiple arguments in an if statement are possible.
Currently that means:
π Expected behavior
What I would expect:
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: