Skip to content

Commit 40fa4b0

Browse files
authored
Merge pull request #19 from jhoff/formatting_weirdness
Adjust formatting, apply, introduce github action
2 parents 6bdccb0 + d8ef4dd commit 40fa4b0

16 files changed

+1230
-1310
lines changed

.clang-format

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
---
22
Language: Cpp
33
AccessModifierOffset: -2
4-
AlignAfterOpenBracket: Align
4+
AlignAfterOpenBracket: BlockIndent
5+
BracedInitializerIndentWidth: 4
56
AlignArrayOfStructures: None
67
AlignConsecutiveAssignments:
78
Enabled: false
@@ -65,29 +66,28 @@ AlignConsecutiveTableGenDefinitionColons:
6566
AlignFunctionDeclarations: false
6667
AlignFunctionPointers: false
6768
PadOperators: false
68-
AlignEscapedNewlines: Right
69-
AlignOperands: Align
69+
AlignEscapedNewlines: Left
70+
AlignOperands: DontAlign
7071
AlignTrailingComments:
71-
Kind: Always
72-
OverEmptyLines: 0
72+
Kind: Always
73+
OverEmptyLines: 2
7374
AllowAllArgumentsOnNextLine: true
7475
AllowAllParametersOfDeclarationOnNextLine: true
75-
AllowBreakBeforeNoexceptSpecifier: Never
76-
AllowShortBlocksOnASingleLine: Never
76+
AllowBreakBeforeNoexceptSpecifier: Always
77+
AllowShortBlocksOnASingleLine: Empty
7778
AllowShortCaseExpressionOnASingleLine: true
78-
AllowShortCaseLabelsOnASingleLine: false
79+
AllowShortCaseLabelsOnASingleLine: true
7980
AllowShortCompoundRequirementOnASingleLine: true
80-
AllowShortEnumsOnASingleLine: true
81-
AllowShortFunctionsOnASingleLine: All
82-
AllowShortIfStatementsOnASingleLine: Never
81+
AllowShortEnumsOnASingleLine: false
82+
AllowShortFunctionsOnASingleLine: Inline
83+
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
8384
AllowShortLambdasOnASingleLine: All
84-
AllowShortLoopsOnASingleLine: false
85+
AllowShortLoopsOnASingleLine: true
8586
AllowShortNamespacesOnASingleLine: false
86-
AlwaysBreakAfterDefinitionReturnType: None
8787
AlwaysBreakBeforeMultilineStrings: false
8888
AttributeMacros:
8989
- __capability
90-
BinPackArguments: true
90+
BinPackArguments: false
9191
BinPackParameters: BinPack
9292
BitFieldColonSpacing: Both
9393
BraceWrapping:
@@ -99,7 +99,7 @@ BraceWrapping:
9999
AfterFunction: false
100100
AfterNamespace: false
101101
AfterObjCDeclaration: false
102-
AfterStruct: false
102+
AfterStruct: true
103103
AfterUnion: false
104104
BeforeCatch: false
105105
BeforeElse: false
@@ -109,23 +109,23 @@ BraceWrapping:
109109
SplitEmptyFunction: true
110110
SplitEmptyRecord: true
111111
SplitEmptyNamespace: true
112-
BreakAdjacentStringLiterals: true
112+
BreakAdjacentStringLiterals: false
113113
BreakAfterAttributes: Leave
114114
BreakAfterJavaFieldAnnotations: false
115-
BreakAfterReturnType: None
116-
BreakArrays: true
115+
BreakAfterReturnType: Automatic
116+
BreakArrays: false
117117
BreakBeforeBinaryOperators: None
118118
BreakBeforeConceptDeclarations: Always
119-
BreakBeforeBraces: Attach
119+
BreakBeforeBraces: Custom
120120
BreakBeforeInlineASMColon: OnlyMultiline
121121
BreakBeforeTernaryOperators: true
122122
BreakBinaryOperations: Never
123123
BreakConstructorInitializers: BeforeColon
124124
BreakFunctionDefinitionParameters: false
125125
BreakInheritanceList: BeforeColon
126-
BreakStringLiterals: true
126+
BreakStringLiterals: false
127127
BreakTemplateDeclarations: MultiLine
128-
ColumnLimit: 80
128+
ColumnLimit: 120
129129
CommentPragmas: '^ IWYU pragma:'
130130
CompactNamespaces: false
131131
ConstructorInitializerIndentWidth: 4
@@ -143,7 +143,7 @@ ForEachMacros:
143143
- BOOST_FOREACH
144144
IfMacros:
145145
- KJ_IF_MAYBE
146-
IncludeBlocks: Preserve
146+
IncludeBlocks: Regroup
147147
IncludeCategories:
148148
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
149149
Priority: 2
@@ -161,16 +161,16 @@ IncludeIsMainRegex: '(Test)?$'
161161
IncludeIsMainSourceRegex: ''
162162
IndentAccessModifiers: false
163163
IndentCaseBlocks: false
164-
IndentCaseLabels: false
164+
IndentCaseLabels: true
165165
IndentExportBlock: true
166166
IndentExternBlock: AfterExternBlock
167167
IndentGotoLabels: true
168168
IndentPPDirectives: None
169169
IndentRequiresClause: true
170-
IndentWidth: 2
170+
IndentWidth: 4
171171
IndentWrappedFunctionNames: false
172172
InsertBraces: false
173-
InsertNewlineAtEOF: false
173+
InsertNewlineAtEOF: true
174174
InsertTrailingCommas: None
175175
IntegerLiteralSeparator:
176176
Binary: 0
@@ -183,10 +183,10 @@ JavaScriptQuotes: Leave
183183
JavaScriptWrapImports: true
184184
KeepEmptyLines:
185185
AtEndOfFile: false
186-
AtStartOfBlock: true
187-
AtStartOfFile: true
186+
AtStartOfBlock: false
187+
AtStartOfFile: false
188188
KeepFormFeed: false
189-
LambdaBodyIndentation: Signature
189+
LambdaBodyIndentation: OuterScope
190190
LineEnding: DeriveLF
191191
MacroBlockBegin: ''
192192
MacroBlockEnd: ''
@@ -217,7 +217,7 @@ QualifierAlignment: Leave
217217
ReferenceAlignment: Pointer
218218
ReflowComments: Always
219219
RemoveBracesLLVM: false
220-
RemoveEmptyLinesInUnwrappedLines: false
220+
RemoveEmptyLinesInUnwrappedLines: true
221221
RemoveParentheses: Leave
222222
RemoveSemicolon: false
223223
RequiresClausePosition: OwnLine
@@ -228,8 +228,8 @@ SkipMacroDefinitionBody: false
228228
SortIncludes: CaseSensitive
229229
SortJavaStaticImport: Before
230230
SortUsingDeclarations: LexicographicNumeric
231-
SpaceAfterCStyleCast: false
232-
SpaceAfterLogicalNot: false
231+
SpaceAfterCStyleCast: true
232+
SpaceAfterLogicalNot: true
233233
SpaceAfterTemplateKeyword: true
234234
SpaceAroundPointerQualifiers: Default
235235
SpaceBeforeAssignmentOperators: true
@@ -255,7 +255,7 @@ SpaceBeforeSquareBrackets: false
255255
SpaceInEmptyBlock: false
256256
SpacesBeforeTrailingComments: 1
257257
SpacesInAngles: Never
258-
SpacesInContainerLiterals: true
258+
SpacesInContainerLiterals: false
259259
SpacesInLineCommentPrefix:
260260
Minimum: 1
261261
Maximum: -1
@@ -274,7 +274,7 @@ StatementMacros:
274274
- Q_UNUSED
275275
- QT_REQUIRE_VERSION
276276
TableGenBreakInsideDAGArg: DontBreak
277-
TabWidth: 8
277+
TabWidth: 4
278278
UseTab: Never
279279
VerilogBreakBetweenInstancePorts: true
280280
WhitespaceSensitiveMacros:
@@ -285,4 +285,3 @@ WhitespaceSensitiveMacros:
285285
- STRINGIZE
286286
WrapNamespaceBodyWithEmptyLines: Leave
287287
...
288-

.github/workflows/format-check.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Format Check
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
format-check:
11+
name: Check Code Formatting
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v3
17+
18+
- name: Setup Node
19+
uses: actions/setup-node@v4
20+
21+
- name: Install Dependencies
22+
run: npm ci
23+
24+
- name: Install Clang Format
25+
uses: jidicula/[email protected]
26+
with:
27+
clang-format-version: '20'
28+
check-path: 'src'
29+
30+
- name: Run Prettier
31+
run: ./node_modules/.bin/prettier --check 'src/**/*.{js,json,css,html}' platformio.ini package.json README.md vite.config.mjs tailwind.config.js

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"scripts": {
55
"build": "npm run format && npm run assets && npm run pio",
66
"format": "npm run format:cpp && npm run format:web",
7-
"format:web": "prettier --write 'src/**/*.{js,json,css,html}' platformio.ini package.json readme.md vite.config.mjs tailwind.config.js",
8-
"format:cpp": "command -v dlang-format >/dev/null 2>&1 && find src -iname '*.h' -o -iname '*.cpp' | xargs clang-format -i || echo 'clang-format not found, skipping format:cpp'",
7+
"format:web": "prettier --write 'src/**/*.{js,json,css,html}' platformio.ini package.json README.md vite.config.mjs tailwind.config.js",
8+
"format:cpp": "command -v clang-format >/dev/null 2>&1 && find src -iname '*.h' -o -iname '*.cpp' -o -iname '*.ino' | xargs clang-format -i || echo 'clang-format not found, skipping format:cpp'",
99
"assets": "vite build --emptyOutDir",
1010
"pio": "npm run pio:firmware && sleep 2 && npm run pio:filesystem",
1111
"pio:firmware": "pio run -t upload",

src/JsonSetting.cpp

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
11
#include "JsonSetting.h"
22

33
String JsonSetting::intVectorToString(const std::vector<int> &vec) {
4-
String result;
5-
for (size_t i = 0; i < vec.size(); ++i) {
6-
result += String(vec[i]);
7-
if (i < vec.size() - 1) {
8-
result += ",";
4+
String result;
5+
for (size_t i = 0; i < vec.size(); ++i) {
6+
result += String(vec[i]);
7+
if (i < vec.size() - 1) {
8+
result += ",";
9+
}
910
}
10-
}
11-
return result;
11+
return result;
1212
}
1313

1414
bool JsonSetting::validate(String str) {
15-
switch (type) {
16-
case JsonSettingType::JST_INT_VECTOR:
17-
return validateIntVector(str);
18-
default:
19-
return true;
20-
}
15+
switch (type) {
16+
case JsonSettingType::JST_INT_VECTOR: return validateIntVector(str);
17+
default: return true;
18+
}
2119
}
2220

2321
bool JsonSetting::validateIntVector(String str) {
24-
for (size_t i = 0; i < str.length(); ++i) {
25-
if (str[i] == ',' || str[i] == '-') {
26-
continue;
22+
for (size_t i = 0; i < str.length(); ++i) {
23+
if (str[i] == ',' || str[i] == '-') {
24+
continue;
25+
}
26+
if (str[i] < '0' || str[i] > '9') {
27+
lastValidationError = "Non-integer value found";
28+
return false;
29+
}
2730
}
28-
if (str[i] < '0' || str[i] > '9') {
29-
lastValidationError = "Non-integer value found";
30-
return false;
31-
}
32-
}
33-
return true;
31+
return true;
3432
}

src/JsonSetting.h

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,42 @@
1-
#ifndef JsonSetting_h
2-
#define JsonSetting_h
1+
#pragma once
32

4-
#include "JsonSetting.h"
53
#include <Preferences.h>
64
#include <vector>
75

8-
typedef enum { JST_STR, JST_INT, JST_FLOAT, JST_INT_VECTOR } JsonSettingType;
6+
typedef enum {
7+
JST_STR,
8+
JST_INT,
9+
JST_FLOAT,
10+
JST_INT_VECTOR
11+
} JsonSettingType;
912

1013
class JsonSetting {
11-
public:
12-
JsonSetting(String strDefault)
13-
: type(JsonSettingType::JST_STR), strDefault(strDefault) {}
14-
JsonSetting(int intDefault)
15-
: type(JsonSettingType::JST_INT), intDefault(intDefault) {}
16-
JsonSetting(float floatDefault)
17-
: type(JsonSettingType::JST_FLOAT), floatDefault(floatDefault) {
18-
strDefault = String(floatDefault);
19-
}
20-
JsonSetting(std::vector<int> intVectorDefault)
21-
: type(JsonSettingType::JST_INT_VECTOR),
22-
intVectorDefault(intVectorDefault) {
23-
strDefault = intVectorToString(intVectorDefault);
24-
}
25-
26-
bool validate(String str);
27-
String getLastValidationError() { return lastValidationError; }
28-
29-
private:
30-
JsonSettingType type;
31-
32-
String strDefault;
33-
int intDefault;
34-
float floatDefault;
35-
std::vector<int> intVectorDefault;
36-
37-
String intVectorToString(const std::vector<int> &vec);
38-
39-
String lastValidationError;
40-
bool validateIntVector(String str);
41-
42-
friend class JsonSettings;
14+
public:
15+
JsonSetting(String strDefault) : type(JsonSettingType::JST_STR), strDefault(strDefault) {}
16+
JsonSetting(int intDefault) : type(JsonSettingType::JST_INT), intDefault(intDefault) {}
17+
JsonSetting(float floatDefault) : type(JsonSettingType::JST_FLOAT), floatDefault(floatDefault) {
18+
strDefault = String(floatDefault);
19+
}
20+
JsonSetting(std::vector<int> intVectorDefault)
21+
: type(JsonSettingType::JST_INT_VECTOR), intVectorDefault(intVectorDefault) {
22+
strDefault = intVectorToString(intVectorDefault);
23+
}
24+
25+
bool validate(String str);
26+
String getLastValidationError() { return lastValidationError; }
27+
28+
private:
29+
JsonSettingType type;
30+
31+
String strDefault;
32+
int intDefault;
33+
float floatDefault;
34+
std::vector<int> intVectorDefault;
35+
36+
String intVectorToString(const std::vector<int> &vec);
37+
38+
String lastValidationError;
39+
bool validateIntVector(String str);
40+
41+
friend class JsonSettings;
4342
};
44-
45-
#endif

0 commit comments

Comments
 (0)