Skip to content

Commit

Permalink
Move clang-format to the root directory
Browse files Browse the repository at this point in the history
  • Loading branch information
mikir committed Jan 5, 2024
1 parent 5789aff commit d3cf6c2
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 88 deletions.
235 changes: 235 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
---
# Access modifier should be aligned to braces.
AccessModifierOffset: -4

# Align pointer to the left (to the type).
PointerAlignment: Left

# The column limit for Zserio.
ColumnLimit: 112

# Always break after template declaration.
AlwaysBreakTemplateDeclarations: Yes

# Indent width for line continuations.
ContinuationIndentWidth: 8

# Settings for constructor initializers.
BreakConstructorInitializers: AfterColon
ConstructorInitializerIndentWidth: 8
PackConstructorInitializers: Never

# Don’t align, instead use ContinuationIndentWidth.
AlignAfterOpenBracket: DontAlign

# Don't align trailing comments.
AlignTrailingComments: false

# Don't align operands.
AlignOperands: DontAlign

# Indent preprocessor directives.
IndentPPDirectives: BeforeHash

# Improve indentation of chained method calls.
PenaltyIndentedWhitespace: 10

# Allow brace wrapping for unions .
# Allow empty braces on the same line for functions, records and namespaces.
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: Always
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false

# Indent case blocks.
IndentCaseBlocks: true

# All other defaults from Microsoft style.
AlignArrayOfStructures: None
AlignConsecutiveMacros: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Right
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AttributeMacros:
- __capability
BinPackArguments: true
BinPackParameters: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
CommentPragmas: '^ IWYU pragma:'
QualifierAlignment: Leave
CompactNamespaces: false
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
BasedOnStyle: ''
ConstructorInitializerAllOnOneLineOrOnePerLine: false
AllowAllConstructorInitializersOnNextLine: true
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseLabels: false
IndentGotoLabels: true
IndentExternBlock: AfterExternBlock
IndentRequires: false
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 1000
PPIndentWidth: -1
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterOverloadedOperator: false
BeforeNonEmptyParentheses: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
---
# C++ specific rules
Language: Cpp

# Regroup and sort includes.
IncludeBlocks: Regroup
IncludeCategories:
# System headers in <>.
- Regex: '<.*>'
Priority: -2
CaseSensitive: false
# Headers in "" in current directory.
- Regex: '"[^/\]+"'
Priority: 0
CaseSensitive: false
# Headers in "" in different directory.
- Regex: '".*"'
Priority: -1
CaseSensitive: false
# All other headers.
- Regex: '.*'
Priority: 1
CaseSensitive: false
---
# Java specific rules
Language: Java

# Set Java import groups.
JavaImportGroups: ['java', 'org', 'zserio', 'test_object']

# Break after Java annotations.
BreakAfterJavaFieldAnnotations: true
...
5 changes: 3 additions & 2 deletions .github/workflows/build_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ jobs:
run: |
sudo apt-get install clang-${{matrix.clang-version}}
sudo apt-get install llvm-${{matrix.clang-version}}
if [ -f "`which clang-format-14`" ] ; then
echo "CLANG_FORMAT_BIN=clang-format-14" >> ${GITHUB_ENV}
fi
- name: Install dependencies
run: sudo apt-get install cmake doxygen graphviz g++-multilib
Expand Down Expand Up @@ -126,7 +129,6 @@ jobs:
run: |
if [ -f "`which clang-tidy-14`" ] ; then
export CLANG_TIDY_BIN=clang-tidy-14
export CLANG_FORMAT_BIN=clang-format-14
fi
# gcovr works only for default gcc version
if [[ `gcc --version` == *" ${{matrix.gcc-version}}."* ]] ; then
Expand Down Expand Up @@ -155,7 +157,6 @@ jobs:
run: |
if [ -f "`which clang-tidy-14`" ] ; then
export CLANG_TIDY_BIN=clang-tidy-14
export CLANG_FORMAT_BIN=clang-format-14
fi
scripts/test.sh cpp-linux32-gcc cpp-linux64-gcc cpp-linux64-clang
env:
Expand Down
2 changes: 1 addition & 1 deletion cmake/clang_format_tool.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ execute_process(
if (NOT ${CLANG_FORMAT_RESULT} EQUAL 0)
message(NOTICE "Command hints to reformat source using clang-format tool:")
message(NOTICE " git clang-format")
message(NOTICE " clang-format --style=file -i ${SOURCE}")
message(NOTICE " clang-format --style=file:${CONFIG_FILE} -i ${SOURCE}")
message(FATAL_ERROR "Clang Format Tool failed!")
endif ()
2 changes: 1 addition & 1 deletion cmake/clang_format_utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function(clang_format_add_custom_target CLANG_FORMAT_TARGET)
-DWERROR="${CLANG_FORMAT_WERROR}"
-P ${CMAKE_MODULE_PATH}/clang_format_tool.cmake
COMMAND "${CMAKE_COMMAND}" -E touch "${CLANG_FORMAT_FILE_STAMP}"
DEPENDS ${SOURCE_FILE}
DEPENDS ${SOURCE_FILE} ${CLANG_FORMAT_CONFIG_FILE}
COMMENT "Running clang-format on ${SOURCE_FILE}")
list(APPEND CLANG_FORMAT_FILE_STAMPS "${CLANG_FORMAT_FILE_STAMP}")
math(EXPR INDEX "${INDEX} + 1")
Expand Down
76 changes: 0 additions & 76 deletions compiler/extensions/cpp/runtime/.clang-format

This file was deleted.

2 changes: 1 addition & 1 deletion compiler/extensions/cpp/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ clang_format_add_custom_target(ZserioCppRuntime-clang-format
"${CMAKE_CURRENT_SOURCE_DIR}/src/zserio/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/test/zserio/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/test/zserio/*.h"
CONFIG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/.clang-format"
CONFIG_FILE "${ZSERIO_PROJECT_ROOT}/.clang-format"
WERROR ON)

# add cppcheck custom command
Expand Down
Loading

0 comments on commit d3cf6c2

Please sign in to comment.