Skip to content

Commit 633fc25

Browse files
authored
Add unusedPrivateDeclaration rule (airbnb#284)
1 parent 1d7fa19 commit 633fc25

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4002,6 +4002,39 @@ _You can enable the following settings in Xcode by running [this script](resourc
40024002
```
40034003

40044004
</details>
4005+
4006+
* <a id='unused-private-declaration'></a>(<a href='#unused-private-declaration'>link</a>) **Remove unused private and fileprivate properties, functions, and typealiases** [![SwiftFormat: unusedPrivateDeclaration](https://img.shields.io/badge/SwiftFormat-unusedPrivateDeclaration-008489.svg)](https://github.com/nicklockwood/SwiftFormat/blob/master/Rules.md#unusedPrivateDeclaration)
4007+
4008+
<details>
4009+
4010+
#### Why?
4011+
4012+
Improves readability since the code has no effect and should be removed for clarity.
4013+
4014+
```swift
4015+
// WRONG: Includes private declarations that are unused
4016+
struct Planet {
4017+
var ageInBillionYears: Double {
4018+
ageInMillionYears / 1000
4019+
}
4020+
4021+
private var ageInMillionsOfYears: Double
4022+
private typealias Dependencies = UniverseBuilderProviding // unused
4023+
private var mass: Double // unused
4024+
private func distance(to: Planet) { } // unused
4025+
}
4026+
4027+
// RIGHT
4028+
struct Planet {
4029+
var ageInBillionsOfYears: Double {
4030+
ageInMillionYears / 1000
4031+
}
4032+
4033+
private var ageInMillionYears: Double
4034+
}
4035+
```
4036+
4037+
</details>
40054038

40064039
* <a id='remove-empty-extensions'></a>(<a href='#remove-empty-extensions'>link</a>) **Remove empty extensions that define no properties, functions, or conformances.** [![SwiftFormat: emptyExtension](https://img.shields.io/badge/SwiftFormat-emptyExtension-008489.svg)](https://github.com/nicklockwood/SwiftFormat/blob/master/Rules.md#emptyExtension)
40074040

Sources/AirbnbSwiftFormatTool/airbnb.swiftformat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,5 @@
109109
--rules semicolons
110110
--rules propertyType
111111
--rules blankLinesBetweenChainedFunctions
112+
--rules unusedPrivateDeclaration
112113
--rules emptyExtension

0 commit comments

Comments
 (0)