Skip to content

Commit b50f877

Browse files
authored
Fix formatting (#116)
Motivation: bfcd4bb didn't go through the normal CI as it was a security fix. The CI is unhappy with some of the formatting in this change. Modifications: - Run the formatter Result: CI is happy
1 parent bfcd4bb commit b50f877

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

Sources/Prometheus/PrometheusCollectorRegistry.swift

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -578,11 +578,10 @@ extension [(String, String)] {
578578
}
579579

580580
fileprivate func ensureValidLabelNames() -> [(String, String)] {
581-
if self.allSatisfy({ $0.0.isValidLabelName() }) {
582-
return self
583-
} else {
581+
guard self.allSatisfy({ $0.0.isValidLabelName() }) else {
584582
return self.map { ($0.ensureValidLabelName(), $1) }
585583
}
584+
return self
586585
}
587586
}
588587

@@ -627,8 +626,8 @@ extension String {
627626
defer { isFirstCharacter = false }
628627
switch ascii {
629628
case UInt8(ascii: "A")...UInt8(ascii: "Z"),
630-
UInt8(ascii: "a")...UInt8(ascii: "z"),
631-
UInt8(ascii: "_"), UInt8(ascii: ":"):
629+
UInt8(ascii: "a")...UInt8(ascii: "z"),
630+
UInt8(ascii: "_"), UInt8(ascii: ":"):
632631
continue
633632
case UInt8(ascii: "0"), UInt8(ascii: "9"):
634633
if isFirstCharacter {
@@ -648,8 +647,8 @@ extension String {
648647
defer { isFirstCharacter = false }
649648
switch ascii {
650649
case UInt8(ascii: "A")...UInt8(ascii: "Z"),
651-
UInt8(ascii: "a")...UInt8(ascii: "z"),
652-
UInt8(ascii: "_"):
650+
UInt8(ascii: "a")...UInt8(ascii: "z"),
651+
UInt8(ascii: "_"):
653652
continue
654653
case UInt8(ascii: "0"), UInt8(ascii: "9"):
655654
if isFirstCharacter {
@@ -664,23 +663,21 @@ extension String {
664663
}
665664

666665
fileprivate func ensureValidMetricName() -> String {
667-
if self.isValidMetricName() {
668-
return self
669-
} else {
666+
guard self.isValidMetricName() else {
670667
var new = self
671668
new.fixPrometheusName(allowColon: true)
672669
return new
673670
}
671+
return self
674672
}
675673

676674
fileprivate func ensureValidLabelName() -> String {
677-
if self.isValidLabelName() {
678-
return self
679-
} else {
675+
guard self.isValidLabelName() else {
680676
var new = self
681677
new.fixPrometheusName(allowColon: false)
682678
return new
683679
}
680+
return self
684681
}
685682

686683
fileprivate mutating func fixPrometheusName(allowColon: Bool) {

Tests/PrometheusTests/ValidNamesTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final class ValidNamesTests: XCTestCase {
4242
"""
4343
name{bad="haha"} 121212121
4444
bad_bad 12321323
45-
"""
45+
""",
4646
]
4747

4848
for test in tests {

0 commit comments

Comments
 (0)