Skip to content

feat: add scrap check, which analyzes the sources with clang-tidy - #149

Merged
skipbit merged 10 commits into
mainfrom
feat/check-command
Nov 23, 2026
Merged

skipbit merged 10 commits into
mainfrom
feat/check-command

Conversation

@skipbit

@skipbit skipbit commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

scrap check [<path>...] [--release] [-j <jobs>] analyzes the sources of a project with the clang-tidy found on PATH, with the commands scrap build would compile them with, and compiles nothing.

  • The commands are planned as a build plans them, for the debug profile or, with --release, the release one, and written to build/<profile>/compile_commands.json, which clang-tidy is given with -p. The compilers are chosen, and a failure to find them reported, as for a build.
  • The sources the targets compile are covered. A source two targets compile is analyzed once, and clang-tidy analyzes it with the command of each. Paths narrow the sources down as they do for scrap format: a named file that is not a source of a target, a header among them, is left out with a warning, and when nothing is left the command exits with 0 without looking for clang-tidy.
  • The clang-tidy used is named with its version before the analysis starts. Files are analyzed -j at once, by default as many as the system has processors for. Each file is named in a Checking <file> line as it starts, and what clang-tidy wrote for it follows once it has ended. A check in which no file failed ends with Finished debug check, or Finished release check.
  • [check] checks in scrap.toml is passed as --checks=-*,<checks>, so it takes the place of the checks of .clang-tidy and leaves its other settings in effect.
  • The command exits with 1 when clang-tidy fails on a file, as it does on a compile error or on a warning that WarningsAsErrors makes an error, and with 0 otherwise. The files it failed on are named at the end in error: failed to check '<file>' lines, with the status clang-tidy exited with when it wrote nothing, followed by one hint. A clang-tidy that cannot be started stops the analysis and is reported once.
  • A project that states it builds nothing has nothing to analyze: its database is emptied, as a build empties it, and the command exits with 0 without looking for a compiler or clang-tidy.
  • The width the verb of a progress line is written in moves out of the build progress, so the lines of a check line up with those of a build.
  • What both commands share with the build and with scrap format moves to one place each: writing what a tool wrote to the terminal (ToolOutput), narrowing the files to the paths given with its warnings (selectRequestedFiles), the heading of a tool that failed (renderToolFailureHeading), and the hint after the errors (FixErrorsHint). The output of scrap build and scrap format does not change.
  • The README describes the command in a Static Analysis section.

Tests:

  • CheckTextTest: 7 tests of the progress lines and of how failures are named. ToolTextTest has 1 more, for the heading alone. The tests of printableOutput move from BuildProgressTest to ToolOutputTest as they were.
  • CliE2ETest: 8 tests with a stub clang-tidy, and 5 with the clang-tidy on PATH, which skip when there is none.
  • Breaking any of these fails at least one test: passing the checks of the manifest, analyzing with the database of the profile asked for, warning of a file left out, emptying the database of a project that builds nothing, exiting with 1 when a file failed, naming a clang-tidy that cannot be started once, giving the hint only for files that failed, naming the status of a file clang-tidy failed on without writing anything, and the line that ends a check.
  • The value of -j is not seen by these tests beyond being accepted; analyzing files at once is tested with the analysis itself.

The width the verb is written in moves out of the build progress, so
a check lines its own lines up with those of a build.
Each file is named as its analysis starts, and what the tool wrote
follows once it has ended. The files the tool failed on are named
after them with one hint, a tool that could not be started only once.
The commands scrap build would compile the project with are written
to compile_commands.json, and the sources the paths name are analyzed
with the clang-tidy on PATH, several at once, without compiling.
--release analyzes with the commands of the release profile, and -j
sets how many files are analyzed at once. A named file that is not a
source of a target, a header among them, is left out with a warning.
With nothing written above it, the line naming the file gave no reason
for the failure; it now says the status the tool exited with, as a
format does.
Escaping the output of a tool for the terminal and asking whether
standard error is one move out of the build progress, and both
reporters write a tool's output through the same function, so a
check no longer reads the build progress for it.
Format and check both selected the files the paths name and warned of
what they left out; one function does it for both.
A check names the files it failed on without what the tool wrote,
which it has shown already, so the heading with the signal or the
status is offered apart from the output.
@skipbit
skipbit merged commit 02442dd into main Nov 23, 2026
29 checks passed
@skipbit
skipbit deleted the feat/check-command branch November 23, 2026 07:42
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