Skip to content

feat: add useParentheses configuration option#5

Open
steffen-heil-secforge wants to merge 3 commits intomainfrom
feature/use-parentheses
Open

feat: add useParentheses configuration option#5
steffen-heil-secforge wants to merge 3 commits intomainfrom
feature/use-parentheses

Conversation

@steffen-heil-secforge
Copy link
Member

@steffen-heil-secforge steffen-heil-secforge commented Oct 24, 2025

Adds a new useParentheses configuration option to control how parentheses are used around expressions.

Three modes are supported:

  • maintain: preserves parentheses as written in source code
  • disambiguation: forces parentheses for disambiguation (object literals, function expressions, class expressions at statement position)
  • preferNone: removes unnecessary parentheses, only using them when required to avoid breaking code

The implementation respects JavaScript operator precedence rules and syntax requirements, ensuring parentheses are kept when needed for unary operators before exponentiation and other precedence-critical cases.

@steffen-heil-secforge steffen-heil-secforge force-pushed the feature/use-parentheses branch 5 times, most recently from 038d4e4 to 10ec06a Compare October 26, 2025 11:52
@steffen-heil-secforge steffen-heil-secforge changed the title use-parentheses feat: add useParentheses configuration option Oct 26, 2025
@steffen-heil-secforge steffen-heil-secforge force-pushed the feature/use-parentheses branch 13 times, most recently from cf0498a to 740d668 Compare October 28, 2025 19:14
steffen-heil-secforge and others added 2 commits November 7, 2025 19:05
…t suites

Added comprehensive test cases for type assertions in binary expressions
to all three useParentheses configuration modes:
- Disambiguation: Adds parentheses for clarity
- Maintain: Preserves existing parentheses
- PreferNone: Removes unnecessary parentheses

Tests demonstrate that parentheses around type assertions in binary expressions
are not required for operator precedence (type assertions have higher precedence
than relational operators like >=), so they can be safely removed when not needed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add test case for `(([] as X[])).f(g)` to all three useParentheses modes:
- Disambiguation: removes outer parentheses -> `([] as X[]).f(g)`
- Maintain: keeps both sets of parentheses -> `(([] as X[])).f(g)`
- PreferNone: removes outer parentheses -> `([] as X[]).f(g)`

This ensures proper handling of nested parentheses around type assertions
followed by member access expressions.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments