Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix implicit_getter false positive #5300

Merged
merged 7 commits into from Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -49,6 +49,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)
SimplyDanny marked this conversation as resolved.
Show resolved Hide resolved
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