Skip to content

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

@CraigSiemens

Description

@CraigSiemens

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

  • SwiftLint version (run swiftlint version to be sure)? 0.55.1
  • Installation method used (Homebrew, CocoaPods, building from source, etc)? homebrew
  • Paste your configuration file: n/a
opt_in_rules:
  - extension_access_modifier
  • Are you using nested configurations? No
    If so, paste their relative paths and respective contents.
  • Which Xcode version are you using (check xcodebuild -version)? 15.4
  • Do you have a sample that shows the issue? Yes
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  

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUnexpected and reproducible misbehavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions