[MapServer-dev] Whole code base reformatting
Even Rouault
even.rouault at spatialys.com
Thu Sep 28 07:24:27 PDT 2023
Hi,
Below text from https://github.com/MapServer/MapServer/pull/6937:
I propose to apply to Mapserver the same set of tools that have been
applied to GDAL and PROJ recently to have consistent code formatting for
C/C++ and .py files
This uses the pre-commit tool that installs hooks run by git commit to
automatically apply the formatting rules:
- clang-format for C/C++ code using a .clang-format style based on the
LLVMStyle with a minimal customization to do 2-space indentation (which
is the general practice in Mapserver), and not sorting includes (as this
breaks compilation due to includes unfortunately not being
clean/standalone, with inconsistencies like "a.h needs a type of b.h,
but b.h includes a.h"). Third-party code is excluded from reformating
(in .pre-commit-config.yaml)
- black and isort to format Python code
- flake8 to enforce some rules on Python code (with tons of exceptions
in .flake8, directly borrowed from the ones of GDAL). I had to manually
fixup a few things in the .py files
Cf https://gdal.org/development/rfc/rfc69_cplusplus_formatting.html on
how to install pre-commit (one time operation to do), and
https://gdal.org/development/dev_practices.html#commit-hooks
A .git-blame-ignore-revs file is also added to identify the reformatting
commit as to be ignored for the purpose of "git blame". It needs to be
manually declared to git with "git config blame.ignoreRevsFile
.git-blame-ignore-revs", for local use (one time operation) but it is
automatically pickedup by GitHub.
We should probably apply that to the stable branch as well to make
backports easier.
This also adds a .github/workflows/code_checks.yml GitHub Action that
runs pre-commit on pull requests to detect violations. Such sitaution
shouldn't happen for developers that have already set it up locally, but
useful to catch issues coming from casual contributors (e.g. simulation
of a commit that would break formatting:
https://github.com/rouault/mapserver/actions/runs/6340096023/job/17220740975)
Upon acceptance, I'll add a "Code formatting rules" section to
https://mapserver.org/development/index.html to gather all above information
Even
--
http://www.spatialys.com
My software is free, but my time generally not.
More information about the MapServer-dev
mailing list