Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI/CD] Add clang-format workflow #3

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 42 additions & 38 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,93 +1,97 @@
Language: C
Language: Cpp
Standard: Latest

BasedOnStyle: LLVM
IndentWidth: 4
TabWidth: 4
UseTab: Always
ColumnLimit: 120
BreakBeforeBraces: Allman
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakTemplateDeclarations: Yes
IndentCaseLabels: false
IndentCaseLabels: true
IndentCaseBlocks: false
IndentGotoLabels: false
IndentPPDirectives: AfterHash
IndentPPDirectives: None
IndentWrappedFunctionNames: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
Standard: C23
SpacesBeforeTrailingComments: 4
SpaceBeforeSquareBrackets: false
SpacesInParens: Custom
SpacesInParensOptions:
InConditionalStatements: false
InEmptyParentheses: false
InCStyleCasts: false
Other: false
SpacesInSquareBrackets: false

# Additional configurations to match specific rules
AlignConsecutiveMacros: AcrossComments
AlignConsecutiveDeclarations:
Enabled: true
AcrossEmptyLines: false
AlignCompound: true
AcrossComments: true
AlignFunctionPointers: true
AlignAfterOpenBracket: Align
AlignEscapedNewlines: Right
AlignOperands: true
AlignOperands: Align
AlignTrailingComments: true
BinPackArguments: false
BinPackParameters: false
BreakAdjacentStringLiterals: true
BreakAfterAttributes: Always

BinPackArguments: true
BinPackParameters: true
BitFieldColonSpacing: None
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterControlStatement: Always
AfterCaseLabel: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterExternBlock: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: true
BeforeWhile: true
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
Cpp11BracedListStyle: true
BreakBeforeTernaryOperators: false
BreakStringLiterals: false
DerivePointerAlignment: false
FixNamespaceComments: true
PointerAlignment: Left
SpaceAfterLogicalNot: false

# Custom header sorting
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<menix/.*>'
Priority: 2
- Regex: '^".*\.h"'
Priority: 3
SortIncludes: true
SortIncludes: CaseInsensitive

# Comment style
CommentPragmas: '^//.*'
ReflowComments: false
ReflowComments: true

# Typedefs and structs
TypenameMacros: ['typedef', 'struct']
AllowShortEnumsOnASingleLine: false

# Naming conventions
VariableCase: lower_case
FunctionCase: lower_case
TypeCase: PascalCase
MacroCase: UPPER_CASE

# Doxygen style comments
CommentStyle:
Doxygen: true
Slash: true

# Additional formatting options
MaxEmptyLinesToKeep: 1
KeepEmptyLinesAtTheStartOfBlocks: false
InsertTrailingCommas: false
InsertTrailingCommas: None
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
InsertNewlineAtEOF: true
33 changes: 33 additions & 0 deletions .github/workflows/clang-format-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: clang-format Check
on:
pull_request:
types: [opened, review_requested, synchronize]
# Only trigger if C source files have been changed.
paths:
- '**.c'
- '**.h'

jobs:
formatting-check:
name: Formatting Check
runs-on: ubuntu-latest
steps:
# Filter only files changed by the PR.
- name: Filter changed files
id: filter
uses: dorny/paths-filter@v2
with:
filters: |
c_files:
- '**.c'
h_files:
- '**.h'
# Check code.
- uses: actions/checkout@v4
- name: Run clang-format style check for C.
if: steps.filter.outputs.c_files == 'true' || steps.filter.outputs.h_files == 'true'
uses: jidicula/clang-format-action@v4.13.0
with:
clang-format-version: '18'
check-path: 'kernel'
fallback-style: llvm
3 changes: 1 addition & 2 deletions kernel/drv/misc/example/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ static void exit()
printf("bye!\n");
}

MENIX_MODULE_INFO
{
MENIX_MODULE_INFO {
.load = load,
.exit = exit,
};
8 changes: 4 additions & 4 deletions kernel/menix/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
Kernel entry point
----------------*/

#include <menix/stdio.h>
#include <menix/arch.h>
#include <menix/module.h>

#include <menix/config.h>
#include <menix/module.h>
#include <menix/stdio.h>

void kernel_main(void)
{
// Init platform.
arch_init();

printf("menix v" MENIX_VERSION " (" MENIX_ARCH ")" "\n");
printf("menix v" MENIX_VERSION " (" MENIX_ARCH ")"
"\n");

#if CFG_ENABLED(example)
hello_world_say_hello();
Expand Down
Loading