lix/subprojects/lix-clang-tidy
eldritch horrors b0d7a81613 fix tooling after include reorganization
clangd broke because it can't look through symlinks. compile_commands
manipulation does not fix it, clangd configuration does not fix it, a
vfs overlay does not fix it, and while a combination of those can fix
it with a bind mount in place that's just too cursed to even consider

clangd bug: https://github.com/llvm/llvm-project/issues/116877

Change-Id: I8e3e8489548eb3a7aa65ac9d12a5ec8abf814aec
2024-11-19 22:55:32 +00:00
..
.clang-format build: implement clang-tidy using our plugin 2024-08-04 20:41:19 -07:00
.editorconfig build: implement clang-tidy using our plugin 2024-08-04 20:41:19 -07:00
CharPtrCast.cc clang-tidy: write a lint for charptr_cast 2024-08-08 14:53:17 -07:00
CharPtrCast.hh clang-tidy: write a lint for charptr_cast 2024-08-08 14:53:17 -07:00
default.nix build: implement clang-tidy using our plugin 2024-08-04 20:41:19 -07:00
FixIncludes.cc fix tooling after include reorganization 2024-11-19 22:55:32 +00:00
FixIncludes.hh build: implement clang-tidy using our plugin 2024-08-04 20:41:19 -07:00
HasPrefixSuffix.cc build: implement clang-tidy using our plugin 2024-08-04 20:41:19 -07:00
HasPrefixSuffix.hh build: implement clang-tidy using our plugin 2024-08-04 20:41:19 -07:00
LixClangTidyChecks.cc clang-tidy: write a lint for charptr_cast 2024-08-08 14:53:17 -07:00
meson.build lix-clang-tidy: Require Clang >= 16 2024-08-23 12:17:01 -07:00
meson.options build: implement clang-tidy using our plugin 2024-08-04 20:41:19 -07:00
README.md fix tooling after include reorganization 2024-11-19 22:55:32 +00:00

Clang tidy lints for Lix

This is a skeleton of a clang-tidy lints library for Lix.

Currently there is one check (which is already obsolete as it has served its goal and is there as an example), HasPrefixSuffixCheck.

Running fixes/checks

One file:

ninja -C build && clang-tidy --checks='-*,lix-*' --load=build/liblix-clang-tidy.so -p ../../build -header-filter '\.\./lix/.*\.h' --fix ../../lix/libcmd/installables.cc

Several files, in parallel:

ninja -C build && run-clang-tidy -checks='-*,lix-*' -load=build/liblix-clang-tidy.so -p ../../build -header-filter '\.\./lix/.*\.h' -fix ../../lix | tee -a clang-tidy-result

Resources

Developing new checks

Put something like so in myquery.txt:

set traversal     IgnoreUnlessSpelledInSource
# ^ Ignore implicit AST nodes. May need to use AsIs depending on how you are
# working.
set bind-root     true
# ^ true unless you use any .bind("foo") commands
set print-matcher true
enable output     dump
match callExpr(callee(functionDecl(hasName("hasPrefix"))), optionally(hasArgument( 0, cxxConstructExpr(hasDeclaration(functionDecl(hasParameter(0, parmVarDecl(hasType(asString("const char *"))).bind("meow2"))))))))

Then run, e.g. clang-query --preload hasprefix.query -p compile_commands.json lix/libcmd/installables.cc.

With this you can iterate a query before writing it in C++ and suffering from C++.

Tips and tricks for the C++

There is a function dump() on many things that will dump to stderr. Also llvm::errs() lets you print to stderr.

When I wrote HasPrefixSuffixCheck, I was not really able to figure out how the structured replacement system was supposed to work. In principle you can describe the replacement with a nice DSL. Look up the Stencil system in Clang for details.