explicit_acl should not be triggered for extensions adding protocol conformance #2705
Closed
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
Describe the bug
Swiftlint tells me that I need to add an access control level for an extension that adds protocol conformance. However, the Swift compiler won't allow me to do that -- when I try to build I get
error: 'public' modifier cannot be used with extensions that declare protocol conformances
. (Note I get an equivalent error if I use any other ACL, private
, internal
, etc.)
This can be reproduced in a directory containing just the following two files:
lint.swift
public struct MyStruct {}
extension MyStruct: Equatable {}
.swiftlint.yml
opt_in_rules:
- explicit_acl
Complete output when running SwiftLint, including the stack trace and command used
kaitlinmahar@kaitlin:~/lint-test$ swiftlint lint
Loading configuration from '.swiftlint.yml'
Linting Swift files at paths
Linting 'lint.swift' (1/1)
/Users/kaitlinmahar/lint-test/lint.swift:2:1: warning: Explicit ACL Violation: All declarations should specify Access Control Level keywords explicitly. (explicit_acl)
Done linting! Found 1 violation, 0 serious in 1 file.
If I change the file to:
public struct MyStruct {}
public extension MyStruct: Equatable {}
Swiftlint is satisfied --
kaitlinmahar@kaitlin:~/lint-test$ swiftlint lint
Loading configuration from '.swiftlint.yml'
Linting Swift files at paths
Linting 'lint.swift' (1/1)
Done linting! Found 0 violations, 0 serious in 1 file.
But the compiler is not:
kaitlinmahar@kaitlin:~/lint-test$ swift lint.swift
lint.swift:2:1: error: 'public' modifier cannot be used with extensions that declare protocol conformances
public extension MyStruct: Equatable {}
^~~~~~~
Environment
- SwiftLint version (run
swiftlint version
to be sure)?0.31.0
- Installation method used (Homebrew, CocoaPods, building from source, etc)? Homebrew
- Which Xcode version are you using (check
xcode-select -p
)? xcode-select version 2354. However, I'm using Swift 4.2 installed via swiftenv.
kaitlinmahar@kaitlin:~/lint-test$ swift --version
Apple Swift version 4.2 (swift-4.2-RELEASE)
Target: x86_64-apple-darwin18.2.0
I also switched to Swift 5.0 via swiftenv and tested, same results.
Metadata
Assignees
Labels
No labels