Skip to content

feat: run clang-tidy on a source by the commands that compile it - #147

Merged
skipbit merged 3 commits into
mainfrom
feat/clang-tidy-runner
Nov 23, 2026
Merged

skipbit merged 3 commits into
mainfrom
feat/clang-tidy-runner

Conversation

@skipbit

@skipbit skipbit commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds the part that runs clang-tidy, which scrap check will use. No command uses it yet.

  • Check::analyzeFile runs clang-tidy in the project root on one source, with -p= naming the directory of compile_commands.json, so every command that compiles the source is analyzed in one run. It returns everything clang-tidy wrote, both streams together, or the failure holding it.
  • An exit status other than 0 comes back as a failure. clang-tidy 18 ends with 1 both for a diagnostic it judged an error and for a source it cannot read, so the status alone does not tell the two apart, and the command will show the output either way.
  • Checks given replace those of .clang-tidy as --checks=-*,<checks>, since --checks alone adds to them. The other settings of .clang-tidy stay in effect.
  • --quiet is passed. clang-tidy 22 then leaves out the "N warnings generated." lines; clang-tidy 18 still writes them.
  • The name, finding the program and asking for its version come from src/tool, as for clang-format.

src/check joins the linted modules.

Tests

ClangTidyTest, 5 tests, with a script standing in for clang-tidy, written by the test support that ClangFormatTest now uses too: the command line from the project root, the checks in place of the configuration's, a file that looks like an option, an analysis that ends with a status other than 0, and one stopped by a signal or not started.

Taking out --quiet, the -*, the ./ before a file that looks like an option, the project root, or standard error from what comes back each fails at least one of them.

The command line was also run with clang-tidy 18.1.3 on a project whose .clang-tidy enables modernize-use-nullptr: without checks given it reported that check, and with readability-braces-around-statements given it reported that one alone.

analyzeFile runs clang-tidy from the project root with the directory
of compile_commands.json, and returns everything it wrote. Checks
given replace those of .clang-tidy, so they come after -*. --quiet
leaves out the count of warnings on the versions that honour it.

src/check joins the linted modules.
The clang-format and clang-tidy tests each wrote the same script and
split the file it writes into lines. Both now come from the test
support, which reads the file with the standard library so it keeps
linking no scrap module.
clang-tidy given an empty -p analyzes without the commands, and given
--checks=-*, alone enables no check and refuses to run.
@skipbit
skipbit merged commit 74e492f into main Nov 23, 2026
29 checks passed
@skipbit
skipbit deleted the feat/clang-tidy-runner branch November 23, 2026 03:02
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