mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Add clang-format v18 workflow and configuration
This commit is contained in:
parent
d17c0297ec
commit
c970fa9bad
145
.clang-format
145
.clang-format
@ -1,57 +1,112 @@
|
|||||||
---
|
---
|
||||||
#------------------------------------
|
BasedOnStyle: LLVM
|
||||||
# Configuration for clang-format v12
|
Standard: Auto # let the formatter accept any C++ standard
|
||||||
#------------------------------------
|
|
||||||
|
|
||||||
Language: Cpp
|
# =============================================================================
|
||||||
|
# Indentation
|
||||||
|
# =============================================================================
|
||||||
|
TabWidth: 2
|
||||||
|
ContinuationIndentWidth: 2
|
||||||
|
ConstructorInitializerIndentWidth: 2
|
||||||
|
NamespaceIndentation: All # everything inside namespace is indented
|
||||||
|
IndentCaseLabels: true # case labels at switch-body indent level
|
||||||
|
IndentCaseBlocks: true # indent block inside case label
|
||||||
|
IndentExternBlock: Indent
|
||||||
|
IndentWrappedFunctionNames: true # keep function name at same indent as return type
|
||||||
|
IndentPPDirectives: BeforeHash # nested #if / #include get indented before the #
|
||||||
|
PPIndentWidth: 2
|
||||||
|
|
||||||
BasedOnStyle: Chromium
|
# =============================================================================
|
||||||
|
# Braces & line-break style
|
||||||
|
# =============================================================================
|
||||||
|
BreakBeforeBraces: Allman
|
||||||
|
BreakConstructorInitializers: BeforeComma # colon on new line, commas lead
|
||||||
|
BreakInheritanceList: BeforeComma
|
||||||
|
BreakBeforeBinaryOperators: NonAssignment
|
||||||
|
BreakStringLiterals: false
|
||||||
|
AlwaysBreakTemplateDeclarations: Yes # template <…> always on its own line
|
||||||
|
|
||||||
SortIncludes: true
|
# =============================================================================
|
||||||
IncludeBlocks: Preserve
|
# Short statements
|
||||||
|
# =============================================================================
|
||||||
|
AllowShortBlocksOnASingleLine: Empty
|
||||||
|
AllowShortFunctionsOnASingleLine: Empty # only empty bodies: void f() {}
|
||||||
|
AllowShortCaseLabelsOnASingleLine: true # case X: stmt; break; on one line
|
||||||
|
AllowShortLoopsOnASingleLine: true
|
||||||
|
AllowShortLambdasOnASingleLine: Inline
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# Empty lines
|
||||||
|
# =============================================================================
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
|
EmptyLineBeforeAccessModifier: Always # blank line before public:/private:/protected:
|
||||||
|
EmptyLineAfterAccessModifier: Always # blank line after public:/private:/protected:
|
||||||
|
InsertNewlineAtEOF: true
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# Spacing
|
||||||
|
# =============================================================================
|
||||||
|
SpacesInAngles: Leave # preserve C++03 "> >" vs C++11 ">>"
|
||||||
|
SpacesInContainerLiterals: false
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# Alignment
|
||||||
|
# =============================================================================
|
||||||
|
PointerAlignment: Left # T* ptr, const T& ref
|
||||||
|
ReferenceAlignment: Left
|
||||||
|
AlignConsecutiveAssignments: true
|
||||||
|
AlignConsecutiveDeclarations: true
|
||||||
|
AlignConsecutiveBitFields: true
|
||||||
|
AlignConsecutiveMacros: true # align macro bodies
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# Line length and wrapping
|
||||||
|
# =============================================================================
|
||||||
|
ColumnLimit: 0
|
||||||
|
ReflowComments: true # preserve hand-formatted comment rulers
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# Includes
|
||||||
|
# =============================================================================
|
||||||
IncludeCategories:
|
IncludeCategories:
|
||||||
- Regex: '^(<|")(.*/)?platform\.h(>|")$'
|
- Regex: '^(<|")(.*/)?platform\.h(>|")$'
|
||||||
Priority: 1
|
Priority: -1
|
||||||
- Regex: '.*'
|
# everything else gets the default priority (0)
|
||||||
Priority: 2
|
|
||||||
|
|
||||||
BinPackParameters: false
|
# =============================================================================
|
||||||
BitFieldColonSpacing: Both
|
# Arguments, parameters and constructor initialisers
|
||||||
|
# =============================================================================
|
||||||
|
PackConstructorInitializers: Never # each initialiser on its own line
|
||||||
|
|
||||||
BreakBeforeBraces: Allman
|
# =============================================================================
|
||||||
BreakConstructorInitializers: BeforeComma
|
# Namespaces and using declarations
|
||||||
|
# =============================================================================
|
||||||
|
SortUsingDeclarations: Lexicographic
|
||||||
|
|
||||||
AllowShortBlocksOnASingleLine: false
|
# =============================================================================
|
||||||
AllowShortCaseLabelsOnASingleLine: true
|
# Macro-aware formatting
|
||||||
AllowShortFunctionsOnASingleLine: None
|
# =============================================================================
|
||||||
AllowShortIfStatementsOnASingleLine: false
|
# ETL-specific macros that should be treated as statement-level constructs
|
||||||
|
StatementMacros:
|
||||||
|
- ETL_DECLARE_DEBUG_COUNT
|
||||||
|
- ETL_INCREMENT_DEBUG_COUNT
|
||||||
|
- ETL_DECREMENT_DEBUG_COUNT
|
||||||
|
- ETL_ADD_DEBUG_COUNT
|
||||||
|
- ETL_STATIC_ASSERT
|
||||||
|
|
||||||
AllowAllArgumentsOnNextLine: true
|
# Macros that behave like attributes or specifiers.
|
||||||
AllowAllParametersOfDeclarationOnNextLine: true
|
AttributeMacros:
|
||||||
|
- ETL_NODISCARD
|
||||||
|
- ETL_NORETURN
|
||||||
|
- ETL_DEPRECATED
|
||||||
|
|
||||||
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
|
# Macros that behave like type names
|
||||||
ConstructorInitializerIndentWidth: '2'
|
TypenameMacros:
|
||||||
|
- ETL_OR_STD
|
||||||
|
|
||||||
NamespaceIndentation: All
|
# Do not reformat these macros — they contain DSL-like content
|
||||||
IndentPPDirectives: BeforeHash
|
WhitespaceSensitiveMacros:
|
||||||
PointerAlignment: Left
|
- ETL_ERROR_TEXT
|
||||||
ColumnLimit: '0'
|
- ETL_DECLARE_ENUM_TYPE
|
||||||
ContinuationIndentWidth: '2'
|
- ETL_ENUM_TYPE
|
||||||
UseTab: Never
|
- ETL_END_ENUM_TYPE
|
||||||
TabWidth: '2'
|
|
||||||
IndentWidth: '2'
|
|
||||||
AccessModifierOffset : '-2'
|
|
||||||
IndentCaseLabels: false
|
|
||||||
Cpp11BracedListStyle: 'true'
|
|
||||||
AlignAfterOpenBracket: Align
|
|
||||||
AlignConsecutiveDeclarations: true
|
|
||||||
|
|
||||||
#------------------------------------
|
|
||||||
# Configurations not supported by clang-format v12
|
|
||||||
#------------------------------------
|
|
||||||
# BreakInheritanceList: AfterComma
|
|
||||||
# EmptyLineBeforeAccessModifier: Always
|
|
||||||
# EmptyLineAfterAccessModifier: Always
|
|
||||||
# ReferenceAlignment: Left
|
|
||||||
|
|
||||||
...
|
|
||||||
|
|||||||
42
.github/workflows/clang-format.yaml
vendored
Normal file
42
.github/workflows/clang-format.yaml
vendored
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
name: clang-format
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master, development, pull-request/* ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ master, development, pull-request/* ]
|
||||||
|
types: [opened, synchronize, reopened]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
clang-format:
|
||||||
|
name: clang-format
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Install clang-format and git
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y --no-install-recommends git clang-format
|
||||||
|
clang-format --version
|
||||||
|
|
||||||
|
- name: Run clang-format on added/changed files
|
||||||
|
run: |
|
||||||
|
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
||||||
|
BEFORE="origin/${{ github.base_ref }}"
|
||||||
|
elif [ "${{ github.event_name }}" = "push" ]; then
|
||||||
|
BEFORE="${{ github.event.before }}"
|
||||||
|
else
|
||||||
|
echo "Unsupported event: ${{ github.event_name }}"
|
||||||
|
echo "This is likely a bug in the workflow configuration. Please report it to the maintainers."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
git diff --name-only -z --diff-filter=AMCR "$BEFORE"..HEAD -- \
|
||||||
|
'*.c' '*.cc' '*.cxx' '*.cpp' \
|
||||||
|
'*.h' '*.hh' '*.hpp' '*.hxx' \
|
||||||
|
'*.ipp' '*.inl' \
|
||||||
|
':(exclude)include/etl/generators/*' \
|
||||||
|
| xargs -0 --no-run-if-empty clang-format --Werror -n --style=file
|
||||||
Loading…
x
Reference in New Issue
Block a user