Skip to content
This repository was archived by the owner on Aug 3, 2026. It is now read-only.

Commit b466674

Browse files
authored
Merge pull request #2 from ESPToolKit/formatter-baseline
Align formatter baseline with esptoolkit-template
2 parents f03a896 + dd66d14 commit b466674

23 files changed

Lines changed: 2266 additions & 2043 deletions

File tree

.clang-format

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
BasedOnStyle: LLVM
2+
ColumnLimit: 100
3+
BinPackArguments: false
4+
BinPackParameters: false
5+
AllowAllArgumentsOnNextLine: false
6+
AlignAfterOpenBracket: BlockIndent
7+
UseTab: ForIndentation
8+
IndentWidth: 4
9+
TabWidth: 4
10+
ContinuationIndentWidth: 4
11+
AllowShortFunctionsOnASingleLine: None

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
charset = utf-8
7+
8+
[*.{c,cc,cpp,h,hpp,ino}]
9+
indent_style = tab
10+
indent_size = tab
11+
tab_width = 4

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
.venv
22
build/
33
build_prev_runner/
4-
.vscode

.vscode/bin/clang-format

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
if command -v clang-format >/dev/null 2>&1; then
6+
exec clang-format "$@"
7+
fi
8+
9+
_home_dir="${HOME:-}"
10+
if [ -n "$_home_dir" ]; then
11+
_candidate="$(ls -1d "$_home_dir"/.vscode/extensions/ms-vscode.cpptools-*-linux-x64/LLVM/bin/clang-format 2>/dev/null | tail -n 1 || true)"
12+
if [ -n "$_candidate" ] && [ -x "$_candidate" ]; then
13+
exec "$_candidate" "$@"
14+
fi
15+
fi
16+
17+
echo "clang-format executable not found." >&2
18+
echo "Install clang-format system-wide or install/update ms-vscode.cpptools." >&2
19+
exit 127

.vscode/extensions.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"recommendations": [
3+
"pioarduino.pioarduino-ide",
4+
"xaver.clang-format"
5+
],
6+
"unwantedRecommendations": [
7+
"ms-vscode.cpptools-extension-pack"
8+
]
9+
}

.vscode/settings.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"files.associations": {
3+
"*.ino": "cpp"
4+
},
5+
"editor.defaultFormatter": "xaver.clang-format",
6+
"C_Cpp.formatting": "Disabled",
7+
"clang-format.style": "file",
8+
"clang-format.executable": "${workspaceRoot}/.vscode/bin/clang-format",
9+
"[cpp]": {
10+
"editor.defaultFormatter": "xaver.clang-format",
11+
"editor.detectIndentation": false,
12+
"editor.insertSpaces": false,
13+
"editor.tabSize": 4,
14+
"editor.formatOnSave": true
15+
},
16+
"[c]": {
17+
"editor.defaultFormatter": "xaver.clang-format",
18+
"editor.detectIndentation": false,
19+
"editor.insertSpaces": false,
20+
"editor.tabSize": 4,
21+
"editor.formatOnSave": true
22+
},
23+
"[arduino]": {
24+
"editor.defaultFormatter": "xaver.clang-format",
25+
"editor.detectIndentation": false,
26+
"editor.insertSpaces": false,
27+
"editor.tabSize": 4,
28+
"editor.formatOnSave": true
29+
}
30+
}

.vscode/tasks.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "Format Firmware Sources",
6+
"type": "shell",
7+
"command": "bash ${workspaceFolder}/scripts/format_cpp.sh",
8+
"group": "build",
9+
"problemMatcher": []
10+
}
11+
]
12+
}

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ serializeJson(json, Serial);
134134
- `examples/failure-policy` - rollback and teardown failure policy behavior.
135135
- `examples/reload-burst` - listener burst coalescing and deduplicated node-name reloads.
136136

137+
## Formatting Baseline
138+
139+
This repository follows the firmware formatting baseline from `esptoolkit-template`:
140+
- `.clang-format` is the source of truth for C/C++/INO layout.
141+
- `.editorconfig` enforces tabs (`tab_width = 4`), LF endings, and final newline.
142+
- Format all tracked firmware sources with `bash scripts/format_cpp.sh`.
143+
137144
## License
138145
MIT - see [LICENSE.md](LICENSE.md).
139146

examples/basic-startup/basic-startup.ino

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,53 @@ ESPWorker worker;
66
ESPLifecycle lifecycle;
77

88
void setup() {
9-
Serial.begin(115200);
10-
11-
worker.init(ESPWorker::Config{});
12-
13-
LifecycleConfig config{};
14-
config.worker = &worker;
15-
config.enableParallelInit = true;
16-
config.enableParallelDeinit = true;
17-
config.enableParallelReinit = true;
18-
config.onInitStarted = []() { Serial.println("init started"); };
19-
config.onReady = []() { Serial.println("running"); };
20-
config.onInitFailed = []() { Serial.println("init failed"); };
21-
22-
lifecycle.configure(config);
23-
lifecycle.init({"core", "network"});
24-
25-
lifecycle.addTo("core", "logger", []() { return true; }, []() { return true; }).parallelSafe();
26-
lifecycle.addTo("core", "storage", []() { return true; }, []() { return true; });
27-
lifecycle.addTo("network", "wifi", []() { return true; }, []() { return true; }).after("storage");
28-
29-
LifecycleResult buildResult = lifecycle.build();
30-
if( !buildResult.ok ){
31-
Serial.println("build failed");
32-
return;
33-
}
34-
35-
LifecycleResult initResult = lifecycle.initialize();
36-
if( !initResult.ok ){
37-
Serial.println("initialize failed");
38-
return;
39-
}
40-
41-
JsonDocument snapshot = lifecycle.snapshotJson();
42-
const bool phaseCompleted = snapshot["phaseCompleted"] | false;
43-
Serial.printf("phase status: %s\n", phaseCompleted ? "completed" : "in progress");
44-
serializeJson(snapshot, Serial);
45-
Serial.println();
46-
47-
delay(1000);
48-
(void)lifecycle.deinitialize({"logger"});
9+
Serial.begin(115200);
10+
11+
worker.init(ESPWorker::Config{});
12+
13+
LifecycleConfig config{};
14+
config.worker = &worker;
15+
config.enableParallelInit = true;
16+
config.enableParallelDeinit = true;
17+
config.enableParallelReinit = true;
18+
config.onInitStarted = []() { Serial.println("init started"); };
19+
config.onReady = []() { Serial.println("running"); };
20+
config.onInitFailed = []() { Serial.println("init failed"); };
21+
22+
lifecycle.configure(config);
23+
lifecycle.init({"core", "network"});
24+
25+
lifecycle.addTo("core", "logger", []() { return true; }, []() { return true; }).parallelSafe();
26+
lifecycle.addTo("core", "storage", []() { return true; }, []() { return true; });
27+
lifecycle.addTo(
28+
"network",
29+
"wifi",
30+
[]() { return true; },
31+
[]() { return true; }
32+
).after("storage");
33+
34+
LifecycleResult buildResult = lifecycle.build();
35+
if (!buildResult.ok) {
36+
Serial.println("build failed");
37+
return;
38+
}
39+
40+
LifecycleResult initResult = lifecycle.initialize();
41+
if (!initResult.ok) {
42+
Serial.println("initialize failed");
43+
return;
44+
}
45+
46+
JsonDocument snapshot = lifecycle.snapshotJson();
47+
const bool phaseCompleted = snapshot["phaseCompleted"] | false;
48+
Serial.printf("phase status: %s\n", phaseCompleted ? "completed" : "in progress");
49+
serializeJson(snapshot, Serial);
50+
Serial.println();
51+
52+
delay(1000);
53+
(void)lifecycle.deinitialize({"logger"});
4954
}
5055

5156
void loop() {
52-
delay(250);
57+
delay(250);
5358
}

examples/deferred-readiness/deferred-readiness.ino

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,57 @@ ESPWorker worker;
66
ESPLifecycle lifecycle;
77

88
bool initCore() {
9-
Serial.println("init core");
10-
return true;
9+
Serial.println("init core");
10+
return true;
1111
}
1212

1313
bool initCloud() {
14-
Serial.println("init cloud");
15-
return true;
14+
Serial.println("init cloud");
15+
return true;
1616
}
1717

1818
bool deinitCore() {
19-
Serial.println("deinit core");
20-
return true;
19+
Serial.println("deinit core");
20+
return true;
2121
}
2222

2323
bool deinitCloud() {
24-
Serial.println("deinit cloud");
25-
return true;
24+
Serial.println("deinit cloud");
25+
return true;
2626
}
2727

2828
bool cloudReady() {
29-
return millis() > 4000;
29+
return millis() > 4000;
3030
}
3131

3232
void waitForReady(TickType_t waitTicks) {
33-
(void)waitTicks;
34-
delay(250);
33+
(void)waitTicks;
34+
delay(250);
3535
}
3636

3737
void setup() {
38-
Serial.begin(115200);
38+
Serial.begin(115200);
3939

40-
worker.init(ESPWorker::Config{});
40+
worker.init(ESPWorker::Config{});
4141

42-
LifecycleConfig config{};
43-
config.worker = &worker;
44-
config.onReady = []() { Serial.println("all sections ready"); };
42+
LifecycleConfig config{};
43+
config.worker = &worker;
44+
config.onReady = []() { Serial.println("all sections ready"); };
4545

46-
lifecycle.configure(config);
47-
lifecycle.init({"core", "cloud"});
46+
lifecycle.configure(config);
47+
lifecycle.init({"core", "cloud"});
4848

49-
lifecycle.section("cloud")
50-
.mode(LifecycleSectionMode::Deferred)
51-
.readiness(cloudReady, waitForReady);
49+
lifecycle.section("cloud")
50+
.mode(LifecycleSectionMode::Deferred)
51+
.readiness(cloudReady, waitForReady);
5252

53-
lifecycle.addTo("core", "core-init", initCore, deinitCore);
54-
lifecycle.addTo("cloud", "cloud-sync", initCloud, deinitCloud).after("core-init");
53+
lifecycle.addTo("core", "core-init", initCore, deinitCore);
54+
lifecycle.addTo("cloud", "cloud-sync", initCloud, deinitCloud).after("core-init");
5555

56-
(void)lifecycle.build();
57-
(void)lifecycle.initialize();
56+
(void)lifecycle.build();
57+
(void)lifecycle.initialize();
5858
}
5959

6060
void loop() {
61-
delay(500);
61+
delay(500);
6262
}

0 commit comments

Comments
 (0)