clang-format is located in clang/tools/clang-format and can be used to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code.
But the pre-commit hook denies this kind of configuration file:
---
# We'll use defaults from the LLVM style, but with 4 columns indentation.
BasedOnStyle: LLVM
IndentWidth: 4
---
Language: Cpp
# Force pointers to the type for C++.
DerivePointerAlignment: false
PointerAlignment: Left
---
Language: JavaScript
# Use 100 columns for JS.
ColumnLimit: 100
---
Language: Proto
# Don't format .proto files.
DisableFormat: true
---
Language: CSharp
# Use 100 columns for C#.
ColumnLimit: 100
...
No objection from me. C++ projects are naturally polyglot in that they contain CMake, JSON, YAML, etc. Picking sensible code formatting across the board is a great idea.
I would like to avoid lots of fiddly configuration per repo, but I’m willing to defer that goal until accessible CI facilities are discovered or developed that meet our needs.
To be specific, I don’t know that we need a few dozen lines in every repo to express “this repo uses Beman standard formatting”. I predict we’ll have subtly different settings across our repos – even with a fairly modest number of repos.
I advise this against clang-format as if someone wants to change linting rules, the first place they will look at would be pre-commit config, people don’t usually think about clang-format when they format json files.
pre-commit run check-yaml --files .clang-format --verbose
check yaml...............................................................Failed
- hook id: check-yaml
- duration: 0.21s
- exit code: 1
expected a single document in the stream
in ".clang-format", line 3, column 1
but found another document
in ".clang-format", line 5, column 1
bash-5.2$