fix: keep comments with statement in IndentNestedKeywords - #1919
Merged
bhirsz merged 1 commit intoAug 26, 2026
Merged
Conversation
Previously all comments were moved in front of the formatted keyword, which could relocate line-scoped disablers (e.g. robocop: fmt: off) and detach comments from the code they reference. Comments trailing data on a line are now anchored to the closest keyword or argument and rendered on the same output line, while comment-only lines are kept as standalone comment lines before the statement. Closes #1507 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bhirsz
deleted the
fix/keep-comments-with-statement-in-indent-nested-keywords
branch
August 26, 2026 12:02
This was referenced Aug 26, 2026
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.
Description
The
IndentNestedKeywordsformatter used to collect all comments from a run-keyword statement and move them in front of the formatted keyword. This caused two problems:# robocop: fmt: off) were relocated away from the line they were meant to affect.This PR makes the formatter keep comments together with their code:
The same anchoring logic is now applied consistently across keyword calls and settings (
Suite Setup/Suite Teardown/Test Setup/Test Teardown/[Setup]/[Teardown]), replacing the old "merge every comment onto the first line" behavior for settings.Example
Before:
After:
Previously the comment was hoisted above
Run Keywords.Implementation
misc.py: addedsplit_comments_by_anchor()returning standalone comments plus aid(data_token) -> trailing commentsmap.IndentNestedKeywords.py:parse_keyword_linesappends trailing comments per output line; the visit methods use the anchor logic;node_was_formattednow strips comments from both sides before comparing.Tests & docs
docs/formatter/formatters/IndentNestedKeywords.md.Closes #1507