Skip to content

Commit 6d599e5

Browse files
committed
Add CI for formatting (#33)
Add a GitHub workflow to validate formatting and other standardized checks.
1 parent d6f88d3 commit 6d599e5

36 files changed

+231
-107
lines changed

.github/workflows/lint.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
9+
# on:
10+
# pull_request:
11+
# types: [opened, reopened, synchronize]
12+
13+
jobs:
14+
validate_format_config:
15+
name: Validate Format Config
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repo
19+
uses: actions/checkout@v4
20+
21+
- name: Install apt dependencies
22+
run: sudo apt-get -qq update && sudo apt-get -qq -y install curl
23+
24+
- name: Compare against swift-mmio swift-format config
25+
run: |
26+
curl -sL https://raw.githubusercontent.com/apple/swift-mmio/refs/heads/main/SupportingFiles/Tools/swift-format/.swift-format -o .swift-format-mmio
27+
diff .swift-format .swift-format-mmio
28+
29+
soundness:
30+
name: Soundness
31+
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
32+
with:
33+
api_breakage_check_enabled: false # this repo doesn't vend any API
34+
license_header_check_enabled: false # incorrectly flags this github workflow yml file
35+
license_header_check_project_name: "" # bug: https://github.com/swiftlang/github-workflows/issues/76
36+
shell_check_enabled: false # incorrectly flags tutorial content
37+
unacceptable_language_check_enabled: false # incorrectly flags "master" in external branch names

.swift-format

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lineBreakBeforeControlFlowKeywords" : false,
1212
"lineBreakBeforeEachArgument" : false,
1313
"lineBreakBeforeEachGenericRequirement" : false,
14-
"lineLength" : 160,
14+
"lineLength" : 80,
1515
"maximumBlankLines" : 1,
1616
"multiElementCollectionTrailingCommas" : true,
1717
"noAssignmentInExpressions" : {
@@ -62,6 +62,7 @@
6262
"UseWhereClausesInForLoops" : false,
6363
"ValidateDocumentationComments" : true
6464
},
65+
"spacesBeforeEndOfLineComments": 2,
6566
"spacesAroundRangeFormationOperators" : false,
6667
"tabWidth" : 2,
6768
"version" : 1

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import PackageDescription
55
let package = Package(
66
name: "swift-matter-examples",
77
products: [
8-
.library(name: "SwiftMatterExamples", targets: ["SwiftMatterExamples"]),
8+
.library(name: "SwiftMatterExamples", targets: ["SwiftMatterExamples"])
99
],
1010
targets: [
1111
.target(name: "SwiftMatterExamples")
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
#! /bin/sh
2+
13
# Install Homebrew
24
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Sources/SwiftMatterExamples/Documentation.docc/Resources/install-esp-terminal/install-esp-terminal-01.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#! /bin/sh
2+
13
# Install Homebrew
24
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
35

Sources/SwiftMatterExamples/Documentation.docc/Resources/install-esp-terminal/install-esp-terminal-02.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#! /bin/sh
2+
13
# Install Homebrew
24
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
35

Sources/SwiftMatterExamples/Documentation.docc/Resources/install-esp-terminal/install-esp-terminal-03.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#! /bin/sh
2+
13
# Install Homebrew
24
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
35

Sources/SwiftMatterExamples/Documentation.docc/Resources/install-esp-terminal/install-esp-terminal-04.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#! /bin/sh
2+
13
# Install Homebrew
24
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
35

Sources/SwiftMatterExamples/Documentation.docc/Resources/install-esp-terminal/install-esp-terminal-05.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#! /bin/sh
2+
13
# Install Homebrew
24
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
35

Sources/SwiftMatterExamples/Documentation.docc/Resources/install-esp-terminal/install-esp-terminal-06.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#! /bin/sh
2+
13
# Install Homebrew
24
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
35

Sources/SwiftMatterExamples/Documentation.docc/Resources/run-example-led-blink/walkthrough-example-led-blink-01.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
func app_main() {
12+
func main() {
1313
print("🏎️ Hello, Embedded Swift! (LED Blink)")
1414
}

Sources/SwiftMatterExamples/Documentation.docc/Resources/run-example-led-blink/walkthrough-example-led-blink-02.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
@_cdecl("app_main")
13-
func app_main() {
13+
func main() {
1414
print("🏎️ Hello, Embedded Swift! (LED Blink)")
1515
}

Sources/SwiftMatterExamples/Documentation.docc/Resources/run-example-led-blink/walkthrough-example-led-blink-03.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
@_cdecl("app_main")
13-
func app_main() {
13+
func main() {
1414
print("🏎️ Hello, Embedded Swift! (LED Blink)")
1515

1616
let led = LED()

Sources/SwiftMatterExamples/Documentation.docc/Resources/run-example-led-blink/walkthrough-example-led-blink-04.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
@_cdecl("app_main")
13-
func app_main() {
13+
func main() {
1414
print("🏎️ Hello, Embedded Swift! (LED Blink)")
1515

1616
let led = LED()

Sources/SwiftMatterExamples/Documentation.docc/Resources/run-example-led-blink/walkthrough-example-led-blink-05.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
@_cdecl("app_main")
13-
func app_main() {
13+
func main() {
1414
print("🏎️ Hello, Embedded Swift! (LED Blink)")
1515

1616
let led = LED()
@@ -21,7 +21,7 @@ func app_main() {
2121
sleep(1)
2222
led.enabled.toggle()
2323
if led.enabled {
24-
led.color = .hueSaturation(Int.random(in: 0 ..< 360), 100)
24+
led.color = .hueSaturation(Int.random(in: 0..<360), 100)
2525
}
2626
}
2727
}

Sources/SwiftMatterExamples/Documentation.docc/Resources/run-example-smart-light/walkthrough-example-smart-light-01.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
@_cdecl("app_main")
13-
func app_main() {
13+
func main() {
1414
print("🏎️ Hello, Embedded Swift! (Smart Light)")
1515
}

Sources/SwiftMatterExamples/Documentation.docc/Resources/run-example-smart-light/walkthrough-example-smart-light-02.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
@_cdecl("app_main")
13-
func app_main() {
13+
func main() {
1414
print("🏎️ Hello, Embedded Swift! (Smart Light)")
1515

1616
let led = LED()

Sources/SwiftMatterExamples/Documentation.docc/Resources/run-example-smart-light/walkthrough-example-smart-light-03.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
@_cdecl("app_main")
13-
func app_main() {
13+
func main() {
1414
print("🏎️ Hello, Embedded Swift! (Smart Light)")
1515

1616
let led = LED()

Sources/SwiftMatterExamples/Documentation.docc/Resources/run-example-smart-light/walkthrough-example-smart-light-04-a.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
@_cdecl("app_main")
13-
func app_main() {
13+
func main() {
1414
print("🏎️ Hello, Embedded Swift! (Smart Light)")
1515

1616
let led = LED()

Sources/SwiftMatterExamples/Documentation.docc/Resources/run-example-smart-light/walkthrough-example-smart-light-04-b.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
@_cdecl("app_main")
13-
func app_main() {
13+
func main() {
1414
print("🏎️ Hello, Embedded Swift! (Smart Light)")
1515

1616
let led = LED()

Sources/SwiftMatterExamples/Documentation.docc/Resources/run-example-smart-light/walkthrough-example-smart-light-04-c.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
@_cdecl("app_main")
13-
func app_main() {
13+
func main() {
1414
print("🏎️ Hello, Embedded Swift! (Smart Light)")
1515

1616
let led = LED()

Sources/SwiftMatterExamples/Documentation.docc/Resources/run-example-smart-light/walkthrough-example-smart-light-04.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
@_cdecl("app_main")
13-
func app_main() {
13+
func main() {
1414
print("🏎️ Hello, Embedded Swift! (Smart Light)")
1515

1616
let led = LED()

Sources/SwiftMatterExamples/Documentation.docc/Resources/run-example-smart-light/walkthrough-example-smart-light-05.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
@_cdecl("app_main")
13-
func app_main() {
13+
func main() {
1414
print("🏎️ Hello, Embedded Swift! (Smart Light)")
1515

1616
let led = LED()

Sources/SwiftMatterExamples/Documentation.docc/Resources/run-example-smart-light/walkthrough-example-smart-light-06.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
@_cdecl("app_main")
13-
func app_main() {
13+
func main() {
1414
print("🏎️ Hello, Embedded Swift! (Smart Light)")
1515

1616
let led = LED()

Sources/SwiftMatterExamples/Documentation.docc/Tutorials/Run-Example-LED-Blink.tutorial

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,14 @@
6464

6565
@Steps {
6666
@Step {
67-
We start the application by declaring an **`app_main`** function with a print statement to show the application has started.
68-
69-
`app_main` serves the same purpose as a `main` function in a traditional user-land application and acts as the primary entry point for our firmware application.
67+
We start the application by declaring an **`main`** function with a print statement to show the application has started.
7068

7169
@Code(name: "Main.swift", file: "walkthrough-example-led-blink-01.swift", previousFile: "walkthrough-example-led-blink-00.swift")
7270
}
7371

7472
@Step {
7573
We use the **`@_cdecl("app_main")`** attribute to generate a wrapper C symbol which is expected by ESP IDF.
76-
74+
7775
> Important: Underscored attributes, like `@_cdecl`, are unstable features of the Swift compiler and may change behavior or break between compiler versions.
7876

7977
@Code(name: "Main.swift", file: "walkthrough-example-led-blink-02.swift", previousFile: "walkthrough-example-led-blink-01.swift")

empty-template/main/Main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
@_cdecl("app_main")
13-
func app_main() {
13+
func main() {
1414
print("🏎️ Hello, Embedded Swift!")
1515
}

empty-template/main/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
dependencies:
22
espressif/cmake_utilities:
33
version: 0.*
4-
rules: # will add "optional_component" only when all if clauses are True
4+
rules: # will add "optional_component" only when all if clauses are True
55
- if: "idf_version >=5.0"
66
- if: "target in [esp32c2]"

led-blink/main/LED.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,28 @@ final class LED {
5353
// Hue range is 0 ..< 360.
5454
var hue: Int {
5555
switch self {
56-
case .hueSaturation(let hue, _): return hue
57-
case .temperature: return 0
56+
case .hueSaturation(let hue, _): return hue
57+
case .temperature: return 0
5858
}
5959
}
6060

6161
// Saturation is 0 ... 100.
6262
var saturation: Int {
6363
switch self {
64-
case .hueSaturation(_, let saturation): return saturation
65-
case .temperature: return 0
64+
case .hueSaturation(_, let saturation): return saturation
65+
case .temperature: return 0
6666
}
6767
}
6868
}
6969

7070
var handle: led_driver_handle_t
71-
71+
7272
init() {
7373
var config = led_driver_get_config()
7474
let handle = led_driver_init(&config)
75+
guard let handle else { fatalError("Failed to initialize handle") }
7576
led_driver_set_power(handle, true)
76-
self.handle = handle!
77+
self.handle = handle
7778
}
7879

7980
}

led-blink/main/Main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
@_cdecl("app_main")
13-
func app_main() {
13+
func main() {
1414
print("🏎️ Hello, Embedded Swift! (LED Blink)")
1515

1616
let led = LED()
@@ -21,7 +21,7 @@ func app_main() {
2121
sleep(1)
2222
led.enabled.toggle()
2323
if led.enabled {
24-
led.color = .hueSaturation(Int.random(in: 0 ..< 360), 100)
24+
led.color = .hueSaturation(Int.random(in: 0..<360), 100)
2525
}
2626
}
2727
}

led-blink/main/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
dependencies:
22
espressif/cmake_utilities:
33
version: 0.*
4-
rules: # will add "optional_component" only when all if clauses are True
4+
rules: # will add "optional_component" only when all if clauses are True
55
- if: "idf_version >=5.0"
66
- if: "target in [esp32c2]"

0 commit comments

Comments
 (0)