Skip to content

line output: only list files that actually changed - #336

Open
rootkiller6788 wants to merge 2 commits into
google:mainfrom
rootkiller6788:fix-line-output-unchanged-files
Open

rootkiller6788 wants to merge 2 commits into
google:mainfrom
rootkiller6788:fix-line-output-unchanged-files

Conversation

@rootkiller6788

Copy link
Copy Markdown

While playing with -output_format line I noticed it reports files that weren't touched. If you lint a directory where one file needs formatting and ten are already fine, it prints all eleven as "formatting difference found", which makes the output useless for tooling and also flips around between runs because it walks the map directly.

The default and gitlab output formats already skip unchanged files and print in a stable order, so this brings the line format in line with them: only report diffs where something actually changed, and sort the paths.

Added a unit test for the single line output and extended the existing line_output integration case with an already-formatted file so this doesn't silently regress.

The single line output format was iterating over every file it
processed, so running yamlfmt -output_format line on a directory
where only one file needs formatting would report every file in
that directory as having a formatting difference. Files that are
already formatted should not show up here.

While at it, sort the paths so the output is stable across runs;
previously it depended on Go map iteration order.
The existing line_output case only had a single file that needed
formatting, so it never exercised what happens to files that are
already formatted. Add one that yamlfmt should leave alone so the
output format is checked against a mixed directory.
@rootkiller6788
rootkiller6788 marked this pull request as ready for review November 10, 2026 05:15
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