Skip to content

Commit e9077f1

Browse files
committed
Update formatting setup
1 parent b2c54fe commit e9077f1

File tree

3 files changed

+86
-5
lines changed

3 files changed

+86
-5
lines changed

.clang-format

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,75 @@
11
---
2-
BasedOnStyle: LLVM
2+
# Explicitly define all formatting options to ensure consistency across clang-format versions
33
Language: Cpp
4+
# Don't base on any style to avoid version-specific behaviors
5+
# BasedOnStyle: LLVM
46

7+
# Indentation
58
UseTab: Never
69
IndentWidth: 2
10+
TabWidth: 2
11+
BreakBeforeBraces: Attach
12+
IndentCaseLabels: false
13+
NamespaceIndentation: None
14+
ContinuationIndentWidth: 2
15+
IndentPPDirectives: None
16+
IndentWrappedFunctionNames: false
17+
AccessModifierOffset: -2
18+
19+
# Alignment
20+
AlignAfterOpenBracket: DontAlign
21+
AlignConsecutiveAssignments: false
22+
AlignConsecutiveDeclarations: false
23+
AlignConsecutiveMacros: false
24+
AlignEscapedNewlines: Left
25+
AlignOperands: false
26+
AlignTrailingComments: true
27+
DerivePointerAlignment: false
28+
PointerAlignment: Right
29+
30+
# Wrapping and Breaking
731
ColumnLimit: 0
8-
SortIncludes: Never
32+
AllowAllParametersOfDeclarationOnNextLine: false
33+
AllowShortBlocksOnASingleLine: Never
34+
AllowShortCaseLabelsOnASingleLine: false
35+
AllowShortFunctionsOnASingleLine: All
36+
AllowShortIfStatementsOnASingleLine: Always
37+
AllowShortLoopsOnASingleLine: false
38+
AlwaysBreakAfterReturnType: None
39+
AlwaysBreakBeforeMultilineStrings: false
40+
AlwaysBreakTemplateDeclarations: No
41+
BinPackArguments: false
42+
BinPackParameters: false
43+
BreakBeforeBinaryOperators: None
44+
BreakBeforeTernaryOperators: false
45+
BreakConstructorInitializers: BeforeColon
46+
BreakInheritanceList: BeforeColon
47+
BreakStringLiterals: false
48+
CompactNamespaces: false
49+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
950
Cpp11BracedListStyle: false
51+
ReflowComments: false
52+
SortIncludes: Never
53+
54+
# The one rule we want to enable
1055
SpaceAfterCStyleCast: true
11-
AllowShortIfStatementsOnASingleLine: Always
56+
57+
# Other Spaces
58+
SpaceAfterLogicalNot: false
59+
SpaceAfterTemplateKeyword: true
60+
SpaceBeforeAssignmentOperators: true
61+
SpaceBeforeCpp11BracedList: true
62+
SpaceBeforeCtorInitializerColon: true
63+
SpaceBeforeInheritanceColon: true
64+
SpaceBeforeParens: ControlStatements
65+
SpaceBeforeRangeBasedForLoopColon: true
66+
SpaceBeforeSquareBrackets: false
67+
SpaceInEmptyBlock: false
68+
SpaceInEmptyParentheses: false
69+
SpacesBeforeTrailingComments: 1
70+
SpacesInAngles: false
71+
SpacesInCStyleCastParentheses: false
72+
SpacesInConditionalStatement: false
73+
SpacesInContainerLiterals: true
74+
SpacesInParentheses: false
75+
SpacesInSquareBrackets: false

.github/workflows/clang-format.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ jobs:
3030
- name: Install dependencies
3131
run: |
3232
sudo apt-get update
33-
sudo apt-get install -y libdb-dev curl autoconf automake m4 libtool clang-format
33+
sudo apt-get install -y libdb-dev curl autoconf automake m4 libtool
34+
- name: Install clang-format from LLVM
35+
run: |
36+
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
37+
sudo apt-add-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy main"
38+
sudo apt-get update
39+
sudo apt-get install -y clang-format
40+
clang-format --version
3441
- name: Install Re2c
3542
run: |
3643
cd /tmp
@@ -50,5 +57,6 @@ jobs:
5057
bin/setup
5158
- name: Check C code formatting
5259
run: |
60+
clang-format --version
5361
bundle exec rake templates
5462
bundle exec rake format:c_check

Rakefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,17 @@ namespace :format do
106106

107107
needs_format = false
108108
files.each do |file|
109-
unless system("clang-format --dry-run -Werror -style=file #{file} >/dev/null 2>&1")
109+
formatted = `clang-format -style=file #{file}`
110+
original = File.read(file)
111+
112+
if formatted != original
110113
puts "❌ #{file} needs formatting"
114+
puts "Diff:"
115+
# Save formatted version to temp file and run diff
116+
temp_file = "#{file}.formatted"
117+
File.write(temp_file, formatted)
118+
system("diff -u #{file} #{temp_file}")
119+
File.unlink(temp_file)
111120
needs_format = true
112121
end
113122
end

0 commit comments

Comments
 (0)