Skip to content

Commit

Permalink
Creating clang-check cmake target to check all files in src/test agai…
Browse files Browse the repository at this point in the history
…nst style file. Clang-format cmake target applies the changes needed
  • Loading branch information
HarryMills-UL authored and TheMunro committed Sep 30, 2020
1 parent fb806e8 commit 584ae58
Show file tree
Hide file tree
Showing 4 changed files with 563 additions and 1 deletion.
28 changes: 27 additions & 1 deletion .github/workflows/libelement.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,30 @@ jobs:
-Dsonar.coverageReportPaths="coverage.xml" \
-Dsonar.projectBaseDir="." \
-Dsonar.exclusions=**/dependencies/**/*,**/_deps/**/*,**/build/**/* \
-Dsonar.coverage.exclusions=**/dependencies/**/*,**/_deps/**/*,**/build/**/*
-Dsonar.coverage.exclusions=**/dependencies/**/*,**/_deps/**/*,**/build/**/*
code-analysis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Checkout submodules
shell: bash
run: |
# If your submodules are configured to use SSH instead of HTTPS please uncomment the following line
git config --global url."https://github.com/".insteadOf "[email protected]:"
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
git submodule sync --recursive
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1
- name: Install dependencies
run: |
sudo apt-get install clang-format
- name: Run analysis
run: |
export CC=gcc-9
export CXX=g++-9
cd libelement
mkdir build
cd build
cmake ..
# Run clang-format to see if code matches our style guide, clang-format target can be used to apply changes
cmake --build . --target clang-check
122 changes: 122 additions & 0 deletions libelement/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
#AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
#AllowAllArgumentsOnNextLine: true
#AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
#AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
# AfterCaseLabel: false
AfterClass: true
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
#BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 0
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
#DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^(<|")(rapidtest|gtest|gmock)'
Priority: -1
- Regex: '^<Q[^/]*>'
Priority: 2
- Regex: '^<boost/'
Priority: 3
- Regex: '^<.*>'
Priority: 4
- Regex: '^".*"'
Priority: 1
IncludeIsMainRegex: '(\.test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
#RawStringFormats:
# - Delimiter: pb
# Language: TextProto
# BasedOnStyle: google
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
12 changes: 12 additions & 0 deletions libelement/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,18 @@ if (BUILD_TESTING)
endif()
endif ()

find_program(CLANG_FORMAT clang-format)
if(CLANG_FORMAT)
find_package(Python)
add_custom_target(clang-check
COMMAND ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/scripts/run-clang-format.py -r ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/test
COMMENT "Checking src & test folder against clang format styling.")

add_custom_target(clang-format
COMMAND ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/scripts/run-clang-format.py -i -r ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/test
COMMENT "Formatting src & test folder to match clang format styling.")
endif()

target_compile_definitions(libelement
PRIVATE
${LEGACY_COMPILER}
Expand Down
Loading

0 comments on commit 584ae58

Please sign in to comment.