feat(linter): implement eslint/no-sequences rule#16872
Merged
camc314 merged 8 commits intooxc-project:mainfrom Dec 15, 2025
Merged
feat(linter): implement eslint/no-sequences rule#16872camc314 merged 8 commits intooxc-project:mainfrom
eslint/no-sequences rule#16872camc314 merged 8 commits intooxc-project:mainfrom
Conversation
CodSpeed Performance ReportMerging #16872 will not alter performanceComparing Summary
Footnotes
|
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)