Skip to content

Commit

Permalink
Add tidy and format to make rules
Browse files Browse the repository at this point in the history
 # Problem
 clang-tidy and clang-format are not part of developer workflow

 # Changes
 * add clang-tidy and clang-format to rules for C files in the tree
 * allow overriding tidy and format for subtrees
 * tidy up the clang-tidy github integration

 fixes #2
  • Loading branch information
Rob Walker committed Mar 12, 2020
1 parent 34e2b26 commit b20f862
Show file tree
Hide file tree
Showing 46 changed files with 2,662 additions and 1,996 deletions.
230 changes: 228 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,7 +1,233 @@
---
Language: Cpp
BasedOnStyle: WebKit
# BasedOnStyle: WebKit
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: false
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: AfterColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 132
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeCategories:
- Regex: '^<Weave/Core.*'
Priority: 0
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
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: Middle
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
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
---
Language: ObjC
BasedOnStyle: WebKit
# BasedOnStyle: WebKit
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: false
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: All
BreakBeforeBraces: WebKit
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 132
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Middle
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseTab: Never
...
2 changes: 1 addition & 1 deletion .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Tidy
on: [pull_request]

jobs:
build:
clang-tidy:
runs-on: ubuntu-latest

steps:
Expand Down
33 changes: 32 additions & 1 deletion .yams/cpp_rules.min
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

_@=@
Common_C_Flags = -DHAVE_CONFIG_H -g -O2

Expand Down Expand Up @@ -26,27 +27,47 @@ endif

CLANG_FORMAT := $(shell command -v clang-format 2> /dev/null)
ifdef CLANG_FORMAT
CLANG_FORMAT += -style=Chromium -i
CLANG_FORMAT += -i
endif

CLANG_TIDY := $(shell command -v clang-tidy 2> /dev/null)
ifdef CLANG_TIDY
CLANG_TIDY += -checks=-*,clang-analyzer-*,-clang-analyzer-cplusplus*
endif

GCOV := $(shell command -v gcov 2> /dev/null)

ifdef GCOV
GCOV_FLAGS=-fprofile-arcs -ftest-coverage
endif

# search up in the tree from where the makefile lives for overrides, other definitions
__updirs=$(if $1,$(if $2,$(if $(subst /,,$(abspath $2)),$(or $(wildcard $2$1),$(call __updirs,$1,$2../))),$(call __updirs,$1,./)))
-include $(call __updirs,.yams.min)

%.o: %.c
ifdef CLANG_FORMAT
$(_@)$(CLANG_FORMAT) $<
endif
$(_@)$(CC) $(Module_C_Flags) -c $< -o $@
ifdef CPPCHECK
$(_@)$(CPPCHECK) $(Module_Includes) $<
endif
ifdef CLANG_TIDY
$(_@)$(CLANG_TIDY) $< -- $(Module_C_Flags)
endif
@echo "CC <= $<"

%.o: %.cpp
ifdef CLANG_FORMAT
$(_@)$(CLANG_FORMAT) $<
endif
$(_@)$(CXX) $(Module_C_Flags) -c $< -o $@
ifdef CPPCHECK
$(_@)$(CPPCHECK) $(Module_Includes) $<
endif
ifdef CLANG_TIDY
$(_@)$(CLANG_TIDY) $< -- $(Module_C_Flags)
endif
@echo "CXX <= $<"

Expand All @@ -57,6 +78,9 @@ endif
$(_@)$(CC) $< -o $@ $(Module_Test_C_Flags) -L/usr/local/lib $($(*F)_FLAGS) $(GCOV_FLAGS)
ifdef CPPCHECK
$(_@)$(CPPCHECK) $(Module_Test_Includes) $($(*F)_Inc_FLAGS) $<
endif
ifdef CLANG_TIDY
$(_@)$(CLANG_TIDY) $< -- $(Module_Test_C_Flags)
endif
@echo "Building tests <= $<"

Expand All @@ -67,6 +91,9 @@ endif
$(_@)$(CXX) $< -o $@ $(Module_Test_C_Flags) -L/usr/local/lib $($(*F)_FLAGS) $(GCOV_FLAGS)
ifdef CPPCHECK
$(_@)$(CPPCHECK) $(Module_Test_Includes) $($(*F)_Inc_FLAGS) $<
endif
ifdef CLANG_TIDY
$(_@)$(CLANG_TIDY) $< -- $(Module_Test_C_Flags)
endif
@echo "Building tests <= $<"

Expand All @@ -86,3 +113,7 @@ my_clean:
$(_@)rm -f $(Tests_C_Exe) $(Tests_CPP_Exe) $(Test_Dir)/*.gcda $(Test_Dir)/*.gcno $(Test_Dir)/*.gcov
$(_@)rm -rf $(Test_Dir)/*.dSYM

.PHONY: _DEBUG_%
_DEBUG_%:
@echo $*='"$($(*))"'

2 changes: 1 addition & 1 deletion integrations/github/actions/clang-tidy/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "Clang Pull Request Tidy"
description: "clang-lint"
description: "clang-tidy"
inputs:
files_added:
description: "JSON list of files added"
Expand Down
27 changes: 27 additions & 0 deletions src/.yams.min
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

VALGRIND := $(shell command -v valgrind 2> /dev/null)

ifdef VALGRIND
VALGRIND += --leak-check=yes -q
endif

CPPCHECK := $(shell command -v cppcheck 2> /dev/null)
ifdef CPPCHECK
CPPCHECK += -q --error-exitcode=1
endif

CLANG_FORMAT := $(shell command -v clang-format 2> /dev/null)
ifdef CLANG_FORMAT
CLANG_FORMAT += -i
endif

CLANG_TIDY := $(shell command -v clang-tidy 2> /dev/null)
ifdef CLANG_TIDY
CLANG_TIDY += -checks=-*,clang-analyzer-*,-clang-analyzer-cplusplus*
endif

GCOV := $(shell command -v gcov 2> /dev/null)

ifdef GCOV
GCOV_FLAGS=-fprofile-arcs -ftest-coverage
endif
Loading

0 comments on commit b20f862

Please sign in to comment.