Skip to content

Commit

Permalink
improve: added clang format using GHA for code format (opentibiabr#775)
Browse files Browse the repository at this point in the history
This implements the Clang formatter, a linter, to maintain a consistent code style throughout the code base.

In addition to configuring the Clang formatter, a GH Action has been added to automatically run the linter on the code base every time a push or pull request is made and make a commit to apply the format whenever necessary. This way, we can guarantee that the code is always in the same format.

This also allows us to merge faster, as we can simply apply the linter to any open pull request to resolve any conflicts or changes that may occur during the merge.
  • Loading branch information
beats-dh authored Feb 12, 2023
1 parent 4989291 commit ecc0642
Show file tree
Hide file tree
Showing 314 changed files with 14,947 additions and 17,778 deletions.
142 changes: 142 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
---
Language: Cpp
#BasedOnStyle: WebKit
AccessModifierOffset: -4
AlignAfterOpenBracket: BlockIndent
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: false
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
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: false
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: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: AfterColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 0
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DeriveLineEnding: true
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: 3
SortPriority: 0
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 2
SortPriority: 0
- Regex: '.*'
Priority: 1
SortPriority: 0
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: true
IndentGotoLabels: true
IndentPPDirectives: BeforeHash
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: Left
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
Standard: Latest
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseCRLF: false
UseTab: true
IndentAccessModifiers: true
RemoveBracesLLVM: false
#InsertNewlineAtEOF: true
LambdaBodyIndentation: Signature
NamespaceIndentation: All
QualifierAlignment: Left
ReferenceAlignment: Right
MaxEmptyLinesToKeep: 1
42 changes: 42 additions & 0 deletions .github/workflows/clang-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
name: Clang-format
on:
pull_request:
push:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set up Git
if: ${{ github.ref != 'refs/heads/main' }}
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Actions"
- name: Actions checkout
if: ${{ github.ref != 'refs/heads/main' }}
uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Run clang format lint
if: ${{ github.ref != 'refs/heads/main' }}
uses: DoozyX/clang-format-lint-action@v0.15
with:
source: "src"
exclude: "src/protobuf"
extensions: "cpp,hpp,h"
clangFormatVersion: 15
inplace: true

- name: Run add and commit
if: ${{ github.ref != 'refs/heads/main' }}
uses: EndBug/add-and-commit@v9
with:
author_name: GitHub Actions
author_email: github-actions[bot]@users.noreply.github.com
message: "Code format - (Clang-format)"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 4 additions & 4 deletions src/config/config_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* License: https://github.com/opentibiabr/canary/blob/main/LICENSE
* Contributors: https://github.com/opentibiabr/canary/graphs/contributors
* Website: https://docs.opentibiabr.org/
*/
*/

#ifndef SRC_CONFIG_CONFIG_DEFINITIONS_HPP_
#define SRC_CONFIG_CONFIG_DEFINITIONS_HPP_
Expand Down Expand Up @@ -69,7 +69,7 @@ enum booleanConfig_t {
ALLOW_RELOAD,

LAST_BOOLEAN_CONFIG
};
};

enum stringConfig_t {
MAP_NAME,
Expand Down Expand Up @@ -102,7 +102,7 @@ enum stringConfig_t {
FORGE_FIENDISH_INTERVAL_TIME,

LAST_STRING_CONFIG
};
};

enum integerConfig_t {
SQL_PORT,
Expand Down Expand Up @@ -216,4 +216,4 @@ enum floatingConfig_t {
LAST_FLOATING_CONFIG
};

#endif // SRC_CONFIG_CONFIG_DEFINITIONS_HPP_
#endif // SRC_CONFIG_CONFIG_DEFINITIONS_HPP_
Loading

0 comments on commit ecc0642

Please sign in to comment.