-
-
Notifications
You must be signed in to change notification settings - Fork 763
feat(linter): implement eslint/no-sequences rule
#16872
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
Conversation
CodSpeed Performance ReportMerging #16872 will not alter performanceComparing Summary
Footnotes
|
camc314
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
This rule disallows the use of the comma operator, except in: - For loop initializers and update expressions - Expressions wrapped in parentheses (when allowInParentheses is true) For grammar positions that require parentheses (if, while, do-while, switch, with), double parentheses are needed to indicate intentionality. Options: - allowInParentheses (default: true): allows comma operator when wrapped in parentheses
Follow oxc conventions by using DefaultRuleConfig for cleaner configuration parsing.
- Fix for loop detection to skip ParenthesizedExpression nodes - Add ArrowFunctionExpression body to double-parens requirement - Add WithStatement test coverage - Fix for ((a,b);;) with allowInParentheses: false (ESLint compatibility)
…ibility
The grammar-required parentheses (e.g., `if (...)`) don't appear in the AST
as ParenthesizedExpression nodes. So for if/while/do/switch/with, paren_depth
of 1 already indicates an extra layer of parentheses showing intentional use.
Only arrow function bodies need paren_depth >= 2 because the first layer
is syntactically required (`() => (a, b)` vs `() => a, b` which would be
parsed as `(() => a), b`).
Test cases now match ESLint official documentation examples:
- `if ((doSomething(), !!test))` - PASS (1 extra paren)
- `do {} while ((doSomething(), !!test))` - PASS (1 extra paren)
- `() => (a, b)` - FAIL (needs double parens)
- `() => ((a, b))` - PASS (2 parens for arrow body)
Sync documentation examples with actual implementation: - Conditions only need single extra parentheses - Arrow function body needs double parentheses
4464284 to
3691618
Compare
Summary
Implements the
eslint/no-sequencesrule that disallows the use of the comma operator.The comma operator evaluates each of its operands (from left to right) and returns the value of the last operand. However, this frequently obscures side effects, and its use is often an accident.
Features
allowInParenthesesoption (default:true) allows sequences wrapped in parenthesesExamples
Incorrect:
Correct:
Closes #481 (partially - adds no-sequences)