Skip to content

Commit

Permalink
Fix false positive in explicit_acl rule with Swift 5.2+
Browse files Browse the repository at this point in the history
Fixes #3186
  • Loading branch information
marcelofabri committed Aug 4, 2020
1 parent a4a0481 commit 2d7702f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
* Fix false positive uppercase enum case in `raw_value_for_camel_cased_codable_enum` rule
[Teameh](https://github.com/teameh)

* Fix false positive in `explicit_acl` rule when using `extension` with
Swift 5.2+.
[Marcelo Fabri](https://github.com/marcelofabri)
[#3186](https://github.com/realm/SwiftLint/issues/3186)

## 0.39.2: Stay Home

This is the last release to support building with Swift 5.0.x.
Expand Down
26 changes: 18 additions & 8 deletions Source/SwiftLintFramework/Rules/Idiomatic/ExplicitACLRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,25 @@ public struct ExplicitACLRule: OptInRule, ConfigurationProviderRule, AutomaticTe
"""),
Example("internal class A { deinit {} }"),
Example("extension A: Equatable {}"),
Example("extension A {}")
Example("extension A {}"),
Example("""
extension Foo {
internal func bar() {}
}
""")
],
triggeringExamples: [
Example("enum A {}\n"),
Example("final class B {}\n"),
Example("internal struct C { let d = 5 }\n"),
Example("public struct C { let d = 5 }\n"),
Example("enum A {}\n"),
Example("final class B {}\n"),
Example("internal struct C { let d = 5 }\n"),
Example("public struct C { let d = 5 }\n"),
Example("func a() {}\n"),
Example("internal let a = 0\nfunc b() {}\n")
Example("internal let a = 0\n↓func b() {}\n"),
Example("""
extension Foo {
↓func bar() {}
}
""")
]
)

Expand Down Expand Up @@ -91,7 +101,7 @@ public struct ExplicitACLRule: OptInRule, ConfigurationProviderRule, AutomaticTe
}

public func validate(file: SwiftLintFile) -> [StyleViolation] {
let implicitAndExplicitInternalElements = internalTypeElements(in: file.structureDictionary )
let implicitAndExplicitInternalElements = internalTypeElements(in: file.structureDictionary)

guard !implicitAndExplicitInternalElements.isEmpty else {
return []
Expand Down Expand Up @@ -129,7 +139,7 @@ public struct ExplicitACLRule: OptInRule, ConfigurationProviderRule, AutomaticTe
let internalTypeElementsInSubstructure = elementKind.childsAreExemptFromACL || isPrivate ? [] :
internalTypeElements(in: element)

if element.accessibility == .internal {
if element.accessibility == .internal || element.accessibility == nil {
return internalTypeElementsInSubstructure + [element]
}

Expand Down

0 comments on commit 2d7702f

Please sign in to comment.