Skip to content

Commit a1deaae

Browse files
committed
Enable more rules by default
1 parent cc2d9ba commit a1deaae

30 files changed

+162
-188
lines changed

.swiftformat

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,7 @@
3737

3838
# rules
3939

40-
--enable unusedPrivateDeclarations
41-
--enable emptyExtensions
4240
--enable isEmpty
43-
--enable docComments
44-
# --enable noForceTryInTests
4541
# --enable noForceUnwrapInTests
4642
# --enable noGuardInTests
4743
--enable preferFinalClasses
48-
--enable redundantAsync
49-
--enable redundantEquatable
50-
--enable redundantMemberwiseInit
51-
--enable redundantProperty
52-
--enable redundantThrows

Rules.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@
99
* [blankLinesAtEndOfScope](#blankLinesAtEndOfScope)
1010
* [blankLinesAtStartOfScope](#blankLinesAtStartOfScope)
1111
* [blankLinesBetweenChainedFunctions](#blankLinesBetweenChainedFunctions)
12+
* [blankLinesBetweenImports](#blankLinesBetweenImports)
1213
* [blankLinesBetweenScopes](#blankLinesBetweenScopes)
1314
* [braces](#braces)
1415
* [conditionalAssignment](#conditionalAssignment)
1516
* [consecutiveBlankLines](#consecutiveBlankLines)
1617
* [consecutiveSpaces](#consecutiveSpaces)
1718
* [consistentSwitchCaseSpacing](#consistentSwitchCaseSpacing)
19+
* [docComments](#docComments)
1820
* [docCommentsBeforeModifiers](#docCommentsBeforeModifiers)
1921
* [duplicateImports](#duplicateImports)
2022
* [elseOnSameLine](#elseOnSameLine)
2123
* [emptyBraces](#emptyBraces)
24+
* [emptyExtensions](#emptyExtensions)
2225
* [enumNamespaces](#enumNamespaces)
26+
* [environmentEntry](#environmentEntry)
2327
* [extensionAccessControl](#extensionAccessControl)
2428
* [fileHeader](#fileHeader)
2529
* [fileMacro](#fileMacro)
@@ -35,31 +39,37 @@
3539
* [linebreaks](#linebreaks)
3640
* [modifierOrder](#modifierOrder)
3741
* [modifiersOnSameLine](#modifiersOnSameLine)
42+
* [noForceTryInTests](#noForceTryInTests)
3843
* [numberFormatting](#numberFormatting)
3944
* [opaqueGenericParameters](#opaqueGenericParameters)
4045
* [preferCountWhere](#preferCountWhere)
4146
* [preferForLoop](#preferForLoop)
4247
* [preferKeyPath](#preferKeyPath)
48+
* [redundantAsync](#redundantAsync)
4349
* [redundantBackticks](#redundantBackticks)
4450
* [redundantBreak](#redundantBreak)
4551
* [redundantClosure](#redundantClosure)
52+
* [redundantEquatable](#redundantEquatable)
4653
* [redundantExtensionACL](#redundantExtensionACL)
4754
* [redundantFileprivate](#redundantFileprivate)
4855
* [redundantGet](#redundantGet)
4956
* [redundantInit](#redundantInit)
5057
* [redundantInternal](#redundantInternal)
5158
* [redundantLet](#redundantLet)
5259
* [redundantLetError](#redundantLetError)
60+
* [redundantMemberwiseInit](#redundantMemberwiseInit)
5361
* [redundantNilInit](#redundantNilInit)
5462
* [redundantObjc](#redundantObjc)
5563
* [redundantOptionalBinding](#redundantOptionalBinding)
5664
* [redundantParens](#redundantParens)
5765
* [redundantPattern](#redundantPattern)
66+
* [redundantProperty](#redundantProperty)
5867
* [redundantPublic](#redundantPublic)
5968
* [redundantRawValues](#redundantRawValues)
6069
* [redundantReturn](#redundantReturn)
6170
* [redundantSelf](#redundantSelf)
6271
* [redundantStaticSelf](#redundantStaticSelf)
72+
* [redundantThrows](#redundantThrows)
6373
* [redundantType](#redundantType)
6474
* [redundantTypedThrows](#redundantTypedThrows)
6575
* [redundantVoidReturnType](#redundantVoidReturnType)
@@ -88,6 +98,7 @@
8898
* [trailingSpace](#trailingSpace)
8999
* [typeSugar](#typeSugar)
90100
* [unusedArguments](#unusedArguments)
101+
* [unusedPrivateDeclarations](#unusedPrivateDeclarations)
91102
* [void](#void)
92103
* [wrap](#wrap)
93104
* [wrapArguments](#wrapArguments)
@@ -102,31 +113,20 @@
102113
* [acronyms](#acronyms)
103114
* [blankLineAfterSwitchCase](#blankLineAfterSwitchCase)
104115
* [blankLinesAfterGuardStatements](#blankLinesAfterGuardStatements)
105-
* [blankLinesBetweenImports](#blankLinesBetweenImports)
106116
* [blockComments](#blockComments)
107-
* [docComments](#docComments)
108-
* [emptyExtensions](#emptyExtensions)
109-
* [environmentEntry](#environmentEntry)
110117
* [isEmpty](#isEmpty)
111118
* [markTypes](#markTypes)
112119
* [noExplicitOwnership](#noExplicitOwnership)
113-
* [noForceTryInTests](#noForceTryInTests)
114120
* [noForceUnwrapInTests](#noForceUnwrapInTests)
115121
* [noGuardInTests](#noGuardInTests)
116122
* [organizeDeclarations](#organizeDeclarations)
117123
* [preferFinalClasses](#preferFinalClasses)
118124
* [preferSwiftTesting](#preferSwiftTesting)
119125
* [privateStateVariables](#privateStateVariables)
120126
* [propertyTypes](#propertyTypes)
121-
* [redundantAsync](#redundantAsync)
122-
* [redundantEquatable](#redundantEquatable)
123-
* [redundantMemberwiseInit](#redundantMemberwiseInit)
124-
* [redundantProperty](#redundantProperty)
125-
* [redundantThrows](#redundantThrows)
126127
* [singlePropertyPerLine](#singlePropertyPerLine)
127128
* [sortSwitchCases](#sortSwitchCases)
128129
* [testSuiteAccessControl](#testSuiteAccessControl)
129-
* [unusedPrivateDeclarations](#unusedPrivateDeclarations)
130130
* [urlMacro](#urlMacro)
131131
* [validateTestCases](#validateTestCases)
132132
* [wrapConditionalBodies](#wrapConditionalBodies)
@@ -1008,7 +1008,7 @@ Option | Description
10081008

10091009
## emptyExtensions
10101010

1011-
Remove empty, non-conforming, extensions.
1011+
Remove empty, non-protocol-conforming extensions.
10121012

10131013
<details>
10141014
<summary>Examples</summary>

Snapshots/Consumer/LinuxMain.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import XCTest
2-
31
import ConsumerTests
2+
import XCTest
43

54
var tests = [XCTestCaseEntry]()
65
tests += ConsumerTests.__allTests()

Snapshots/Euclid/LinuxMain.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import XCTest
2-
31
import EuclidTests
2+
import XCTest
43

54
var tests = [XCTestCaseEntry]()
65
tests += EuclidTests.__allTests()

Snapshots/Expression/LinuxMain.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import XCTest
2-
31
import ExpressionTests
2+
import XCTest
43

54
var tests = [XCTestCaseEntry]()
65
tests += ExpressionTests.__allTests()

Snapshots/Layout/LayoutTests/AttributedStringExpressionTests.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,100 +4,100 @@ import XCTest
44
@testable import Layout
55

66
final class AttributedStringExpressionTests: XCTestCase {
7-
func testAttributedStringExpressionTextAndFont() {
7+
func testAttributedStringExpressionTextAndFont() throws {
88
let node = LayoutNode()
99
let expression = LayoutExpression(attributedStringExpression: "foo", for: node)
10-
let result = try! expression?.evaluate() as! NSAttributedString
10+
let result = try expression?.evaluate() as! NSAttributedString
1111
XCTAssertEqual(result.string, "foo")
1212
XCTAssertEqual(result.attribute(NSAttributedString.Key.font, at: 0, effectiveRange: nil) as? UIFont, .systemFont(ofSize: 17))
1313
}
1414

15-
func testAttributedStringHTMLExpression() {
15+
func testAttributedStringHTMLExpression() throws {
1616
let node = LayoutNode()
1717
let expression = LayoutExpression(attributedStringExpression: "<b>foo</b>", for: node)
18-
let result = try! expression?.evaluate() as! NSAttributedString
18+
let result = try expression?.evaluate() as! NSAttributedString
1919
XCTAssertEqual(result.string, "foo")
2020
XCTAssertEqual(result.attribute(NSAttributedString.Key.font, at: 0, effectiveRange: nil) as? UIFont, .boldSystemFont(ofSize: 17))
2121
}
2222

23-
func testAttributedStringContainingUnicode() {
23+
func testAttributedStringContainingUnicode() throws {
2424
let node = LayoutNode()
2525
let text = "🤔😂"
2626
let expression = LayoutExpression(attributedStringExpression: "<i>\(text)</i>", for: node)
27-
let result = try! expression?.evaluate() as! NSAttributedString
27+
let result = try expression?.evaluate() as! NSAttributedString
2828
XCTAssertEqual(result.string, text)
2929
}
3030

31-
func testAttributedStringInheritsFont() {
31+
func testAttributedStringInheritsFont() throws {
3232
let label = UILabel()
3333
label.font = UIFont(name: "Courier", size: 57)
3434
let node = LayoutNode(view: label)
3535
let expression = LayoutExpression(attributedStringExpression: "foo", for: node)
36-
let result = try! expression?.evaluate() as! NSAttributedString
36+
let result = try expression?.evaluate() as! NSAttributedString
3737
XCTAssertEqual(result.attribute(NSAttributedString.Key.font, at: 0, effectiveRange: nil) as? UIFont, label.font)
3838
}
3939

40-
func testAttributedStringInheritsTextColor() {
40+
func testAttributedStringInheritsTextColor() throws {
4141
let label = UILabel()
4242
label.textColor = .red
4343
let node = LayoutNode(view: label)
4444
let expression = LayoutExpression(attributedStringExpression: "foo", for: node)
45-
let result = try! expression?.evaluate() as! NSAttributedString
45+
let result = try expression?.evaluate() as! NSAttributedString
4646
XCTAssertEqual(result.attribute(NSAttributedString.Key.foregroundColor, at: 0, effectiveRange: nil) as? UIColor, .red)
4747
}
4848

49-
func testAttributedStringInheritsTextAlignment() {
49+
func testAttributedStringInheritsTextAlignment() throws {
5050
let label = UILabel()
5151
label.textAlignment = .right
5252
let node = LayoutNode(view: label)
5353
let expression = LayoutExpression(attributedStringExpression: "foo", for: node)
54-
let result = try! expression?.evaluate() as! NSAttributedString
54+
let result = try expression?.evaluate() as! NSAttributedString
5555
let paragraphStyle = result.attribute(NSAttributedString.Key.paragraphStyle, at: 0, effectiveRange: nil) as! NSParagraphStyle
5656
XCTAssertEqual(paragraphStyle.alignment, .right)
5757
}
5858

59-
func testAttributedStringInheritsLinebreakMode() {
59+
func testAttributedStringInheritsLinebreakMode() throws {
6060
let label = UILabel()
6161
label.lineBreakMode = .byTruncatingHead
6262
let node = LayoutNode(view: label)
6363
let expression = LayoutExpression(attributedStringExpression: "foo", for: node)
64-
let result = try! expression?.evaluate() as! NSAttributedString
64+
let result = try expression?.evaluate() as! NSAttributedString
6565
let paragraphStyle = result.attribute(NSAttributedString.Key.paragraphStyle, at: 0, effectiveRange: nil) as! NSParagraphStyle
6666
XCTAssertEqual(paragraphStyle.lineBreakMode, .byTruncatingHead)
6767
}
6868

69-
func testAttributedStringContainingStringConstant() {
69+
func testAttributedStringContainingStringConstant() throws {
7070
let node = LayoutNode(constants: ["bar": "bar"])
7171
let expression = LayoutExpression(attributedStringExpression: "hello world {bar}", for: node)
72-
let result = try! expression?.evaluate() as! NSAttributedString
72+
let result = try expression?.evaluate() as! NSAttributedString
7373
XCTAssertEqual(result.string, "hello world bar")
7474
}
7575

76-
func testAttributedStringContainingAttributedStringConstant() {
76+
func testAttributedStringContainingAttributedStringConstant() throws {
7777
let node = LayoutNode(constants: ["bar": NSAttributedString(string: "bar", attributes: [
7878
NSAttributedString.Key.foregroundColor: UIColor.red,
7979
])])
8080
let expression = LayoutExpression(attributedStringExpression: "hello world {bar}", for: node)
81-
let result = try! expression?.evaluate() as! NSAttributedString
81+
let result = try expression?.evaluate() as! NSAttributedString
8282
XCTAssertEqual(result.string, "hello world bar")
8383
XCTAssertEqual(result.attribute(NSAttributedString.Key.foregroundColor, at: 12, effectiveRange: nil) as? UIColor, .red)
8484
}
8585

86-
func testAttributedStringContainingHTMLConstant() {
86+
func testAttributedStringContainingHTMLConstant() throws {
8787
let node = LayoutNode(constants: ["bar": "<i>bar</i>"])
8888
let expression = LayoutExpression(attributedStringExpression: "<b>foo {bar}</b>", for: node)
89-
let result = try! expression?.evaluate() as! NSAttributedString
89+
let result = try expression?.evaluate() as! NSAttributedString
9090
XCTAssertEqual(result.string, "foo bar")
9191
XCTAssertEqual(result.attribute(NSAttributedString.Key.font, at: 0, effectiveRange: nil) as? UIFont, .boldSystemFont(ofSize: 17))
9292
let traits = (result.attribute(NSAttributedString.Key.font, at: 4, effectiveRange: nil) as? UIFont)?.fontDescriptor.symbolicTraits
9393
XCTAssert(traits?.contains(.traitItalic) == true)
9494
XCTAssert(traits?.contains(.traitBold) == true)
9595
}
9696

97-
func testAttributedStringContainingAmbiguousTokens() {
97+
func testAttributedStringContainingAmbiguousTokens() throws {
9898
let node = LayoutNode(constants: ["foo": "$(2)", "bar": "$(3)"])
9999
let expression = LayoutExpression(attributedStringExpression: "<b>$(1)</b>{foo}{bar}", for: node)
100-
let result = try! expression?.evaluate() as! NSAttributedString
100+
let result = try expression?.evaluate() as! NSAttributedString
101101
XCTAssertEqual(result.string, "$(1)$(2)$(3)")
102102
}
103103
}

Snapshots/Layout/LayoutTests/FontExpressionTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ final class FontExpressionTests: XCTestCase {
292292
XCTAssertEqual(try (expression?.evaluate() as? UIFont)?.fontWeight, .heavy)
293293
}
294294

295-
func testBuiltInFontWeights() {
295+
func testBuiltInFontWeights() throws {
296296
let node = LayoutNode()
297297
for familyName in UIFont.familyNames {
298298
for weightKey in RuntimeType.uiFont_Weight.values.keys {
@@ -301,7 +301,7 @@ final class FontExpressionTests: XCTestCase {
301301
$0.lowercased().contains("-\(weightKey.lowercased())")
302302
}
303303
if !expected.isEmpty {
304-
let name = try! (expression!.evaluate() as! UIFont).fontName
304+
let name = try (expression!.evaluate() as! UIFont).fontName
305305
XCTAssertTrue(expected.contains(name), "\(expected) does not contain \(name)")
306306
}
307307
}

Snapshots/Layout/LayoutTests/LayoutExpressionTests.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -538,65 +538,65 @@ final class LayoutExpressionTests: XCTestCase {
538538
XCTAssertEqual(try expression?.evaluate() as! Double, 17)
539539
}
540540

541-
func testLiteralParameter() {
541+
func testLiteralParameter() throws {
542542
let layout = makeLayout(
543543
expressions: ["foo": "5"],
544544
parameters: ["foo": RuntimeType(Int.self)],
545545
children: [
546546
makeLayout(),
547547
]
548548
)
549-
let parent = try! LayoutNode(layout: layout)
549+
let parent = try LayoutNode(layout: layout)
550550
let child = parent.children[0]
551551
parent.update()
552552
let expression = LayoutExpression(doubleExpression: "foo + 6", for: child)
553553
XCTAssertEqual(expression?.isConstant, true)
554554
XCTAssertEqual(try expression?.evaluate() as! Double, 11)
555555
}
556556

557-
func testConstantParameter() {
557+
func testConstantParameter() throws {
558558
let layout = makeLayout(
559559
expressions: ["foo": "bar + 3"],
560560
parameters: ["foo": RuntimeType(Int.self)],
561561
children: [
562562
makeLayout(),
563563
]
564564
)
565-
let parent = try! LayoutNode(layout: layout, constants: ["bar": 5])
565+
let parent = try LayoutNode(layout: layout, constants: ["bar": 5])
566566
let child = parent.children[0]
567567
parent.update()
568568
let expression = LayoutExpression(doubleExpression: "foo + 6", for: child)
569569
XCTAssertEqual(expression?.isConstant, true)
570570
XCTAssertEqual(try expression?.evaluate() as! Double, 14)
571571
}
572572

573-
func testLiteralMacro() {
573+
func testLiteralMacro() throws {
574574
let layout = makeLayout(
575575
macros: ["BAR": "5"],
576576
children: [
577577
makeLayout(),
578578
]
579579
)
580-
let parent = try! LayoutNode(layout: layout)
580+
let parent = try LayoutNode(layout: layout)
581581
let child = parent.children[0]
582582
parent.update()
583583
let expression = LayoutExpression(doubleExpression: "BAR + 6", for: child)
584584
XCTAssertEqual(expression?.isConstant, true)
585585
XCTAssertEqual(try expression?.evaluate() as! Double, 11)
586586
}
587587

588-
func testArrayMacro() {
588+
func testArrayMacro() throws {
589589
let layout = makeLayout(macros: ["ITEMS": "1,2,3"])
590-
let node = try! LayoutNode(layout: layout)
590+
let node = try LayoutNode(layout: layout)
591591
node.update()
592592
let expression = LayoutExpression(doubleExpression: "ITEMS[1]", for: node)
593593
XCTAssertEqual(expression?.isConstant, true)
594594
XCTAssertEqual(try expression?.evaluate() as! Double, 2)
595595
}
596596

597-
func testArrayMacro2() {
597+
func testArrayMacro2() throws {
598598
let layout = makeLayout(macros: ["ITEMS": "[1,2,3]"])
599-
let node = try! LayoutNode(layout: layout)
599+
let node = try LayoutNode(layout: layout)
600600
node.update()
601601
let expression = LayoutExpression(doubleExpression: "ITEMS[1]", for: node)
602602
XCTAssertEqual(expression?.isConstant, true)

0 commit comments

Comments
 (0)