Skip to content

Commit e88458f

Browse files
authored
Normalize indentation in code listings (#53)
Some parts of the book were written before Swift style was standardized for Swift 1. A bunch of code listings use 3 space indentation instead of 4 space indentation. There are also some `switch` statements whose cases are indented, following an older C-like style. In Swift, a case doesn't start a scope, so we write it at the same level of indentation. Under the legacy Sphinx-based publication pipeline, this wasn't an issue: The publication process used SourceKit to add syntax highlighting, which also reindented the code listings, so the published version matched Swift style. Because DocC preserves indentation, we needed to normalize these in source. Fixes #43 Fixes rdar://96988058
2 parents a348203 + 940f17d commit e88458f

34 files changed

+1570
-1570
lines changed

Sources/TSPL/TSPL.docc/GuidedTour/GuidedTour.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -514,14 +514,14 @@ and tests for equality.
514514
```swift
515515
let vegetable = "red pepper"
516516
switch vegetable {
517-
case "celery":
518-
print("Add some raisins and make ants on a log.")
519-
case "cucumber", "watercress":
520-
print("That would make a good tea sandwich.")
521-
case let x where x.hasSuffix("pepper"):
522-
print("Is it a spicy \(x)?")
523-
default:
524-
print("Everything tastes good in soup.")
517+
case "celery":
518+
print("Add some raisins and make ants on a log.")
519+
case "cucumber", "watercress":
520+
print("That would make a good tea sandwich.")
521+
case let x where x.hasSuffix("pepper"):
522+
print("Is it a spicy \(x)?")
523+
default:
524+
print("Everything tastes good in soup.")
525525
}
526526
// Prints "Is it a spicy red pepper?"
527527
```
@@ -1461,16 +1461,16 @@ enum Rank: Int {
14611461

14621462
func simpleDescription() -> String {
14631463
switch self {
1464-
case .ace:
1465-
return "ace"
1466-
case .jack:
1467-
return "jack"
1468-
case .queen:
1469-
return "queen"
1470-
case .king:
1471-
return "king"
1472-
default:
1473-
return String(self.rawValue)
1464+
case .ace:
1465+
return "ace"
1466+
case .jack:
1467+
return "jack"
1468+
case .queen:
1469+
return "queen"
1470+
case .king:
1471+
return "king"
1472+
default:
1473+
return String(self.rawValue)
14741474
}
14751475
}
14761476
}
@@ -1558,14 +1558,14 @@ enum Suit {
15581558

15591559
func simpleDescription() -> String {
15601560
switch self {
1561-
case .spades:
1562-
return "spades"
1563-
case .hearts:
1564-
return "hearts"
1565-
case .diamonds:
1566-
return "diamonds"
1567-
case .clubs:
1568-
return "clubs"
1561+
case .spades:
1562+
return "spades"
1563+
case .hearts:
1564+
return "hearts"
1565+
case .diamonds:
1566+
return "diamonds"
1567+
case .clubs:
1568+
return "clubs"
15691569
}
15701570
}
15711571
}
@@ -1681,10 +1681,10 @@ let success = ServerResponse.result("6:00 am", "8:09 pm")
16811681
let failure = ServerResponse.failure("Out of cheese.")
16821682

16831683
switch success {
1684-
case let .result(sunrise, sunset):
1685-
print("Sunrise is at \(sunrise) and sunset is at \(sunset).")
1686-
case let .failure(message):
1687-
print("Failure... \(message)")
1684+
case let .result(sunrise, sunset):
1685+
print("Sunrise is at \(sunrise) and sunset is at \(sunset).")
1686+
case let .failure(message):
1687+
print("Failure... \(message)")
16881688
}
16891689
// Prints "Sunrise is at 6:00 am and sunset is at 8:09 pm."
16901690
```

Sources/TSPL/TSPL.docc/LanguageGuide/AccessControl.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -230,25 +230,25 @@ the default access level of the type's members will be internal.
230230
231231
```swift
232232
public class SomePublicClass { // explicitly public class
233-
public var somePublicProperty = 0 // explicitly public class member
234-
var someInternalProperty = 0 // implicitly internal class member
235-
fileprivate func someFilePrivateMethod() {} // explicitly file-private class member
236-
private func somePrivateMethod() {} // explicitly private class member
233+
public var somePublicProperty = 0 // explicitly public class member
234+
var someInternalProperty = 0 // implicitly internal class member
235+
fileprivate func someFilePrivateMethod() {} // explicitly file-private class member
236+
private func somePrivateMethod() {} // explicitly private class member
237237
}
238238

239239
class SomeInternalClass { // implicitly internal class
240-
var someInternalProperty = 0 // implicitly internal class member
241-
fileprivate func someFilePrivateMethod() {} // explicitly file-private class member
242-
private func somePrivateMethod() {} // explicitly private class member
240+
var someInternalProperty = 0 // implicitly internal class member
241+
fileprivate func someFilePrivateMethod() {} // explicitly file-private class member
242+
private func somePrivateMethod() {} // explicitly private class member
243243
}
244244

245245
fileprivate class SomeFilePrivateClass { // explicitly file-private class
246-
func someFilePrivateMethod() {} // implicitly file-private class member
247-
private func somePrivateMethod() {} // explicitly private class member
246+
func someFilePrivateMethod() {} // implicitly file-private class member
247+
private func somePrivateMethod() {} // explicitly private class member
248248
}
249249

250250
private class SomePrivateClass { // explicitly private class
251-
func somePrivateMethod() {} // implicitly private class member
251+
func somePrivateMethod() {} // implicitly private class member
252252
}
253253
```
254254

@@ -378,7 +378,7 @@ In fact, `someFunction()` won't compile as written below:
378378

379379
```swift
380380
func someFunction() -> (SomeInternalClass, SomePrivateClass) {
381-
// function implementation goes here
381+
// function implementation goes here
382382
}
383383
```
384384

@@ -410,7 +410,7 @@ for the function declaration to be valid:
410410

411411
```swift
412412
private func someFunction() -> (SomeInternalClass, SomePrivateClass) {
413-
// function implementation goes here
413+
// function implementation goes here
414414
}
415415
```
416416

@@ -445,10 +445,10 @@ therefore also have an access level of public:
445445

446446
```swift
447447
public enum CompassPoint {
448-
case north
449-
case south
450-
case east
451-
case west
448+
case north
449+
case south
450+
case east
451+
case west
452452
}
453453
```
454454

@@ -668,11 +668,11 @@ the original implementation of `someMethod()`:
668668

669669
```swift
670670
public class A {
671-
fileprivate func someMethod() {}
671+
fileprivate func someMethod() {}
672672
}
673673

674674
internal class B: A {
675-
override internal func someMethod() {}
675+
override internal func someMethod() {}
676676
}
677677
```
678678

@@ -700,13 +700,13 @@ or within the same module as the superclass for an internal member call):
700700

701701
```swift
702702
public class A {
703-
fileprivate func someMethod() {}
703+
fileprivate func someMethod() {}
704704
}
705705

706706
internal class B: A {
707-
override internal func someMethod() {
708-
super.someMethod()
709-
}
707+
override internal func someMethod() {
708+
super.someMethod()
709+
}
710710
}
711711
```
712712

@@ -811,12 +811,12 @@ which keeps track of the number of times a string property is modified:
811811

812812
```swift
813813
struct TrackedString {
814-
private(set) var numberOfEdits = 0
815-
var value: String = "" {
816-
didSet {
817-
numberOfEdits += 1
818-
}
819-
}
814+
private(set) var numberOfEdits = 0
815+
var value: String = "" {
816+
didSet {
817+
numberOfEdits += 1
818+
}
819+
}
820820
}
821821
```
822822

@@ -923,13 +923,13 @@ by combining the `public` and `private(set)` access-level modifiers:
923923

924924
```swift
925925
public struct TrackedString {
926-
public private(set) var numberOfEdits = 0
927-
public var value: String = "" {
928-
didSet {
929-
numberOfEdits += 1
930-
}
931-
}
932-
public init() {}
926+
public private(set) var numberOfEdits = 0
927+
public var value: String = "" {
928+
didSet {
929+
numberOfEdits += 1
930+
}
931+
}
932+
public init() {}
933933
}
934934
```
935935

Sources/TSPL/TSPL.docc/LanguageGuide/AdvancedOperators.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ to add together instances of the `Vector2D` structure:
715715

716716
```swift
717717
struct Vector2D {
718-
var x = 0.0, y = 0.0
718+
var x = 0.0, y = 0.0
719719
}
720720

721721
extension Vector2D {
@@ -989,7 +989,7 @@ You can now use this operator to check whether two `Vector2D` instances are equi
989989
let twoThree = Vector2D(x: 2.0, y: 3.0)
990990
let anotherTwoThree = Vector2D(x: 2.0, y: 3.0)
991991
if twoThree == anotherTwoThree {
992-
print("These two vectors are equivalent.")
992+
print("These two vectors are equivalent.")
993993
}
994994
// Prints "These two vectors are equivalent."
995995
```
@@ -1047,10 +1047,10 @@ you add a type method called `+++` to `Vector2D` as follows:
10471047

10481048
```swift
10491049
extension Vector2D {
1050-
static prefix func +++ (vector: inout Vector2D) -> Vector2D {
1051-
vector += vector
1052-
return vector
1053-
}
1050+
static prefix func +++ (vector: inout Vector2D) -> Vector2D {
1051+
vector += vector
1052+
return vector
1053+
}
10541054
}
10551055

10561056
var toBeDoubled = Vector2D(x: 1.0, y: 4.0)
@@ -1099,9 +1099,9 @@ which belongs to the precedence group `AdditionPrecedence`:
10991099
```swift
11001100
infix operator +-: AdditionPrecedence
11011101
extension Vector2D {
1102-
static func +- (left: Vector2D, right: Vector2D) -> Vector2D {
1103-
return Vector2D(x: left.x + right.x, y: left.y - right.y)
1104-
}
1102+
static func +- (left: Vector2D, right: Vector2D) -> Vector2D {
1103+
return Vector2D(x: left.x + right.x, y: left.y - right.y)
1104+
}
11051105
}
11061106
let firstVector = Vector2D(x: 1.0, y: 2.0)
11071107
let secondVector = Vector2D(x: 3.0, y: 4.0)

0 commit comments

Comments
 (0)