[gdal-dev] Automating code style enforcement ?
even.rouault at spatialys.com
Fri May 5 04:11:30 PDT 2017
> 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.
For now, we are still on svn, so a relatively SCM-independant solution would be better.
By the way, git cl format doesn't seem available out-of-the-box on my Ubuntu 16.04. Perhaps
there's an additional package to install ?
> 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
Yes, but I'm not sure we want to depend on SVN pre-commit hooks, so as to be more future
proof. I'd rather see it as a check as part as one of the Travis-CI builds.
> 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?
Perhaps. I'm not familiar with it either.
> > 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.
But you must remember to run it on every file you touched, which you can easily forget at
some point. Some tiny wrapping on top of that to iterate over all modified files would be
convenient (hint: what does QGIS' scripts/prepare-commit.sh)
> 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.
As soon as you are involved in several projects, there will be different code styles applied, so
don't expect people (at least me) to know the precise code style to apply for a particular one.
Honestly I don't care about if spaces are put before or after parentheses (I'm pretty sure I'm
not self-consistent regarding that. Depends on my mood of the day), or such details. Mostly
consistant indentation is needed for readability. Other people are more sensitive to that, and
I'm fine with that. But we should really make it easy to everybody to ultimately have a way to
submit compliant code, either in their editor, or as a pre-commit action. The later is even
more true for casual contributors.
> > 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
https://github.com/mongodb/mongo/blob/master/buildscripts/clang_format.py you mean ?
Seems to be git only.
Spatialys - Geospatial professional services
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the gdal-dev