realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.45k stars 2.2k forks source link

False positive of extension_access_modifier on property with private(set) #5623

Closed CraigSiemens closed 1 week ago

CraigSiemens commented 2 weeks ago

New Issue Checklist

Describe the bug

When a public extension has a single property with private(set), the property receives a warning that it should use an extension access modifier.

This isn't possible since private(set) cannot be moved from the property to the extension.

Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint
Linting Swift files in current working directory
Linting 'test.swift' (1/1)
test.swift:3:5: warning: Extension Access Modifier Violation: Prefer to use extension access modifiers (extension_access_modifier)
Done linting! Found 1 violation, 0 serious in 1 file.

Environment

opt_in_rules:
  - extension_access_modifier
public class Foo {}
public extension Foo {
    private(set) var value: Int {
        get { 1 }
        set {}
    }
}

Single line to run it

echo "class Foo {}\npublic extension Foo {\n    private(set) var value {\n        get { 0 }\n        set { print(newValue) }\n    }\n}" | swiftlint lint --no-cache --use-stdin --enable-all-rules