STYLE: Enforce ITK style defined by .clang-format#1191
Conversation
|
Is it possible to add a test to new PRs that check for style? |
That should be possible, and probably not too hard for someone who better understands how to make those checks. |
|
@hjmjohnson for the commit that actually applies the mass style change I suggest commiting with |
Yes, the |
|
Also related, is it possible to add this as an (optional) precommit hook for ITK developers? https://gist.github.com/alexeagle/c8ed91b14a407342d9a8e112b5ac7dab |
|
It could be made a pre-commit hook but we'd need to make sure that developers who enable it are using the matching clang-format version. |
|
Hopefully a pre-commit hook could be overridden? It would be a shame to discourage small first time patches just because someone doesn't have a specific version of clang-format on their computer. |
I would be more in favor of a CI service than requiring additional tools locally. If it's optional that would be OK tool. As for version compatibility, VS and Clion come with an embedded version for clang-format, are they close enough for most small changes? It would be nice if the default tool is good enough most of the time for small changes. Needing a specific version for larger changes would be OK. |
|
For reference, if we choose a |
@bradking EXCELLENT IDEAS!!! Thank you. I'll do that. |
I'm using a modified version of the cmake mechanism with standardization on clang 8.0 (for a new refined C++11 feature support, and because that is the clang-format version that is standard with one of the Visual studio plugins, and CLion plugins. |
I choose to standardize on clang 8 to be most aligned with those two IDE's :). |
| const ImageType::IndexType LeftEyeIndex = GetIndexFromMouseClick(); | ||
| ImageType::PointType LeftEyePoint; | ||
| image->TransformIndexToPhysicalPoint(LeftEyeIndex,LeftEyePoint); | ||
| ImageType::PointType LeftEyePoint; |
There was a problem hiding this comment.
I very much dislike alignment somewhere in the middle of a line of code. It would mean that whenever line 348 is modified, line 349 would also be modified to keep the alignment in sync. Please no!
There was a problem hiding this comment.
@N-Dekker, Personally I agree, but this has been discussed several times before, and the historical community agreement is that the benefits in readability outweigh the pain.
There was a problem hiding this comment.
FWIW, I agree with @N-Dekker. It will mess up blame & history to re-indent like that.
There was a problem hiding this comment.
I agree, it's very hard to maintain this alignment. Even if this was discussed before, since formatting will change now anyway, it would be a good time to re-check what most people prefer.
There are many similar questions where people can have different preferences, so maybe all the controversial decisions could be put up on a public vote. We could give different weight to votes depending on involvement in ITK project (e.g., a core ITK developer could have 10x more vote than an ITK user).
There was a problem hiding this comment.
Yes, this is annoying inside functions/methods. Unfortunately, clang-format does not distinguish that from declarations inside classes.
@hjmjohnson Maybe we could completely abolish alignment of declarations because of this?
There was a problem hiding this comment.
@dzenanz @lassoan @N-Dekker @thewtex I want to be VERY CLEAR: I am doing my best to provide better automation of style, and not dictate the style. I spent a lot of time finding the set of options that minimizes changes to the current style while providing AUTOMATION.
I'm willing to entertain other global style changes, but to the extent possible I would rather not let the scope of this PR require that every style be re-considered.
Please vote now, and recruit others to support/reject this coding change.
NOTE: Making this change will also require changing KWSTYLE rules, as the current suggestions will cause the KWSTYLE checks to fail.
--- NOW my personal opinion: Let's change KWSTYLE and remove it's enforcement, and change .clang-format AlignConsecutiveDeclarations: true to AlignConsecutiveDeclarations: false
There was a problem hiding this comment.
Thank you for taking the time for this, I look forward to not thinking about style anymore. 👔 🕴
Are we going to need KWStyle any more?
My issue with looking through history, is not a single change like this one ( seems to be a very good plan for it ). It is more the frequent white space changes cause by this case and the one below. Thank you for being open to a couple be for the big commit.
|
Errors:
|
5c2a0a7 to
1774128
Compare
|
@thewtex All Green! |
Empty macros are nested by clang-format. Explicitly prohibit clang-formatting of lists of macros.
Inconsistent space inside of <> () and [] is resolved to not have spaces consistently as preferred by the ITK community. This was previously unspecified in the style requirements.
BinPackParameters (bool) If false, a function declaration’s or function definition’s parameters will either all be on the same line or will have one line each.
Examples are used to generate Software Guide, and shorter code column limits are needed to render the code into latex.
This is a commit that precedes an automatic application of
clang-format-8.0 to update the C++ style of our entire source tree.
This may be helpful to rebase a topic branch that was originally
based on a commit preceding the transition. One may first rebase
the topic on this commit. Then use one of the following approaches.
* Rewrite the topic, including this commit, using `git filter-branch`
`--tree-filter` with `Utilities/Maintenance/clang-format.bash` to
update the style in every commit. Rebase the revised topic, excluding
the rewrite of this commit, on the style transition commit.
- OR -
* Add a `.git/info/grafts` entry to change the parent of the first
commit in the topic from this commit to the style transition commit.
Rewrite the topic using `git filter-branch --tree-filter` with
`Utilities/Maintenance/clang-format.bash` to update the style in every
commit. Then remove the graft, which was resolved by the filter.
See `git help filter-branch` and `git help repository-layout` for
details.
1774128 to
2b0cf47
Compare
|
@thewtex @dzenanz I have rebased on the merges from this morning. Last nights builds were clean green from the CI perspective. This PR required a manual merging of 2 small blocks of conflicts in from the DCMTK merge that occurred this morning. I tested, and the build succeeded, and all tests pass. As this has 2 approvals, I'd really like to "rebase and merge" immediately (i.e. not wait 5 hours for another green CI for the small formatting fixes induced by the DCMTK code merges ) so that new PR's can be generated against this rigorously enforced code style. Please provide a +1 or just rebase and merge at your earliest convenience, |
|
In some of the previous builds there was a warning about multi-line comment. Was that also addressed? Not a showstopper if it wasn't. But as there are no other PRs which are ready for merging we could wait a few hours for the CI builds too. |
|
Yes it was addressed last night.
A “// clang-format off” “// clang-format on” protection around a comment that had a large latex table imbedded in a comment block.
Hans
From: "notifications@github.com" <notifications@github.com>
Reply-To: InsightSoftwareConsortium/ITK <reply@reply.github.com>
Date: Thursday, August 29, 2019 at 10:56 AM
To: "nipype@noreply.github.com" <ITK@noreply.github.com>
Cc: Hans Johnson <hans.j.johnson@gmail.com>, Mention <mention@noreply.github.com>
Subject: Re: [InsightSoftwareConsortium/ITK] STYLE: Enforce ITK style defined by .clang-format (#1191)
In some of the previous builds there was a warning about multi-line comment. Was that also addressed? Not a showstopper if it wasn't. But as there are no other PRs which are ready for merging we could wait a few hours for the CI builds too.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
./Utilities/Maintenance/clang-format.bash \ --clang-format ~/local/llvm/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang-format \ --tracked This patch updates the ITK preferred style to one that can be automatically enforced, integrated with many IDE's, and based on externally defined documentation and examples. See: https://discourse.itk.org/t/update-coding-style-for-itk/2055 Most of the changes make inconsistent coding practices consistent throughout the toolkit. Community discussions regarding changes to the current defined coding style are explicitly not included in this request so that they can be independantly reviewed and considered. One large change is changing the {} indentation style from `Whitesmiths` style https://en.wikipedia.org/wiki/Indentation_style#Whitesmiths_style to an indentation style consistent with many of the other common indentation styles. The primary reason for this change is to overcome the common deficiency of IDE's and formatters to support this uncommon style choice. Many ITK developers provided insightful comments and suggestions that resulted in this set of style comprimises. Co-authored-by: Hans Johnson <hans-johnson@uiowa.edu> Co-authored-by: Dzenan Zukic <dzenan.zukic@kitware.com> Co-authored-by: Brad King <brad.king@kitware.com>
2b0cf47 to
f3faab0
Compare
dzenanz
left a comment
There was a problem hiding this comment.
Merging this today seems plausible to me.
| ParallelizeArray(SizeValueType firstIndex, | ||
| SizeValueType lastIndexPlus1, | ||
| ArrayThreadingFunctorType aFunc, | ||
| ProcessObject * filter); |
There was a problem hiding this comment.
I thought we agreed on no declaration alignment and left-aligned pointers?
https://doodle.com/poll/sb4aqtpsy6qs7z3h
https://doodle.com/poll/yn8bxxtdzz97xg38
While pointer alignment is more of a personal choice, declaration alignment is not quite common outside of ITK. That's why people less involved with ITK seem to prefer no alignment.
There was a problem hiding this comment.
@dzenanz Please talk to @thewtex.
I was under the opposite impression that this PR was to use the current alignment strategies (i.e. smaller overall differences from current style), and that further discussions were needed for both of those poll items. The further discussions will need to be separate pull requests, and each will need several weeks of a community discussion on discourse.
Discussions from PR InsightSoftwareConsortium#1191 describing community desire to change enforcment of style that have proven to be disruptive or difficult to maintain.
Applies the clang format defined by InsightSoftwareConsortium/ITK#1191.
Removed spaces between class and member names of IO classes, that were accidentally introduced with pull request InsightSoftwareConsortium#1191 commit 2074c2f "STYLE: Enforce ITK style defined by .clang-format". Follow-up to pull request InsightSoftwareConsortium#2096 commit 734d6f8 "STYLE: Remove space between class and member names in C++ source files"
Removed spaces between class and member names, that were accidentally introduced with pull request InsightSoftwareConsortium#1191 commit 2074c2f "STYLE: Enforce ITK style defined by .clang-format". Using bash commands like: find . \( -iname *.cxx \) -exec perl -pi -w -e 's/([A-Z]\w+) \:\:(\w)/$1::$2/g;' {} \; Follow-up to pull request InsightSoftwareConsortium#2096 commit 734d6f8 "STYLE: Remove space between class and member names in C++ source files"
Removed spaces between class and member names, that were accidentally introduced with pull request #1191 commit 2074c2f "STYLE: Enforce ITK style defined by .clang-format". Using bash commands like: find . \( -iname *.cxx \) -exec perl -pi -w -e 's/([A-Z]\w+) \:\:(\w)/$1::$2/g;' {} \; Follow-up to pull request #2096 commit 734d6f8 "STYLE: Remove space between class and member names in C++ source files"
Removed spaces between class and member names, that were accidentally introduced with pull request InsightSoftwareConsortium#1191 commit 38e2d2d "STYLE: Enforce ITK style defined by .clang-format". Using bash commands like: find . \( -iname *.cxx \) -exec perl -pi -w -e 's/([A-Z]\w+) \:\:(\w)/$1::$2/g;' {} \; Follow-up to pull request InsightSoftwareConsortium#2096 commit 4b95bbd "STYLE: Remove space between class and member names in C++ source files"
ITK/Utilities/Maintenance/clang-format.bash
--clang-format ~/local/llvm/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang-format
--tracked
This patch updates the ITK preferred style to one that can be
automatically enforced, integrated with many IDE's, and based
on externally defined documentation and examples.
See: https://discourse.itk.org/t/update-coding-style-for-itk/2055
Most of the changes make inconsistent coding practices consistent
throughout the toolkit.
One large change is changing the {} indentation style from
Whitesmithsstyle https://en.wikipedia.org/wiki/Indentation_style#Whitesmiths_styleto an indentation style consistent with many of the other common
indentation styles. The primary reason for this change is to
overcome the common deficiency of IDE's and formatters to support
this uncommon style choice.
Completes the work started in #1094
PR Checklist