Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
[Hokila](https://github.com/Hokila)
[#6897](https://github.com/realm/SwiftLint/issues/6897)

* Stop `prefer_self_in_static_references` from reporting types referenced with
a module selector such as `Foundation::TimeInterval`, which name a type from
that module rather than the surrounding type.
[SwastikTripathi](https://github.com/SwastikTripathi)
[#6924](https://github.com/realm/SwiftLint/issues/6924)

## 0.65.1: Fresh Folded Fixtures

### Breaking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ private extension PreferSelfInStaticReferencesRule {

override func visitPost(_ node: DeclReferenceExprSyntax) {
guard let parent = node.parent, !parent.is(GenericSpecializationExprSyntax.self),
node.keyPathInParent != \MemberAccessExprSyntax.declName else {
node.keyPathInParent != \MemberAccessExprSyntax.declName,
node.moduleSelector == nil else {
return
}
if parent.is(FunctionCallExprSyntax.self), case .likeClass = parentDeclScopes.peek() {
Expand Down Expand Up @@ -293,7 +294,9 @@ private extension PreferSelfInStaticReferencesRule {
}

override func visitPost(_ node: IdentifierTypeSyntax) {
guard let parent = node.parent else {
// A module selector (`Module::Name`) names a type from that module,
// which isn't necessarily the surrounding type.
guard let parent = node.parent, node.moduleSelector == nil else {
return
}
// Don't flag identifiers that belong to the extension declaration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,19 @@ enum PreferSelfInStaticReferencesRuleExamples {
}
}
""".asExample(excludeFromDocumentation: true),
"""
enum TimeInterval {
private static func defaultInterval() -> Foundation::TimeInterval {
.init()
}
}
""".asExample(excludeFromDocumentation: true),
"""
struct Date {
static let reference = Foundation::Date.distantPast
static let parsed: Foundation::Date? = nil
}
""".asExample(excludeFromDocumentation: true),
])

static let triggeringExamples = #examples([
Expand Down