pmxcfs: add clang-format config add make targets to auto-format code

We are in the process of auto-formatting our Perl (using perltidy) and
JavaScript (using biome) code bases, just like we adopted rustfmt
already a few years ago. So lets also format our C code bases while at
it, while they see less activity compared to perl/js/rust at the
moment, there is still some development going on and using
clang-format works well with a rather minimal config, so just go for
it.

Add a make 'format' target with an 'tidy' alias as we use that for the
perl stuff (mostly due to the tool being named perltidy there). Using
format as main target is chosen in a similar spirit, as for clang the
tool is named clang-format and there is a clang-tidy which is a linter
though.

Check in a .clang-format config here, basing of the LLVM style but
with 4 spaces as indentation and up to 100 character columns text
width, and also try to avoid packing arguments to much into less
lines, this hurts readability and line-based editing can be nicer
w.r.t conflicts and blame/history tracking in git anyway.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2025-06-02 20:22:32 +02:00
parent a86c4b3ba3
commit 483f4ea14d
2 changed files with 10 additions and 0 deletions

5
src/pmxcfs/.clang-format Normal file
View file

@ -0,0 +1,5 @@
BasedOnStyle: LLVM
ColumnLimit: 100
IndentWidth: 4
AlignAfterOpenBracket: BlockIndent
BinPackParameters: false # TODO: evaluate using OnePerLine (needs clang 20+) for a balanance?

View file

@ -51,6 +51,11 @@ install: pmxcfs create_pmxcfs_db pmxcfs.8
install -D -m 0755 create_pmxcfs_db $(DESTDIR)/usr/bin/create_pmxcfs_db
install -D pmxcfs.8 $(DESTDIR)/usr/share/man/man8/pmxcfs.8
.PHONY: tidy format
tidy: format
format:
git ls-files ':/src/pmxcfs/*.[ch]' | xargs -n2 -P0 -- clang-format -i
.PHONY: check
check: check_memdb
./check_memdb