make use of clang-format or uncrustify
-
[ ] add style spec
-
[ ] format all code
-
[ ] enforce in CI
editorconfig is not really up to the task as
- most plugins only understand encoding, tabs vs spaces and indent width, nothing about brace style for instance
- editorconfig linting support for C is abysmal, seems eclint and ec are targeted at JS and the likes
clang-format could step in
- PRO: can specify a lot of format properties
- PRO: can check code against spec
- CON: I could not find a ready-made .clang-format for K&R C (would have to get created). https://zed0.co.uk/clang-format-configurator/ can help. a start:
BreakBeforeBraces: Linux
IndentWidth: '4'
- there is https://github.com/SavchenkoValeriy/emacs-clang-format-plus for emacs and support in vscode, but what about others?
May I suggest to use uncrustify instead?
The big advantage is that the configuration is much simple, and it has an example following the K&R style by default https://github.com/uncrustify/uncrustify/blob/master/etc/kr-indent.cfg, that file can be easily modified for the bracket and space customization.
Uncrustify works quite well, it's actively maintained and can be easily integrated in many editors, IDE and build systems.
If you give me the GO I can try to submit a PR.
Sounds promising, but all kinds of formatting changes are probably held up by open PRs and #394 - after those, this can be tackled, me thinks