Skip to content

Realign comment indentation and add --no-blank-line-before-processor#120

Open
jgstew wants to merge 1 commit into
homebysix:mainfrom
jgstew:fix/comment-indentation-and-processor-spacing
Open

Realign comment indentation and add --no-blank-line-before-processor#120
jgstew wants to merge 1 commit into
homebysix:mainfrom
jgstew:fix/comment-indentation-and-processor-spacing

Conversation

@jgstew

@jgstew jgstew commented Jul 15, 2026

Copy link
Copy Markdown

NOTE: this was done with Claude Code

Problem

format-autopkg-yaml-recipes uses ruamel.yaml round-trip mode, which re-emits each comment at its original absolute column. When the formatter changes structural indentation — most visibly on Process: lists, which it re-emits with the dash at column 0 (sequence=2, offset=0) whereas my recipes are commonly authored with 4-space list indentation — the surrounding keys move but comments stay put and drift out of alignment:

# input
Process:
    # comment before first processor
    - Processor: URLDownloader
      Arguments:
        # comment about url
        url: https://example.com/file.dmg
# before this PR (comments left at their old columns)
Process:
# comment before first processor      <- was col 4, structure now at col 0

- Processor: URLDownloader
  Arguments:
        # comment about url            <- still col 8, url dropped to col 4
    url: https://example.com/file.dmg

Changes

  • _realign_comments: a post-dump text pass that reindents each comment-only line to the indentation of the next content line (falling back to the previous content line for trailing comments at the end of a block). Inline key: value # ... comments are untouched.
  • --no-blank-line-before-processor: optional flag that drops - Processor: from the blank-line insertion. Useful when a separate hook manages spacing between processors; it also keeps a comment tight against the processor it documents. Default behavior is unchanged.

Tests

Added coverage for comment realignment on a reindented Process list, for the new flag keeping comments tight, and for the default still inserting a blank line before processors. Full suite passes (228 tests) and output is idempotent.

ruamel.yaml round-trips comments at their original absolute column, so a
comment does not move when the surrounding structural indentation changes
(most visibly on Process list items, re-emitted with the dash at column 0).
Add a post-dump pass that reindents comment-only lines to match the content
they precede, and add an opt-out flag for the blank line before processors.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jgstew

jgstew commented Jul 15, 2026

Copy link
Copy Markdown
Author

I am using this pre-commit hook to add blank line before - Processor: but in way where it adds the blank line above a comment that is at the same indent as - Processor but this hook does not do that properly, thus the disable flag.

For example:

  # get version from the resolved download URL:
  - Processor: com.github.jgstew.SharedProcessors/TextSearcher

ends up as:

  # get version from the resolved download URL:

- Processor: com.github.jgstew.SharedProcessors/TextSearcher

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.

1 participant