Skip to content

fix: prevent double-indent when bracket and function/sub open on same line#125

Open
chrisdp wants to merge 3 commits intofeature/new-formatting-optionsfrom
fix/double-indent-with-function-in-bracket
Open

fix: prevent double-indent when bracket and function/sub open on same line#125
chrisdp wants to merge 3 commits intofeature/new-formatting-optionsfrom
fix/double-indent-with-function-in-bracket

Conversation

@chrisdp
Copy link
Copy Markdown

@chrisdp chrisdp commented Mar 29, 2026

Summary

  • Fixes #85: when { (or [) and function/sub appear on the same line, both tokens were each incrementing nextLineOffset, causing the body to be indented 2 levels instead of 1.
  • The fix uses a skipOutdentTokens Set — when IndentFormatter detects a bracket opener and a callable keyword on the same line whose closers appear together, it undoes the extra nextLineOffset++ from the bracket and marks its closing bracket to skip the outdent adjustment.
  • Adds 6 regression tests for issue handle double-indent followed by double-outdent #85 (including nested/multi-function AA cases).
  • Adds 3 regression tests for issue #82 (.catch() and chained lambda typecast args incorrectly de-indenting surrounding code — already fixed by the Catch token guard, tests confirm it stays fixed).

Test plan

  • npm run test:nocover — all 320 tests pass
  • npm run lint — no lint errors
  • Manually verify { key: function() ... end function } patterns format with single-level indent

… line (#85)

Also add regression tests for .catch() and chained lambda typecast args
not de-indenting surrounding blocks (issue #82, already fixed by Catch guard).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
chrisdp and others added 2 commits March 28, 2026 23:24
- Refactor lastBracketIndentTokenOnLine to store opener+closer pair,
  eliminating redundant getClosingToken call and unreachable null check
- Remove unnecessary ?. optional chains on token.range (always defined),
  which Istanbul was counting as dead branches
- Add tests for end sub } and non-matching token before bracket closer

Co-Authored-By: Claude Sonnet 4.6 <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.

handle double-indent followed by double-outdent typecast expression incorrectly de-indents

1 participant