Skip to content

Commit d6fce74

Browse files
authored
Merge pull request #4 from sideeffect-io/feature/swiftlint
project: integrate SwiftLint
2 parents 3786a55 + 2ad5eff commit d6fce74

19 files changed

Lines changed: 267 additions & 128 deletions

.github/workflows/lint.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
paths:
6+
- '.github/workflows/lint.yml'
7+
- '.swiftlint.yml'
8+
- 'Sources/**/*.swift'
9+
10+
jobs:
11+
SwiftLint:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: SwiftLint
16+
uses: norio-nomura/action-swiftlint@3.2.1

.swiftlint.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
included:
2+
- Sources
3+
excluded:
4+
- Tests
5+
analyzer_rules:
6+
disabled_rules:
7+
- large_tuple
8+
- unused_declaration
9+
- generic_type_name
10+
opt_in_rules:
11+
- anyobject_protocol
12+
- array_init
13+
- attributes
14+
- closure_end_indentation
15+
- closure_spacing
16+
- collection_alignment
17+
- contains_over_filter_count
18+
- contains_over_filter_is_empty
19+
- contains_over_first_not_nil
20+
- discouraged_object_literal
21+
- empty_count
22+
- empty_string
23+
- empty_xctest_method
24+
- explicit_init
25+
- extension_access_modifier
26+
- fallthrough
27+
- file_header
28+
- file_name
29+
- first_where
30+
- flatmap_over_map_reduce
31+
- identical_operands
32+
- joined_default_parameter
33+
- legacy_random
34+
- let_var_whitespace
35+
- last_where
36+
- literal_expression_end_indentation
37+
- lower_acl_than_parent
38+
- modifier_order
39+
- nimble_operator
40+
- nslocalizedstring_key
41+
- number_separator
42+
- object_literal
43+
- operator_usage_whitespace
44+
- overridden_super_call
45+
- override_in_extension
46+
- pattern_matching_keywords
47+
- private_action
48+
- private_outlet
49+
- prohibited_interface_builder
50+
- prohibited_super_call
51+
- quick_discouraged_call
52+
- quick_discouraged_focused_test
53+
- quick_discouraged_pending_test
54+
- reduce_into
55+
- redundant_nil_coalescing
56+
- redundant_type_annotation
57+
- single_test_class
58+
- sorted_first_last
59+
- sorted_imports
60+
- static_operator
61+
- strong_iboutlet
62+
- toggle_bool
63+
- unavailable_function
64+
- unneeded_parentheses_in_closure_argument
65+
- unowned_variable_capture
66+
- untyped_error_in_catch
67+
- vertical_parameter_alignment_on_call
68+
- vertical_whitespace_closing_braces
69+
- vertical_whitespace_opening_braces
70+
- xct_specific_matcher
71+
- yoda_condition
72+
73+
line_length: 135
74+
75+
# configurable rules can be customized from this configuration file
76+
# binary rules can set their severity level
77+
force_cast: warning # implicitly
78+
force_try:
79+
severity: warning # explicitly
80+
81+
type_name:
82+
excluded:
83+
- on
84+
- On
85+
identifier_name:
86+
excluded:
87+
- id
88+
- me
89+
- on
90+
number_separator:
91+
minimum_length: 5
92+
file_name:
93+
excluded:
94+
- main.swift
95+
- LinuxMain.swift
96+
- TestHelpers.swift
97+
- shim.swift
98+
- AutomaticRuleTests.generated.swift

README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[![Build and test](https://github.com/sideeffect-io/AsyncStateMachine/actions/workflows/ci.yml/badge.svg)](https://github.com/sideeffect-io/AsyncStateMachine/actions/workflows/ci.yml)
2+
[![Lint](https://github.com/sideeffect-io/AsyncStateMachine/actions/workflows/lint.yml/badge.svg)](https://github.com/sideeffect-io/AsyncStateMachine/actions/workflows/lint.yml)
23

34
# Async State Machine
45
**Async State Machine** aims to provide a way to structure an application thanks to state machines. The goal is to identify the states and the side effects involved in each feature and to model them in a consistent and scalable way thanks to a DSL.
@@ -260,17 +261,13 @@ struct ContentView: View {
260261
var body: some View {
261262
VStack {
262263
Text(self.viewState.state.description)
263-
Button {
264-
Task {
265-
await self.viewState.send(Event.personsHaveEntered(persons: 1))
266-
}
264+
Button {
265+
self.viewState.send(Event.personsHaveEntered(persons: 1))
267266
} label: {
268267
Text("New person")
269268
}
270-
Button {
271-
Task {
272-
await self.viewState.send(Event.closeButtonWasPressed)
273-
}
269+
Button {
270+
self.viewState.send(Event.closeButtonWasPressed)
274271
} label: {
275272
Text("Close the door")
276273
}

Sources/AsyncStateMachineSequence.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ where S: DSLCompatible & Sendable, E: DSLCompatible & Sendable, O: DSLCompatible
6161
self.deinitBlock()
6262
}
6363

64-
@Sendable public func send(_ event: E) {
64+
@Sendable
65+
public func send(_ event: E) {
6566
self.eventChannel.send(event)
6667
}
6768

6869
public func makeAsyncIterator() -> AsyncIterator {
6970
self
7071
.eventChannel
71-
.onEach { [weak self] event in await self?.engine.process(event:event) }
72+
.onEach { [weak self] event in await self?.engine.process(event: event) }
7273
.compactScan(self.initialState, self.engine.computeNextState)
7374
.serial()
7475
.onEach { [weak self] state in await self?.engine.process(state: state, sendBackEvent: self?.send(_:)) }

Sources/Runtime/ExecutionStrategy.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// Created by Thibault WITTEMBERG on 25/06/2022.
66
//
77

8-
98
public struct ExecutionStrategy<S>: Sendable, Equatable
109
where S: DSLCompatible {
1110
enum Identifier {

Sources/Runtime/Runtime.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ where S: DSLCompatible, E: DSLCompatible & Sendable, O: DSLCompatible {
8989
let predicate: @Sendable (O) -> Bool = { currentOutput in
9090
currentOutput.matches(output)
9191
}
92-
92+
9393
let sideEffect: @Sendable (O) -> AnyAsyncSequence<E>? = { currentOutput in
9494
if let outputAssociatedValue = currentOutput.associatedValue(expecting: OutputAssociatedValue.self) {
9595
return sideEffect(outputAssociatedValue).eraseToAnyAsyncSequence()
@@ -208,10 +208,10 @@ where S: DSLCompatible, E: DSLCompatible & Sendable, O: DSLCompatible {
208208
})
209209
}
210210

211-
@Sendable func sideEffects(for output: O) -> SideEffect<S, E, O>? {
211+
@Sendable
212+
func sideEffects(for output: O) -> SideEffect<S, E, O>? {
212213
self
213214
.sideEffects
214215
.first(where: { sideEffect in sideEffect.predicate(output) })
215216
}
216217
}
217-

Sources/StateMachine/DSLCompatible.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public extension DSLCompatible {
6161
return memcmp(&me, &other, MemoryLayout<Self>.size) == 0 || me.label == other.label
6262
}
6363

64-
6564
/// Determines if `self` matches an enum case signature that has associated values.
6665
///
6766
/// ```
@@ -94,8 +93,8 @@ public extension DSLCompatible {
9493
/// - Returns: the value of the associated type when `self` matches the given enum signature, nil otherwise.
9594
func associatedValue<AssociatedValue>(matching definition: (AssociatedValue) -> Self) -> AssociatedValue? {
9695
guard
97-
let me: (path: [String?], associatedValue: AssociatedValue) = decompose(expecting: AssociatedValue.self),
98-
let other: (path: [String?], associatedValue: AssociatedValue) = definition(me.associatedValue).decompose(expecting: AssociatedValue.self),
96+
let me = decompose(expecting: AssociatedValue.self),
97+
let other = definition(me.associatedValue).decompose(expecting: AssociatedValue.self),
9998
me.path == other.path else { return nil }
10099
return me.associatedValue
101100
}

Sources/StateMachine/Execute.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
public struct Execute<O>
99
where O: DSLCompatible {
1010
let output: O?
11-
11+
1212
init() {
1313
self.output = nil
1414
}
15-
15+
1616
public init(output: O) {
1717
self.output = output
1818
}
19-
19+
2020
public static var noOutput: Execute<O> {
2121
Execute()
2222
}

Sources/StateMachine/Guard.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
public struct Guard {
99
let predicate: Bool
10-
10+
1111
public init(predicate: @autoclosure () -> Bool) {
1212
self.predicate = predicate()
1313
}

Sources/StateMachine/OneOf.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
public struct OneOf<T>: Sendable
99
where T: DSLCompatible {
1010
let predicate: @Sendable (T) -> Bool
11-
11+
1212
init(predicate: @escaping @Sendable (T) -> Bool) {
1313
self.predicate = predicate
1414
}
15-
15+
1616
public init(@OneOfBuilder<T> _ oneOf: () -> OneOf<T>) {
1717
self = oneOf()
1818
}
@@ -28,15 +28,15 @@ where T: DSLCompatible {
2828
input.matches(expression)
2929
}
3030
}
31-
31+
3232
public static func buildExpression<AssociatedValue>(
3333
_ expression: @escaping (AssociatedValue) -> T
3434
) -> (T) -> Bool {
3535
{ input in
3636
input.matches(expression)
3737
}
3838
}
39-
39+
4040
public static func buildBlock(_ components: ((T) -> Bool)...) -> OneOf<T> {
4141
OneOf(predicate: { input in components.contains { $0(input) } })
4242
}

0 commit comments

Comments
 (0)