fix: keep space between for and await regardless of spaceAfterForKeyword (#692)#790
Open
todor-a wants to merge 2 commits into
Open
fix: keep space between for and await regardless of spaceAfterForKeyword (#692)#790todor-a wants to merge 2 commits into
for and await regardless of spaceAfterForKeyword (#692)#790todor-a wants to merge 2 commits into
Conversation
…Keyword (dprint#692) `gen_for_of_stmt` emitted the configured space between the `for` keyword and the next token *before* the `await` marker, then appended the literal `"await "`. With `forOfStatement.spaceAfterForKeyword: false` that produced `forawait (...)`, which is not valid syntax. Always insert the space between `for` and `await`, and let the config flag control the space between the keyword sequence and the open paren: - spaceAfterForKeyword: true -> 'for await (...)' / 'for (...)' - spaceAfterForKeyword: false -> 'for await(...)' / 'for(...)'
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.
Fixes #692.
Transparency note: This PR was prepared with AI assistance (Claude).
Problem
With
forOfStatement.spaceAfterForKeyword: false:formats to:
forawaitis not valid syntax.Root cause
gen_for_of_stmt(src/generation/generate.rs:5132) used to:forspaceAfterForKeywordis_await, push literal"await "(with trailing space)With
spaceAfterForKeyword: falseandis_await: truethe sequence becomes"for" + "await "->forawait.The space between
forandawaitis mandatory regardless of the config flag — the flag should only control the space between the keyword sequence (fororfor await) and the open paren.Fix
Reorder so the space between
forandawaitis always emitted, then applyspaceAfterForKeywordafter the keyword sequence:Resulting matrix:
for awaitfor (…)for await (…)for(…)for await(…)Tests
Extended
tests/specs/statements/forOfStatement/ForOfStatement_SpaceAfterForKeyword_False.txtwith thefor awaitregression case. The existingshould format with the await keywordcase inForOfStatement_All.txtalready pins thetrue(default) branch.cargo test --releasepasses.