[gdal-dev] Automating code style enforcement ?
Mateusz Loskot
mateusz at loskot.net
Fri May 5 01:45:33 PDT 2017
On 5 May 2017 at 09:22, Even Rouault <even.rouault at spatialys.com> wrote:
>> Please, let's forget about astyle.
>
> Because you consider it more limited feature-wise than clang-format ?
Because, clang-format is based on the same tooling as LLVM/clang,
at least the same tokenizer/lexer, so it can process complex and
convoluted C++ constructs within context; whenever
those tools are applied to LLVM or clang compiler itself,
libformat/clang-format update too.
> I'm wondering what you mean by "No automation of code reformatting is
> proposed. It would be treating the symptomps, no cause: developers not
> following the code formatting standard. "
Please, keep in mind that this draft was prepared and proposed for GEOS.
Kurt has copied it and, AFAIK, is going to review it applying changes
required by GDAL, based on feedback.
I made (or copied and agreed with) the statement that the best way to
reliably maintain consistent code formatting is to learn how to write
properly formatted code and ensure (eg. via code review) all developers
learn it too.
Certainly, tools like `git cl format` would be very handy to let developers
ensure their commits are properly formatted.
Finally, CI build as safety valve is necessary to notify about any style
drifting away from the agreed convention.
A pre-commit hook rejecting incompatible styles are just a stricter variation.
Automated styling of commits would just allow developers to ignore style
completely and commit any garbage with hope the magic will happen automatically.
That would be what is called treating the symptoms.
> I'd really want a script to fix edited files and fix them. From a quick
> look, it isn't obvious that my favorite text editor (kate) could ingest a
> .clang-format file to enforce the style when I'm editing.
Any change you are confusing .editorconfig?
> And honestly I don't even want to learn the rules of the style we would apply.
As per the proposal I made for GEOS, as long as you don't forget to run
clang-format tool before committing, you don't need to learn.
However, I do assume that becoming a project developer and committer,
one agrees to learn how to write code that is expected and accepted by
a project.
> We *need*
> something to fix it easily like scripts/prepare-commit[.sh/.py] that will
> check svn/git edited files and run them through the reformatter.
As I pointed in the RFC, such convenient tools are available:
git cl format from Chromium or the python script
or even running clang-format.
I'm fairly certain there is clang-format integration for Kate-based editors
that allow to run clang-format with shortcut.
Anyhow, I only meant to explain points of my original proposal for GEOS.
Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
More information about the gdal-dev
mailing list