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
Open
fix: prevent double-indent when bracket and function/sub open on same line#125chrisdp wants to merge 3 commits intofeature/new-formatting-optionsfrom
chrisdp wants to merge 3 commits intofeature/new-formatting-optionsfrom
Conversation
This was
linked to
issues
Mar 29, 2026
…with-function-in-bracket
- 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>
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
{(or[) andfunction/subappear on the same line, both tokens were each incrementingnextLineOffset, causing the body to be indented 2 levels instead of 1.skipOutdentTokensSet — whenIndentFormatterdetects a bracket opener and a callable keyword on the same line whose closers appear together, it undoes the extranextLineOffset++from the bracket and marks its closing bracket to skip the outdent adjustment..catch()and chained lambda typecast args incorrectly de-indenting surrounding code — already fixed by theCatchtoken guard, tests confirm it stays fixed).Test plan
npm run test:nocover— all 320 tests passnpm run lint— no lint errors{ key: function() ... end function }patterns format with single-level indent