[unused_declaration] False positive when the conformance to a protocol happens on an extension in a different file
Open
Nobody has claimed this yet.
bug
sourcekit-issue
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
Describe the bug
When running the unused_declaration analyze rule:
- Having a protocol and class conforming to that protocol : https://github.com/acecilia/swift-compilation-database/blob/master/Sources/ModuleB/SomethingProtocol.swift
- Having the implementation of the conformance in a different file: https://github.com/acecilia/swift-compilation-database/blob/master/Sources/ModuleB/Something%2Bconformance.swift
The rule will throw a false positive, detecting the conformance that happens in a different file as unused:
swift-compilation-database/Sources/ModuleB/Something+conformance.swift:2:10: error: Unused Declaration Violation: Declarations should be referenced at least once within all files linted. (unused_declaration)
Environment
- SwiftLint version (run
swiftlint versionto be sure)?0.45.0 - Installation method used (Homebrew, CocoaPods, building from source, etc)?
mint - Paste your configuration file:
analyzer_rules:
- unused_import
- unused_declaration
unused_declaration:
include_public_and_open: true
- Are you using nested configurations?
If so, paste their relative paths and respective contents.No - Which Xcode version are you using (check
xcodebuild -version)?Xcode 12.5.1 - Do you have a sample that shows the issue? Yes. Clone https://github.com/acecilia/swift-compilation-database and then do
make go_with_xcodebuild
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the unused_declaration analyzer and reproduce the report by cloning swift-compilation-database and running make go_with_xcodebuild. Inspect Sources/ModuleB/SomethingProtocol.swift and Sources/ModuleB/Something+conformance.swift, focusing on how declarations and conformances are considered across files. Done means the cross-file conformance is no longer reported as unused while genuine unused declarations remain detected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100