Skip to content

Commit 9c8eb47

Browse files
committed
Enable preferForLoop by default
1 parent b4910bf commit 9c8eb47

File tree

7 files changed

+31
-32
lines changed

7 files changed

+31
-32
lines changed

EditorExtension/Shared/RulesStore.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ extension RulesStore {
165165

166166
let disabledRules = Set(FormatRules.disabledByDefault)
167167
var rules = currentRules
168-
newRuleNames.forEach {
169-
rules[$0] = !disabledRules.contains($0)
168+
for newRuleName in newRuleNames {
169+
rules[newRuleName] = !disabledRules.contains(newRuleName)
170170
}
171171

172172
save(rules)

Rules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* [modifierOrder](#modifierOrder)
3232
* [numberFormatting](#numberFormatting)
3333
* [opaqueGenericParameters](#opaqueGenericParameters)
34+
* [preferForLoop](#preferForLoop)
3435
* [preferKeyPath](#preferKeyPath)
3536
* [redundantBackticks](#redundantBackticks)
3637
* [redundantBreak](#redundantBreak)
@@ -95,7 +96,6 @@
9596
* [isEmpty](#isEmpty)
9697
* [markTypes](#markTypes)
9798
* [organizeDeclarations](#organizeDeclarations)
98-
* [preferForLoop](#preferForLoop)
9999
* [sortSwitchCases](#sortSwitchCases)
100100
* [wrapConditionalBodies](#wrapConditionalBodies)
101101
* [wrapEnumCases](#wrapEnumCases)

Snapshots/Euclid/Sources/CSG.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,8 @@ extension Polygon {
482482
{
483483
precondition(isConvex)
484484
guard polygon.isConvex else {
485-
polygon.tessellate().forEach {
486-
clip($0, &inside, &outside, &id)
485+
for item in polygon.tessellate() {
486+
clip(item, &inside, &outside, &id)
487487
}
488488
return
489489
}
@@ -538,8 +538,8 @@ extension Polygon {
538538
polygon.id = id
539539
}
540540
if !polygon.isConvex {
541-
polygon.tessellate().forEach {
542-
$0.split(along: plane, &coplanar, &front, &back, &id)
541+
for item in polygon.tessellate() {
542+
item.split(along: plane, &coplanar, &front, &back, &id)
543543
}
544544
return
545545
}

Snapshots/Issues/780.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -977,8 +977,8 @@ public extension SNS {
977977
public func validate(name: String) throws {
978978
try validate(resourceArn, name: "resourceArn", parent: name, max: 1011)
979979
try validate(resourceArn, name: "resourceArn", parent: name, min: 1)
980-
try tags.forEach {
981-
try $0.validate(name: "\(name).tags[]")
980+
for tag in tags {
981+
try tag.validate(name: "\(name).tags[]")
982982
}
983983
}
984984

@@ -1033,9 +1033,9 @@ public extension SNS {
10331033
public func validate(name: String) throws {
10341034
try validate(resourceArn, name: "resourceArn", parent: name, max: 1011)
10351035
try validate(resourceArn, name: "resourceArn", parent: name, min: 1)
1036-
try tagKeys.forEach {
1037-
try validate($0, name: "tagKeys[]", parent: name, max: 128)
1038-
try validate($0, name: "tagKeys[]", parent: name, min: 1)
1036+
for tagKey in tagKeys {
1037+
try validate(tagKey, name: "tagKeys[]", parent: name, max: 128)
1038+
try validate(tagKey, name: "tagKeys[]", parent: name, min: 1)
10391039
}
10401040
}
10411041

Sources/Rules.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private let rulesByName: [String: FormatRule] = {
103103
while changedOrder {
104104
changedOrder = false
105105
for value in values {
106-
value.orderAfter.forEach { name in
106+
for name in value.orderAfter {
107107
guard let rule = rules[name] else {
108108
preconditionFailure(name)
109109
}
@@ -7299,7 +7299,6 @@ public struct _FormatRules {
72997299

73007300
public let preferForLoop = FormatRule(
73017301
help: "Convert functional `forEach` calls to for loops.",
7302-
disabledByDefault: true,
73037302
options: ["anonymousforeach", "onelineforeach"]
73047303
) { formatter in
73057304
formatter.forEach(.identifier("forEach")) { forEachIndex, _ in

Tests/CommandLineTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class CommandLineTests: XCTestCase {
261261

262262
func testHelpLineLength() {
263263
CLI.print = { message, _ in
264-
message.components(separatedBy: "\n").forEach { line in
264+
for line in message.components(separatedBy: "\n") {
265265
XCTAssertLessThanOrEqual(line.count, 80, line)
266266
}
267267
}

Tests/OptionDescriptorTests.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ class OptionDescriptorTests: XCTestCase {
3333
testName: String = #function)
3434
{
3535
var options = FormatOptions.default
36-
expectations.forEach {
36+
for expectation in expectations {
3737
do {
38-
try descriptor.toOptions($0.argumentValue, &options)
39-
XCTAssertEqual(options[keyPath: keyPath], $0.optionValue, "\(testName): Argument \($0.argumentValue) map to option \($0.optionValue)")
40-
try descriptor.toOptions($0.argumentValue.uppercased(), &options)
41-
XCTAssertEqual(options[keyPath: keyPath], $0.optionValue, "\(testName): Argument Uppercased \($0.argumentValue) map to option \($0.optionValue)")
42-
try descriptor.toOptions($0.argumentValue.capitalized, &options)
43-
XCTAssertEqual(options[keyPath: keyPath], $0.optionValue, "\(testName): Argument capitalized \($0.argumentValue) map to option \($0.optionValue)")
38+
try descriptor.toOptions(expectation.argumentValue, &options)
39+
XCTAssertEqual(options[keyPath: keyPath], expectation.optionValue, "\(testName): Argument \(expectation.argumentValue) map to option \(expectation.optionValue)")
40+
try descriptor.toOptions(expectation.argumentValue.uppercased(), &options)
41+
XCTAssertEqual(options[keyPath: keyPath], expectation.optionValue, "\(testName): Argument Uppercased \(expectation.argumentValue) map to option \(expectation.optionValue)")
42+
try descriptor.toOptions(expectation.argumentValue.capitalized, &options)
43+
XCTAssertEqual(options[keyPath: keyPath], expectation.optionValue, "\(testName): Argument capitalized \(expectation.argumentValue) map to option \(expectation.optionValue)")
4444
} catch {
4545
XCTFail("\(testName): error: \(error)")
4646
}
@@ -54,16 +54,16 @@ class OptionDescriptorTests: XCTestCase {
5454
testName: String = #function)
5555
{
5656
var options = FormatOptions.default
57-
expectations.forEach {
57+
for expectation in expectations {
5858
do {
59-
try descriptor.toOptions($0.argumentValue, &options)
60-
XCTAssertEqual(options[keyPath: keyPath], $0.optionValue, "\(testName): Argument \($0.argumentValue) map to option \(String(describing: $0.optionValue))")
59+
try descriptor.toOptions(expectation.argumentValue, &options)
60+
XCTAssertEqual(options[keyPath: keyPath], expectation.optionValue, "\(testName): Argument \(expectation.argumentValue) map to option \(String(describing: expectation.optionValue))")
6161
if testCaseVariation {
6262
do {
63-
try descriptor.toOptions($0.argumentValue.uppercased(), &options)
64-
XCTAssertEqual(options[keyPath: keyPath], $0.optionValue, "\(testName): Argument Uppercased \($0.argumentValue) map to option \(String(describing: $0.optionValue))")
65-
try descriptor.toOptions($0.argumentValue.capitalized, &options)
66-
XCTAssertEqual(options[keyPath: keyPath], $0.optionValue, "\(testName): Argument capitalized \($0.argumentValue) map to option \(String(describing: $0.optionValue))")
63+
try descriptor.toOptions(expectation.argumentValue.uppercased(), &options)
64+
XCTAssertEqual(options[keyPath: keyPath], expectation.optionValue, "\(testName): Argument Uppercased \(expectation.argumentValue) map to option \(String(describing: expectation.optionValue))")
65+
try descriptor.toOptions(expectation.argumentValue.capitalized, &options)
66+
XCTAssertEqual(options[keyPath: keyPath], expectation.optionValue, "\(testName): Argument capitalized \(expectation.argumentValue) map to option \(String(describing: expectation.optionValue))")
6767
} catch {
6868
XCTFail("\(testName): error: \(error)")
6969
}
@@ -106,9 +106,9 @@ class OptionDescriptorTests: XCTestCase {
106106
expectations: [FreeTextValidationExpectation],
107107
testName: String = #function)
108108
{
109-
expectations.forEach {
110-
let isValid = descriptor.validateArgument($0.input)
111-
XCTAssertEqual(isValid, $0.isValid, "\(testName): \(isValid) != \($0.isValid)")
109+
for expectation in expectations {
110+
let isValid = descriptor.validateArgument(expectation.input)
111+
XCTAssertEqual(isValid, expectation.isValid, "\(testName): \(isValid) != \(expectation.isValid)")
112112
}
113113
}
114114

0 commit comments

Comments
 (0)