Skip to content

feat: check the format of the sources with scrap format --check - #145

Merged
skipbit merged 6 commits into
mainfrom
feat/format-check
Nov 23, 2026
Merged

skipbit merged 6 commits into
mainfrom
feat/format-check

Conversation

@skipbit

@skipbit skipbit commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds --check to scrap format. With it, no file is changed: each file formatting would change is reported, and the command exits with 1 when there is any or a file cannot be checked, and with 0 otherwise.

$ scrap format --check
Using clang-format '/usr/bin/clang-format' (version 18.1.3)
warning: 'src/main.cpp' is not formatted
hint: run the same command without --check to format the files
  • The files, the paths and the clang-format used are those of a format, and so are the messages when one is left out or clang-format is missing. Paths that leave no file to check exit with 0, as they do for a format.
  • Each file is checked with checkFile, which compares what clang-format writes with the file. A file clang-format fails on is reported as a format reports it, under error: failed to check 'src/a.cpp', and the other files are still checked. A file that cannot be read back to compare is reported as error: cannot read 'src/a.cpp' to compare it with what clang-format wrote.
  • A clang-format that cannot be started stops the check at the first file, as it stops a format.

The README describes the option.

Tests

  • FormatTextTest, 2 more tests: the warning and the hint, and a check that failed or could not read the file back.
  • CliE2ETest, 4 more tests. Three run a script that stands in for clang-format on PATH: a check that reports a file and changes none, then passes once the project is formatted; a file clang-format fails on followed by the next; and a clang-format that cannot be started. One runs the clang-format of the PATH the tests run with, and skips when there is none: a check that finds the file, then passes once the project is formatted.

Each of these fails at least one test when taken out: the warning, the exit code for a file that would change, the hint, going on after a failed file, stopping at a clang-format that cannot be started, the option itself, telling a file that would change from one that would not, and the heading of a failed check.

With --check, no file is changed. Each file formatting would change is
reported with a warning, followed by a hint to run scrap format, and
the command exits with 1 when there is any.
Document that scrap format --check exits with 1 for a file formatting
would change, and test that a check names a clang-format it could not
start as a format does.
A check of named paths no longer suggests formatting the whole project.
scrap format --check changes no file, so its failures no longer say
that formatting failed.
A check that fails exits with 1 as well, and paths that leave no file
to check exit with 0.
@skipbit
skipbit merged commit 6b5b3e6 into main Nov 23, 2026
29 checks passed
@skipbit
skipbit deleted the feat/format-check branch November 23, 2026 00:39
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