You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+91-14
Original file line number
Diff line number
Diff line change
@@ -1647,7 +1647,9 @@ _You can enable the following settings in Xcode by running [this script](resourc
1647
1647
}
1648
1648
```
1649
1649
1650
-
*<a id='doc-comments'></a>(<a href='#doc-comments'>link</a>) Use doc comments (`///`) before declarations, and regular comments (`//`) elsewhere. [](https://github.com/nicklockwood/SwiftFormat/blob/master/Rules.md#docComments)
1650
+
</details>
1651
+
1652
+
*<a id='doc-comments-before-declarations'></a>(<a href='#doc-comments-before-declarations'>link</a>) **Use doc comments (`///`) instead of regular comments (`//`) before declarations within type bodies or at the top level.** [](https://github.com/nicklockwood/SwiftFormat/blob/master/Rules.md#docComments)
1651
1653
1652
1654
<details>
1653
1655
@@ -1656,16 +1658,18 @@ _You can enable the following settings in Xcode by running [this script](resourc
1656
1658
1657
1659
// A planet that exists somewhere in the universe.
1658
1660
classPlanet {
1659
-
// Properties of a planet that are important for life
1660
-
let atmosphere: Atmosphere
1661
-
let oceans: [Ocean]
1661
+
// Data about the composition and density of the planet's atmosphere if present.
1662
+
var atmosphere: Atmosphere?
1662
1663
1663
-
// Terraforms the planet, by adding an atmosphere and ocean that is hospitable for life.
1664
+
// Data about the size, location, and composition of large bodies of water on the planet's surface.
1665
+
var oceans: [Ocean]
1666
+
1667
+
/// Terraforms the planet, by adding an atmosphere and ocean that is hospitable for life.
1664
1668
functerraform() {
1665
-
/// This gas concentration has a pretty good track record so far
1669
+
// This gas concentration has a pretty good track record so far
1666
1670
let configuration =AtmosphereConfiguration(nitrogen: 0.78, oxygen: 0.22)
1667
-
1668
-
/// Generate the atmosphere first, then the oceans
1671
+
1672
+
// Generate the atmosphere first, then the oceans. Otherwise, the water will just boil off immediately.
1669
1673
generateAtmosphere(using: configuration)
1670
1674
generateOceans()
1671
1675
}
@@ -1675,20 +1679,93 @@ _You can enable the following settings in Xcode by running [this script](resourc
1675
1679
1676
1680
/// A planet that exists somewhere in the universe.
1677
1681
classPlanet {
1678
-
/// Properties of a planet that are important for life
1679
-
let atmosphere: Atmosphere
1680
-
let oceans: [Ocean]
1682
+
/// Data about the composition and density of the planet's atmosphere if present.
1683
+
var atmosphere: Atmosphere?
1684
+
1685
+
/// Data about the size, location, and composition of large bodies of water on the planet's surface.
1686
+
var oceans: [Ocean]
1681
1687
1682
1688
/// Terraforms the planet, by adding an atmosphere and ocean that is hospitable for life.
1683
1689
functerraform() {
1684
-
// This gas concentration has a pretty good track record so far
1690
+
// This gas concentration has a pretty good track record so far.
1685
1691
let configuration =AtmosphereConfiguration(nitrogen: 0.78, oxygen: 0.22)
1686
-
1687
-
// Generate the atmosphere first, then the oceans
1692
+
1693
+
// Generate the atmosphere first, then the oceans. Otherwise, the water will just boil off immediately.
1688
1694
generateAtmosphere(using: configuration)
1689
1695
generateOceans()
1690
1696
}
1691
1697
}
1698
+
1699
+
// ALSO RIGHT:
1700
+
1701
+
functerraform() {
1702
+
/// This gas concentration has a pretty good track record so far
1703
+
/// - Doc comments are not required before local declarations in function scopes, but are permitted.
1704
+
let configuration =AtmosphereConfiguration(nitrogen: 0.78, oxygen: 0.22)
1705
+
1706
+
/// Generate the `atmosphere` first, **then** the `oceans`. Otherwise, the water will just boil off immediately.
1707
+
/// - Comments not preceeding declarations can use doc comments, and will not be autocorrected into regular comments.
1708
+
/// This can be useful because Xcode applies markdown styling to doc comments but not regular comments.
1709
+
generateAtmosphere(using: configuration)
1710
+
generateOceans()
1711
+
}
1712
+
```
1713
+
1714
+
Regular comments are permitted before declarations in some cases.
1715
+
1716
+
For example, comment directives like `// swiftformat:`, `// swiftlint:`, `// sourcery:`, `// MARK:` and `// TODO:` are typically required to use regular comments and don't work correctly with doc comments:
1717
+
1718
+
```swift
1719
+
// RIGHT
1720
+
1721
+
// swiftformat:sort
1722
+
enumFeatureFlags {
1723
+
case allowFasterThanLightTravel
1724
+
case disableGravity
1725
+
case enableDarkEnergy
1726
+
case enableDarkMatter
1727
+
}
1728
+
1729
+
// TODO: There are no more production consumers of this legacy model, so we
1730
+
// should detangle the remaining code dependencies and clean it up.
1731
+
structLegacyGeocentricUniverseModel {
1732
+
...
1733
+
}
1734
+
```
1735
+
1736
+
Regular comments are also allowed before a grouped block of delcarations, since it's possible that the comment refers to the block as a whole rather than just the following declaration:
0 commit comments