Use pre-commit, Clang-Format, format-makefile, shfmt
Moderators: another_commander, winston
Use pre-commit, Clang-Format, format-makefile, shfmt
I suggest adopting standardised formatting for all Oolite source code using pre-commit with Clang-Format, format-makefile, shfmt, using the tool defaults which are industry standards or near as these days. This will also ensure that using different IDEs and text editors doesn't mess things up.
Re: Use pre-commit, Clang-Format, format-makefile, shfmt
To prevent history destruction with so many files touched, we would need to create
All developers need to do:
A suitable pre-commit config:
.git-blame-ignore-revs with the commit hash of the squashed and merged PR. When Git or GitHub sees a commit in this file, it looks past that commit to the version of the line before it changed so that the formatting changes are ignored. More on this here.Code: Select all
# 1. Run formatter & Commit
git commit -a -m "Style: Mass reformat"
# 2. Get Hash
git rev-parse HEAD > .git-blame-ignore-revs
# 3. Config Git to use it
git config blame.ignoreRevsFile .git-blame-ignore-revs
# 4. Commit the ignore file
git add .git-blame-ignore-revs
git commit -m "Add ignore-revs file"
git config blame.ignoreRevsFile .git-blame-ignore-revs in future as part of checking out Oolite.A suitable pre-commit config:
Code: Select all
repos:
# 1. Standard Pre-commit Hooks (Essential for Makefiles)
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
- id: check-case-conflict
- id: mixed-line-ending
args: ['--fix=lf']
# 2. Clang-Format (C, C++, Obj-C)
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.6
hooks:
- id: clang-format
# You can define types if you only want it on specific files
types_or: [c, c++, objective-c, cuda]
# 3. shfmt (Shell Scripts)
- repo: https://github.com/scop/pre-commit-shfmt
rev: v3.7.0-4
hooks:
- id: shfmt
# args:
# -w: write changes to file
# -s: simplify code
# -i 4: indent with 4 spaces (standard for shell)
args: ["-w", "-s", "-i", "4"]
# 4. Checkmake (Makefile Linter)
- repo: https://github.com/mrtazz/checkmake.git
rev: 0.2.2
hooks:
- id: checkmake-
another_commander
- Quite Grand Sub-Admiral

- Posts: 7192
- Joined: Wed Feb 28, 2007 7:54 am
Re: Use pre-commit, Clang-Format, format-makefile, shfmt
This seems complicated with quite high risk of messing up something with all needed configs etc. Could we consider it after releasing 1.92?
Re: Use pre-commit, Clang-Format, format-makefile, shfmt
Sure that makes sense.another_commander wrote: ↑Tue Jan 06, 2026 9:12 amThis seems complicated with quite high risk of messing up something with all needed configs etc. Could we consider it after releasing 1.92?
