Skip to content

feat: add ternaryIndentStyle with structural indentation option#6

Open
steffen-heil-secforge wants to merge 1 commit intomainfrom
feature/ternary-indent-style
Open

feat: add ternaryIndentStyle with structural indentation option#6
steffen-heil-secforge wants to merge 1 commit intomainfrom
feature/ternary-indent-style

Conversation

@steffen-heil-secforge
Copy link
Member

This commit adds a new configuration option conditionalExpression.indentStyle that controls how ternary conditional expressions are indented.

Options:

  • align (default): Aligns the ? and : operators under the condition, maintaining the current behavior
  • structural: Uses structural indentation for nested ternary expressions, adding one level of indentation for each nested ternary to improve readability and avoid deep nesting issues

Changes:

  • Added TernaryIndentStyle enum to configuration types
  • Updated schema.json with new configuration option
  • Modified gen_conditional_expr to support both indentation modes
  • Added comprehensive test coverage for both modes

🤖 Generated with Claude Code

@steffen-heil-secforge steffen-heil-secforge force-pushed the feature/ternary-indent-style branch from 1f673e9 to 20a8808 Compare October 26, 2025 15:03
Adds a new configuration option `conditionalExpression.indentStyle` with two modes:

- "align" (default): All branches of nested ternaries align at the same indentation level
  Example:
  ```
  const result = condition1
      ? value1
      : condition2
      ? value2
      : value3;
  ```

- "structural": Nested ternaries increase indentation to reflect nesting structure
  Example:
  ```
  const result = condition1
      ? value1
      : condition2
          ? value2
          : value3;
  ```

The structural mode properly handles wrapper nodes (parentheses, type assertions,
satisfies expressions, non-null assertions) by traversing through them to find the
top-most conditional expression in the chain, ensuring consistent indentation.

Implementation includes:
- Configuration schema updates with new enum type
- Helper function to traverse wrapper nodes in structural mode
- Refactored conditional expression generation for both modes
- Comprehensive test specs for align and structural indentation styles

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

Co-Authored-By: Claude <noreply@anthropic.com>
@steffen-heil-secforge steffen-heil-secforge force-pushed the feature/ternary-indent-style branch from 76f7583 to f771199 Compare October 26, 2025 15:52
@steffen-heil-secforge steffen-heil-secforge changed the title feat: Add ternaryIndentStyle with structural indentation option feat: âdd ternaryIndentStyle with structural indentation option Oct 26, 2025
@steffen-heil-secforge steffen-heil-secforge changed the title feat: âdd ternaryIndentStyle with structural indentation option feat: add ternaryIndentStyle with structural indentation option Oct 26, 2025
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