Skip to content

Commit 5c3a2ee

Browse files
authored
fix: Run swift-format [1/4] (#328)
Support running swift-format -i --recursive . for formatting which is compatible with the linting rules
1 parent fc7e44d commit 5c3a2ee

File tree

58 files changed

+2899
-2001
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2899
-2001
lines changed

.swift-format

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"fileScopedDeclarationPrivacy" : {
3+
"accessLevel" : "private"
4+
},
5+
"indentConditionalCompilationBlocks" : false,
6+
"indentSwitchCaseLabels" : false,
7+
"indentation" : {
8+
"spaces" : 4
9+
},
10+
"lineBreakAroundMultilineExpressionChainComponents" : false,
11+
"lineBreakBeforeControlFlowKeywords" : false,
12+
"lineBreakBeforeEachArgument" : false,
13+
"lineBreakBeforeEachGenericRequirement" : false,
14+
"lineBreakBetweenDeclarationAttributes" : false,
15+
"lineLength" : 140,
16+
"maximumBlankLines" : 1,
17+
"multiElementCollectionTrailingCommas" : true,
18+
"noAssignmentInExpressions" : {
19+
"allowedFunctions" : [
20+
"XCTAssertNoThrow"
21+
]
22+
},
23+
"prioritizeKeepingFunctionOutputTogether" : true,
24+
"reflowMultilineStringLiterals" : {
25+
"never" : {
26+
27+
}
28+
},
29+
"respectsExistingLineBreaks" : true,
30+
"rules" : {
31+
"AllPublicDeclarationsHaveDocumentation" : false,
32+
"AlwaysUseLiteralForEmptyCollectionInit" : false,
33+
"AlwaysUseLowerCamelCase" : true,
34+
"AmbiguousTrailingClosureOverload" : true,
35+
"AvoidRetroactiveConformances" : true,
36+
"BeginDocumentationCommentWithOneLineSummary" : false,
37+
"DoNotUseSemicolons" : true,
38+
"DontRepeatTypeInStaticProperties" : true,
39+
"FileScopedDeclarationPrivacy" : true,
40+
"FullyIndirectEnum" : true,
41+
"GroupNumericLiterals" : true,
42+
"IdentifiersMustBeASCII" : true,
43+
"NeverForceUnwrap" : false,
44+
"NeverUseForceTry" : false,
45+
"NeverUseImplicitlyUnwrappedOptionals" : false,
46+
"NoAccessLevelOnExtensionDeclaration" : false,
47+
"NoAssignmentInExpressions" : true,
48+
"NoBlockComments" : true,
49+
"NoCasesWithOnlyFallthrough" : true,
50+
"NoEmptyLinesOpeningClosingBraces" : false,
51+
"NoEmptyTrailingClosureParentheses" : true,
52+
"NoLabelsInCasePatterns" : true,
53+
"NoLeadingUnderscores" : false,
54+
"NoParensAroundConditions" : true,
55+
"NoPlaygroundLiterals" : true,
56+
"NoVoidReturnOnFunctionSignature" : true,
57+
"OmitExplicitReturns" : false,
58+
"OneCasePerLine" : true,
59+
"OneVariableDeclarationPerLine" : true,
60+
"OnlyOneTrailingClosureArgument" : true,
61+
"OrderedImports" : true,
62+
"ReplaceForEachWithForLoop" : true,
63+
"ReturnVoidInsteadOfEmptyTuple" : true,
64+
"TypeNamesShouldBeCapitalized" : true,
65+
"UseEarlyExits" : false,
66+
"UseExplicitNilCheckInConditions" : true,
67+
"UseLetInEveryBoundCaseVariable" : true,
68+
"UseShorthandTypeNames" : true,
69+
"UseSingleLinePropertyGetter" : true,
70+
"UseSynthesizedInitializer" : true,
71+
"UseTripleSlashForDocumentationComments" : true,
72+
"UseWhereClausesInForLoops" : false,
73+
"ValidateDocumentationComments" : false
74+
},
75+
"spacesAroundRangeFormationOperators" : false,
76+
"spacesBeforeEndOfLineComments" : 1,
77+
"tabWidth" : 8,
78+
"version" : 1
79+
}

.swiftlint_refinement.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
disabled_rules:
2+
- opening_brace
3+
- trailing_comma
4+
- prefer_self_in_static_references
15
excluded:
26
- Sources/Benchmark/Progress
37
- Sources/Benchmark/NIOConcurrencyHelpers

Benchmarks/Benchmarks/Basic/Basic+SetupTeardown.swift

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,44 @@ func sharedSetup() {}
1414
// }
1515

1616
func sharedTeardown() {
17-
// print("Shared teardown hook")
17+
// print("Shared teardown hook")
1818
}
1919

2020
func testSetUpTearDown() {
21-
// Benchmark.setup = { print("Global setup hook")}
22-
// Benchmark.setup = { 123 }
23-
// Benchmark.teardown = { print("Global teardown hook") }
21+
// Benchmark.setup = { print("Global setup hook")}
22+
// Benchmark.setup = { 123 }
23+
// Benchmark.teardown = { print("Global teardown hook") }
2424

25-
Benchmark("SetupTeardown",
26-
configuration: .init(setup: sharedSetup, teardown: sharedTeardown)) { _ in
25+
Benchmark(
26+
"SetupTeardown",
27+
configuration: .init(setup: sharedSetup, teardown: sharedTeardown)
28+
) { _ in
2729
} setup: {
2830
// print("Local setup hook")
2931
} teardown: {
3032
// print("Local teardown hook")
3133
}
3234

33-
Benchmark("SetupTeardown2",
34-
configuration: .init(setup: sharedSetup, teardown: sharedTeardown)) { _ in
35+
Benchmark(
36+
"SetupTeardown2",
37+
configuration: .init(setup: sharedSetup, teardown: sharedTeardown)
38+
) { _ in
3539
}
3640

37-
Benchmark("SetupTeardown3",
38-
configuration: .init(setup: sharedSetup)) { _ in
41+
Benchmark(
42+
"SetupTeardown3",
43+
configuration: .init(setup: sharedSetup)
44+
) { _ in
3945
// let x = benchmark.setupState as! [Int]
4046
// print("\(x)")
4147
} teardown: {
4248
// print("Local teardown hook")
4349
}
4450

45-
Benchmark("SetupTeardown4",
46-
configuration: .init(setup: sharedSetup)) { _ in
51+
Benchmark(
52+
"SetupTeardown4",
53+
configuration: .init(setup: sharedSetup)
54+
) { _ in
4755
// print("\(benchmark.setupState)")
4856
} setup: {
4957
// return 7
@@ -55,7 +63,7 @@ func testSetUpTearDown() {
5563
}
5664

5765
Benchmark("SetupTeardown6") { _, _ in
58-
// print("\(setupState)")
66+
// print("\(setupState)")
5967
} setup: {
6068
[1, 2, 3]
6169
}

Benchmarks/Benchmarks/Basic/BenchmarkRunner+Basic.swift

Lines changed: 87 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,28 @@ let benchmarks: @Sendable () -> Void = {
2626

2727
thresholdTolerances = [.wallClock: .relaxed]
2828

29-
Benchmark.defaultConfiguration = .init(warmupIterations: 0,
30-
maxDuration: .seconds(1),
31-
maxIterations: Int.max,
32-
thresholds: thresholdTolerances)
29+
Benchmark.defaultConfiguration = .init(
30+
warmupIterations: 0,
31+
maxDuration: .seconds(1),
32+
maxIterations: Int.max,
33+
thresholds: thresholdTolerances
34+
)
3335

3436
testSetUpTearDown()
3537

3638
// A way to define custom metrics fairly compact
3739
enum CustomMetrics {
3840
static var one: BenchmarkMetric { .custom("CustomMetricOne") }
3941
static var two: BenchmarkMetric { .custom("CustomMetricTwo", polarity: .prefersLarger, useScalingFactor: true) }
40-
static var three: BenchmarkMetric { .custom("CustomMetricThree", polarity: .prefersLarger, useScalingFactor: false) }
42+
static var three: BenchmarkMetric {
43+
.custom("CustomMetricThree", polarity: .prefersLarger, useScalingFactor: false)
44+
}
4145
}
4246

43-
Benchmark("Basic",
44-
configuration: .init(metrics: [.wallClock, .throughput, .instructions])) { _ in
47+
Benchmark(
48+
"Basic",
49+
configuration: .init(metrics: [.wallClock, .throughput, .instructions])
50+
) { _ in
4551
}
4652

4753
Benchmark("Noop", configuration: .init(metrics: [.wallClock, .mallocCountTotal, .instructions])) { _ in
@@ -50,51 +56,70 @@ let benchmarks: @Sendable () -> Void = {
5056
Benchmark("Noop2", configuration: .init(metrics: [.wallClock, .instructions] + .arc)) { _ in
5157
}
5258

53-
Benchmark("Scaled metrics One",
54-
configuration: .init(metrics: .all + [CustomMetrics.two, CustomMetrics.one],
55-
scalingFactor: .one)) { benchmark in
59+
Benchmark(
60+
"Scaled metrics One",
61+
configuration: .init(
62+
metrics: .all + [CustomMetrics.two, CustomMetrics.one],
63+
scalingFactor: .one
64+
)
65+
) { benchmark in
5666
for _ in benchmark.scaledIterations {
57-
blackHole(Int.random(in: 1 ... 1_000))
67+
blackHole(Int.random(in: 1...1_000))
5868
}
59-
benchmark.measurement(CustomMetrics.two, Int.random(in: 1 ... 1_000_000))
60-
benchmark.measurement(CustomMetrics.one, Int.random(in: 1 ... 1_000))
69+
benchmark.measurement(CustomMetrics.two, Int.random(in: 1...1_000_000))
70+
benchmark.measurement(CustomMetrics.one, Int.random(in: 1...1_000))
6171
}
6272

63-
Benchmark("Scaled metrics K",
64-
configuration: .init(metrics: .all + [CustomMetrics.two, CustomMetrics.one],
65-
scalingFactor: .kilo)) { benchmark in
73+
Benchmark(
74+
"Scaled metrics K",
75+
configuration: .init(
76+
metrics: .all + [CustomMetrics.two, CustomMetrics.one],
77+
scalingFactor: .kilo
78+
)
79+
) { benchmark in
6680
for _ in benchmark.scaledIterations {
67-
blackHole(Int.random(in: 1 ... 1_000))
81+
blackHole(Int.random(in: 1...1_000))
6882
}
69-
benchmark.measurement(CustomMetrics.two, Int.random(in: 1 ... 1_000_000))
70-
benchmark.measurement(CustomMetrics.one, Int.random(in: 1 ... 1_000))
83+
benchmark.measurement(CustomMetrics.two, Int.random(in: 1...1_000_000))
84+
benchmark.measurement(CustomMetrics.one, Int.random(in: 1...1_000))
7185
}
7286

73-
Benchmark("Scaled metrics M",
74-
configuration: .init(metrics: .all + [CustomMetrics.two, CustomMetrics.one, CustomMetrics.three],
75-
scalingFactor: .mega)) { benchmark in
87+
Benchmark(
88+
"Scaled metrics M",
89+
configuration: .init(
90+
metrics: .all + [CustomMetrics.two, CustomMetrics.one, CustomMetrics.three],
91+
scalingFactor: .mega
92+
)
93+
) { benchmark in
7694
for _ in benchmark.scaledIterations {
7795
blackHole(Int.random(in: benchmark.scaledIterations))
7896
}
79-
benchmark.measurement(CustomMetrics.three, Int.random(in: 1 ... 1_000_000_000))
80-
benchmark.measurement(CustomMetrics.two, Int.random(in: 1 ... 1_000_000))
81-
benchmark.measurement(CustomMetrics.one, Int.random(in: 1 ... 1_000))
97+
benchmark.measurement(CustomMetrics.three, Int.random(in: 1...1_000_000_000))
98+
benchmark.measurement(CustomMetrics.two, Int.random(in: 1...1_000_000))
99+
benchmark.measurement(CustomMetrics.one, Int.random(in: 1...1_000))
82100
}
83101

84-
Benchmark("All metrics",
85-
configuration: .init(metrics: .all, skip: true)) { _ in
102+
Benchmark(
103+
"All metrics",
104+
configuration: .init(metrics: .all, skip: true)
105+
) { _ in
86106
}
87107

88108
let stats = Statistics(numberOfSignificantDigits: .four)
89109
let measurementCount = 8_340
90110

91-
for measurement in (0 ..< measurementCount).reversed() {
111+
for measurement in (0..<measurementCount).reversed() {
92112
stats.add(measurement)
93113
}
94114

95-
Benchmark("Statistics",
96-
configuration: .init(metrics: .arc + [.wallClock],
97-
scalingFactor: .kilo, maxDuration: .seconds(1))) { benchmark in
115+
Benchmark(
116+
"Statistics",
117+
configuration: .init(
118+
metrics: .arc + [.wallClock],
119+
scalingFactor: .kilo,
120+
maxDuration: .seconds(1)
121+
)
122+
) { benchmark in
98123
for _ in benchmark.scaledIterations {
99124
blackHole(stats.percentiles())
100125
}
@@ -104,7 +129,7 @@ let benchmarks: @Sendable () -> Void = {
104129

105130
parameterization.forEach { count in
106131
Benchmark("Parameterized", configuration: .init(tags: ["count": count.description])) { benchmark in
107-
for _ in 0 ..< count {
132+
for _ in 0..<count {
108133
blackHole(Int.random(in: benchmark.scaledIterations))
109134
}
110135
}
@@ -115,37 +140,46 @@ let benchmarks: @Sendable () -> Void = {
115140

116141
@Sendable
117142
func dummyCounter(_ count: Int) {
118-
for index in 0 ..< count {
143+
for index in 0..<count {
119144
blackHole(index)
120145
}
121146
}
122147

123148
func concurrentWork(tasks: Int = 4, mallocs: Int = 0) async {
124-
_ = await withTaskGroup(of: Void.self, returning: Void.self, body: { taskGroup in
125-
for _ in 0 ..< tasks {
126-
taskGroup.addTask {
127-
dummyCounter(defaultCounter() * 1_000)
128-
for _ in 0 ..< mallocs {
129-
let something = malloc(1_024 * 1_024)
130-
blackHole(something)
131-
free(something)
132-
}
133-
if let fileHandle = FileHandle(forWritingAtPath: "/dev/null") {
134-
let data = Data("Data to discard".utf8)
135-
fileHandle.write(data)
136-
fileHandle.closeFile()
149+
_ = await withTaskGroup(
150+
of: Void.self,
151+
returning: Void.self,
152+
body: { taskGroup in
153+
for _ in 0..<tasks {
154+
taskGroup.addTask {
155+
dummyCounter(defaultCounter() * 1_000)
156+
for _ in 0..<mallocs {
157+
let something = malloc(1_024 * 1_024)
158+
blackHole(something)
159+
free(something)
160+
}
161+
if let fileHandle = FileHandle(forWritingAtPath: "/dev/null") {
162+
let data = Data("Data to discard".utf8)
163+
fileHandle.write(data)
164+
fileHandle.closeFile()
165+
}
137166
}
138167
}
139-
}
140168

141-
for await _ in taskGroup {}
142-
})
169+
for await _ in taskGroup {}
170+
}
171+
)
143172
}
144173

145-
Benchmark("InstructionCount", configuration: .init(metrics: [.instructions],
146-
warmupIterations: 0,
147-
scalingFactor: .kilo,
148-
thresholds: [.instructions: .relaxed])) { _ in
174+
Benchmark(
175+
"InstructionCount",
176+
configuration: .init(
177+
metrics: [.instructions],
178+
warmupIterations: 0,
179+
scalingFactor: .kilo,
180+
thresholds: [.instructions: .relaxed]
181+
)
182+
) { _ in
149183
await concurrentWork(tasks: 15, mallocs: 1_000)
150184
}
151185
}

Benchmarks/Benchmarks/DateTime/DateTime.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ import Benchmark
1111
import DateTime
1212

1313
let benchmarks: @Sendable () -> Void = {
14-
Benchmark.defaultConfiguration = .init(metrics: [.throughput, .wallClock, .instructions] + .arc,
15-
warmupIterations: 10,
16-
scalingFactor: .kilo,
17-
maxDuration: .seconds(1),
18-
maxIterations: .kilo(10))
14+
Benchmark.defaultConfiguration = .init(
15+
metrics: [.throughput, .wallClock, .instructions] + .arc,
16+
warmupIterations: 10,
17+
scalingFactor: .kilo,
18+
maxDuration: .seconds(1),
19+
maxIterations: .kilo(10)
20+
)
1921

2022
Benchmark("InternalUTCClock-now") { benchmark in
2123
for _ in benchmark.scaledIterations {

0 commit comments

Comments
 (0)