Skip to content

Commit 34847ee

Browse files
hjmjohnsondzenanz
authored andcommitted
ENH: Add .gitattributes to allow running ITK clang-formatting scripts
``` git filter-branch -f \ --tree-filter "~/ITK/Utilities/Maintenance/clang-format.bash --clang-format ~/Dashboard/src/ITK-clang11/clang-format-Linux --tracked" \ master.. ```
1 parent dc53aed commit 34847ee

8 files changed

+924
-770
lines changed

Diff for: .clang-format

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
## This config file is only relevant for clang-format version 8.0.0
2+
##
3+
## Examples of each format style can be found on the in the clang-format documentation
4+
## See: https://clang.llvm.org/docs/ClangFormatStyleOptions.html for details of each option
5+
##
6+
## The clang-format binaries can be downloaded as part of the clang binary distributions
7+
## from http://releases.llvm.org/download.html
8+
##
9+
## Use the script Utilities/Maintenance/clang-format.bash to faciliate
10+
## maintaining a consistent code style.
11+
##
12+
## EXAMPLE apply code style enforcement before commit:
13+
# Utilities/Maintenance/clang-format.bash --clang ${PATH_TO_CLANG_FORMAT_8.0.0} --modified
14+
## EXAMPLE apply code style enforcement after commit:
15+
# Utilities/Maintenance/clang-format.bash --clang ${PATH_TO_CLANG_FORMAT_8.0.0} --last
16+
---
17+
# This configuration requires clang-format version 8.0.0 exactly.
18+
BasedOnStyle: Mozilla
19+
Language: Cpp
20+
AccessModifierOffset: -2
21+
AlignAfterOpenBracket: Align
22+
AlignConsecutiveAssignments: false
23+
AlignConsecutiveDeclarations: true
24+
AlignEscapedNewlines: Right
25+
AlignOperands: true
26+
AlignTrailingComments: true
27+
# clang 9.0 AllowAllArgumentsOnNextLine: true
28+
# clang 9.0 AllowAllConstructorInitializersOnNextLine: true
29+
AllowAllParametersOfDeclarationOnNextLine: false
30+
AllowShortBlocksOnASingleLine: false
31+
AllowShortCaseLabelsOnASingleLine: false
32+
AllowShortFunctionsOnASingleLine: Inline
33+
# clang 9.0 AllowShortLambdasOnASingleLine: All
34+
# clang 9.0 features AllowShortIfStatementsOnASingleLine: Never
35+
AllowShortIfStatementsOnASingleLine: false
36+
AllowShortLoopsOnASingleLine: false
37+
AlwaysBreakAfterDefinitionReturnType: None
38+
AlwaysBreakAfterReturnType: All
39+
AlwaysBreakBeforeMultilineStrings: false
40+
AlwaysBreakTemplateDeclarations: Yes
41+
BinPackArguments: false
42+
BinPackParameters: false
43+
BreakBeforeBraces: Custom
44+
BraceWrapping:
45+
# clang 9.0 feature AfterCaseLabel: false
46+
AfterClass: true
47+
AfterControlStatement: true
48+
AfterEnum: true
49+
AfterFunction: true
50+
AfterNamespace: true
51+
AfterObjCDeclaration: true
52+
AfterStruct: true
53+
AfterUnion: true
54+
AfterExternBlock: true
55+
BeforeCatch: true
56+
BeforeElse: true
57+
## This is the big change from historical ITK formatting!
58+
# Historically ITK used a style similar to https://en.wikipedia.org/wiki/Indentation_style#Whitesmiths_style
59+
# with indented braces, and not indented code. This style is very difficult to automatically
60+
# maintain with code beautification tools. Not indenting braces is more common among
61+
# formatting tools.
62+
IndentBraces: false
63+
SplitEmptyFunction: false
64+
SplitEmptyRecord: false
65+
SplitEmptyNamespace: false
66+
BreakBeforeBinaryOperators: None
67+
#clang 6.0 BreakBeforeInheritanceComma: true
68+
BreakInheritanceList: BeforeComma
69+
BreakBeforeTernaryOperators: true
70+
#clang 6.0 BreakConstructorInitializersBeforeComma: true
71+
BreakConstructorInitializers: BeforeComma
72+
BreakAfterJavaFieldAnnotations: false
73+
BreakStringLiterals: true
74+
## The following line allows larger lines in non-documentation code
75+
ColumnLimit: 120
76+
CommentPragmas: '^ IWYU pragma:'
77+
CompactNamespaces: false
78+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
79+
ConstructorInitializerIndentWidth: 2
80+
ContinuationIndentWidth: 2
81+
Cpp11BracedListStyle: false
82+
DerivePointerAlignment: false
83+
DisableFormat: false
84+
ExperimentalAutoDetectBinPacking: false
85+
FixNamespaceComments: true
86+
ForEachMacros:
87+
- foreach
88+
- Q_FOREACH
89+
- BOOST_FOREACH
90+
IncludeBlocks: Preserve
91+
IncludeCategories:
92+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
93+
Priority: 2
94+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
95+
Priority: 3
96+
- Regex: '.*'
97+
Priority: 1
98+
IncludeIsMainRegex: '(Test)?$'
99+
IndentCaseLabels: true
100+
IndentPPDirectives: AfterHash
101+
IndentWidth: 2
102+
IndentWrappedFunctionNames: false
103+
JavaScriptQuotes: Leave
104+
JavaScriptWrapImports: true
105+
KeepEmptyLinesAtTheStartOfBlocks: true
106+
MacroBlockBegin: ''
107+
MacroBlockEnd: ''
108+
MaxEmptyLinesToKeep: 2
109+
NamespaceIndentation: None
110+
ObjCBinPackProtocolList: Auto
111+
ObjCBlockIndentWidth: 2
112+
ObjCSpaceAfterProperty: true
113+
ObjCSpaceBeforeProtocolList: false
114+
PenaltyBreakAssignment: 2
115+
PenaltyBreakBeforeFirstCallParameter: 19
116+
PenaltyBreakComment: 300
117+
## The following line allows larger lines in non-documentation code
118+
PenaltyBreakFirstLessLess: 120
119+
PenaltyBreakString: 1000
120+
PenaltyBreakTemplateDeclaration: 10
121+
PenaltyExcessCharacter: 1000000
122+
PenaltyReturnTypeOnItsOwnLine: 200
123+
PointerAlignment: Middle
124+
ReflowComments: true
125+
# We may want to sort the includes as a separate pass
126+
SortIncludes: false
127+
# We may want to revisit this later
128+
SortUsingDeclarations: false
129+
SpaceAfterCStyleCast: false
130+
# SpaceAfterLogicalNot: false
131+
SpaceAfterTemplateKeyword: true
132+
SpaceBeforeAssignmentOperators: true
133+
SpaceBeforeCpp11BracedList: false
134+
SpaceBeforeCtorInitializerColon: true
135+
SpaceBeforeInheritanceColon: true
136+
SpaceBeforeParens: ControlStatements
137+
SpaceBeforeRangeBasedForLoopColon: true
138+
SpaceInEmptyParentheses: false
139+
SpacesBeforeTrailingComments: 1
140+
SpacesInAngles: false
141+
SpacesInContainerLiterals: false
142+
SpacesInCStyleCastParentheses: false
143+
SpacesInParentheses: false
144+
SpacesInSquareBrackets: false
145+
Standard: Cpp11
146+
StatementMacros:
147+
- Q_UNUSED
148+
- QT_REQUIRE_VERSION
149+
TabWidth: 2
150+
UseTab: Never
151+
...

Diff for: .gitattributes

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
*.h hooks.style
2-
*.txx hooks.style
3-
*.cxx hooks.style
1+
# Custom attribute to mark sources as using our C++/C code style.
2+
[attr]our-c-style whitespace=tab-in-indent,no-lf-at-eof hooks.style=KWStyle,clangformat
43

5-
# Want namespace defined.
6-
/Code/split-components.cxx hooks.style=uncrustify
7-
/Code/SplitComponentsArgs.h hooks.style=uncrustify
4+
*.c our-c-style
5+
*.h our-c-style
6+
*.cxx our-c-style
7+
*.hxx our-c-style
8+
*.txx our-c-style
9+
*.txt whitespace=tab-in-indent,no-lf-at-eof
10+
*.cmake whitespace=tab-in-indent,no-lf-at-eof
11+
12+
# ExternalData content links must have LF newlines
13+
*.md5 crlf=input
14+
*.sha512 crlf=input

Diff for: apps/SplitComponentsArgs.cxx

+25-26
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,45 @@
22

33
#include "metaCommand.h"
44

5-
Args::Args( int argc, char* argv[] )
5+
Args::Args(int argc, char * argv[])
66
{
77
MetaCommand command;
8-
command.SetDescription(
9-
"Convert an itk::Image of vectors, covariant vectors,\
10-
or symmetric second rank tensors into its components." );
11-
command.SetAuthor( "Matthew McCormick" );
8+
command.SetDescription("Convert an itk::Image of vectors, covariant vectors,\
9+
or symmetric second rank tensors into its components.");
10+
command.SetAuthor("Matthew McCormick");
1211

13-
command.AddField( "inputImage", "Input image.", MetaCommand::STRING, MetaCommand::DATA_IN);
12+
command.AddField("inputImage", "Input image.", MetaCommand::STRING, MetaCommand::DATA_IN);
1413

15-
command.SetOption( "outputPrefix", "o", false, "Output image prefix. Optional." );
16-
command.SetOptionLongTag( "outputPrefix", "output" );
17-
command.AddOptionField( "outputPrefix", "outputPrefix", MetaCommand::STRING, true, "", "", MetaCommand::DATA_OUT );
14+
command.SetOption("outputPrefix", "o", false, "Output image prefix. Optional.");
15+
command.SetOptionLongTag("outputPrefix", "output");
16+
command.AddOptionField("outputPrefix", "outputPrefix", MetaCommand::STRING, true, "", "", MetaCommand::DATA_OUT);
1817

19-
if( !command.Parse( argc, argv ) )
20-
{
21-
if( command.GotXMLFlag() )
22-
throw got_xml_flag_exception( "Passed in --xml" );
18+
if (!command.Parse(argc, argv))
19+
{
20+
if (command.GotXMLFlag())
21+
throw got_xml_flag_exception("Passed in --xml");
2322
else
24-
throw std::logic_error( "Could not parse command line arguments." );
25-
}
23+
throw std::logic_error("Could not parse command line arguments.");
24+
}
2625

27-
if( !command.GetOptionWasSet( "inputImage" ) )
28-
throw std::runtime_error( "Input image not specified." );
29-
this->inputImage = command.GetValueAsString( "inputImage" );
26+
if (!command.GetOptionWasSet("inputImage"))
27+
throw std::runtime_error("Input image not specified.");
28+
this->inputImage = command.GetValueAsString("inputImage");
3029

31-
if( !command.GetOptionWasSet( "outputPrefix" ) )
32-
{
30+
if (!command.GetOptionWasSet("outputPrefix"))
31+
{
3332
// truncate the input extension
3433
std::string fileBase = this->inputImage;
3534
size_t fileBaseLength = fileBase.length();
36-
if ( fileBaseLength > 4 )
35+
if (fileBaseLength > 4)
36+
{
37+
if (!this->inputImage.compare(fileBaseLength - 4, 1, "."))
3738
{
38-
if ( !this->inputImage.compare(fileBaseLength - 4, 1, ".") )
39-
{
4039
fileBase = fileBase.substr(0, fileBaseLength - 4);
41-
}
4240
}
43-
this->outputPrefix = fileBase;
4441
}
42+
this->outputPrefix = fileBase;
43+
}
4544
else
46-
this->outputPrefix = command.GetValueAsString( "outputPrefix", "outputPrefix" );
45+
this->outputPrefix = command.GetValueAsString("outputPrefix", "outputPrefix");
4746
}

Diff for: apps/SplitComponentsArgs.h

+8-6
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ struct Args
1212
std::string inputImage;
1313
std::string outputPrefix;
1414

15-
Args( int argc, char* argv[] );
15+
Args(int argc, char * argv[]);
1616

1717
// Just so we can distinguish it.
18-
class got_xml_flag_exception: public std::logic_error
19-
{
20-
public:
21-
got_xml_flag_exception( const std::string& what ): std::logic_error( what ) {}
22-
};
18+
class got_xml_flag_exception : public std::logic_error
19+
{
20+
public:
21+
got_xml_flag_exception(const std::string & what)
22+
: std::logic_error(what)
23+
{}
24+
};
2325
};
2426

2527
#endif

0 commit comments

Comments
 (0)