Add forLoopTerminator option and fix bogus next handling#130
Open
chrisdp wants to merge 2 commits into
Open
Conversation
Adds a new `forLoopTerminator` formatting option (`'next' | 'endfor' | 'original'`, default `'original'`) that normalizes `for`/`for each` loop terminators. The split/combine choice for `end for` continues to be governed by the existing `compositeKeywords` option. Also fixes a bug where a stray `next` token inside a non-loop block (e.g. `while`, `function`, `try`) caused the formatter to silently dedent. `next` is now only treated as a block terminator when its enclosing block is a `for` or `for each`.
The early-return guard was unreachable because Formatter.ts already gates the call when `forLoopTerminator` is `'original'` or unset, and the truthy checks on `endForToken`/`tokens.endFor` were unreachable because brighterscript's types declare them non-optional. Removing brings coverage back to 100%.
TwitchBronBron
approved these changes
May 7, 2026
TwitchBronBron
left a comment
Member
There was a problem hiding this comment.
Just need some readme entries for this one. Nice!
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
forLoopTerminatorformatting option ('next' | 'endfor' | 'original', default'original') that converts validly-placedfor/for eachloop terminators to a consistent style. The split/combine choice forend forcontinues to be governed by the existingcompositeKeywordsoption.nexttoken inside a non-loop block (e.g.while,function,try) caused the formatter to silently dedent.nextis now only treated as a block terminator when its enclosing block is afororfor each.while,function,sub,if,try,namespace), and allforLoopTerminatormodes including interaction withcompositeKeywordsandkeywordCase.