Skip to content

Commit

Permalink
Fix implicit_getter false positive in case of unknown accessors (re…
Browse files Browse the repository at this point in the history
  • Loading branch information
kabiroberai authored and u-abyss committed Dec 16, 2023
1 parent b91df18 commit 6a4920d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -54,6 +54,10 @@

#### Bug Fixes

* Fix false positive in `implicit_getter` rule when using unknown accessors.
[kabiroberai](https://github.com/kabiroberai)
[#5300](https://github.com/realm/SwiftLint/issues/5300)

* Fix correction of `explicit_init` rule by keeping significant trivia.
[BB9z](https://github.com/BB9z)
[#5289](https://github.com/realm/SwiftLint/issues/5289)
Expand Down
Expand Up @@ -30,8 +30,8 @@ private enum ViolationKind {
private extension ImplicitGetterRule {
final class Visitor: ViolationsSyntaxVisitor<ConfigurationType> {
override func visitPost(_ node: AccessorBlockSyntax) {
guard let getAccessor = node.getAccessor,
node.setAccessor == nil,
guard node.accessorsList.count == 1,
let getAccessor = node.getAccessor,
getAccessor.effectSpecifiers == nil,
getAccessor.modifier == nil,
getAccessor.attributes.isEmpty == true,
Expand Down
Expand Up @@ -30,6 +30,24 @@ struct ImplicitGetterRuleExamples {
}
}
"""),
Example("""
class Foo {
var foo: Int {
get { _foo }
_modify { yield &_foo }
}
}
"""),
Example("""
class Foo {
var _foo: Int
var foo: Int {
@storageRestrictions(initializes: _foo)
init { _foo = newValue }
get { _foo }
}
}
"""),
Example("""
class Foo {
var foo: Int
Expand Down
Expand Up @@ -397,7 +397,7 @@ public struct ConfigurationElement<T: AcceptableByConfigurationElement & Equatab
/// The wrapper itself providing access to all its data. This field can only be accessed by the
/// element's name prefixed with a `$`.
public var projectedValue: ConfigurationElement {
get { self } // swiftlint:disable:this implicit_getter
get { self }
_modify { yield &self }
}

Expand Down

0 comments on commit 6a4920d

Please sign in to comment.