From 48ec472084141bd3bb0e50fb403ba2c1f7ad9723 Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Sat, 24 May 2025 19:02:20 -0700 Subject: [PATCH 1/4] Add clang-tidy to pre-commit --- maintainers/flake-module.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/maintainers/flake-module.nix b/maintainers/flake-module.nix index 224f47268..bdc7edab9 100644 --- a/maintainers/flake-module.nix +++ b/maintainers/flake-module.nix @@ -65,6 +65,14 @@ ''^tests/functional/lang/eval-fail-set\.nix$'' ]; }; + clang-tidy = { + enable = true; + # TODO: this requires meson to have been configured + # we could optionally wrap this in a script that runs meson first + # but for now let us keep it simple + entry = "${pkgs.clang-tools}/bin/clang-tidy --fix -p ./build"; + files = ''^src/libstore''; + }; clang-format = { enable = true; # https://github.com/cachix/git-hooks.nix/pull/532 From a0527da40e83054d246049a9e1a94ca742a5f771 Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Sat, 24 May 2025 19:29:12 -0700 Subject: [PATCH 2/4] Add misc-include-cleaner to .clang-tidy --- .clang-tidy | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index 0887b8670..dd997c771 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,3 +1,6 @@ # We use pointers to aggregates in a couple of places, intentionally. # void * would look weird. -Checks: '-bugprone-sizeof-expression' +Checks: ' + misc-include-cleaner, + -bugprone-sizeof-expression + ' \ No newline at end of file From 1552fb6228621e5a48a0b897de15669ecec8d36f Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Tue, 27 May 2025 09:21:59 -0700 Subject: [PATCH 3/4] Make it only bugprone check --- .clang-tidy | 1 - doc/manual/source/development/building.md | 10 ++++++++++ maintainers/flake-module.nix | 10 ++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index dd997c771..9eac06fe1 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,6 +1,5 @@ # We use pointers to aggregates in a couple of places, intentionally. # void * would look weird. Checks: ' - misc-include-cleaner, -bugprone-sizeof-expression ' \ No newline at end of file diff --git a/doc/manual/source/development/building.md b/doc/manual/source/development/building.md index 167463837..8a2bfb8ca 100644 --- a/doc/manual/source/development/building.md +++ b/doc/manual/source/development/building.md @@ -291,6 +291,16 @@ To refresh pre-commit hook's config file, do the following: 1. Exit the development shell and start it again by running `nix develop`. 2. If you also use the pre-commit hook, also run `pre-commit-hooks-install` again. +#### Hooks + +##### clang-tidy + +Portions of the codebase are checked with [clang-tidy](https://clang.llvm.org/extra/clang-tidy/). + +> clang-tidy is a clang-based C++ “linter” tool. + +The current build system, Meson, by default outputs a `compile_commands.json` file which is used by all Clang tooling (clang-tidy, clangd etc..). + ### VSCode Insert the following json into your `.vscode/settings.json` file to configure `nixfmt`. diff --git a/maintainers/flake-module.nix b/maintainers/flake-module.nix index bdc7edab9..a2bcee8db 100644 --- a/maintainers/flake-module.nix +++ b/maintainers/flake-module.nix @@ -70,8 +70,14 @@ # TODO: this requires meson to have been configured # we could optionally wrap this in a script that runs meson first # but for now let us keep it simple - entry = "${pkgs.clang-tools}/bin/clang-tidy --fix -p ./build"; - files = ''^src/libstore''; + # + # clang-tidy doesn't work well running it on multiple files + # TODO: change this to use run-clang-tidy.py + entry = "${pkgs.writeShellScript "clang-tidy-wrapper" '' + for file in "$@"; do + "${pkgs.clang-tools}/bin/clang-tidy" --fix -p ./build "$file" + done + ''}"; }; clang-format = { enable = true; From 1460f9f52c32df103cded1b6dfc202087739f703 Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Tue, 27 May 2025 10:06:36 -0700 Subject: [PATCH 4/4] Fix uninitialized variable in repl.hh --- src/libcmd/include/nix/cmd/repl.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcmd/include/nix/cmd/repl.hh b/src/libcmd/include/nix/cmd/repl.hh index 83e39727f..2cb46c69d 100644 --- a/src/libcmd/include/nix/cmd/repl.hh +++ b/src/libcmd/include/nix/cmd/repl.hh @@ -11,7 +11,7 @@ struct AbstractNixRepl Bindings * autoArgs; AbstractNixRepl(ref state) - : state(state) + : state(state), autoArgs(nullptr) { } virtual ~AbstractNixRepl()