unused_declaration false positives on SceneDelegate and unrelated delegate methods.
Nobody has claimed this yet.
- 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
After enabling the unused_declaration analyzer rule it reports some delegates classes or methods (e.g. SceneDelegate, WKUIDelegate.webView(<args>)) as unused, which while they aren't referenced in our code they are used by the system.
Interestingly the delegate methods only get reported as unused when they are on a subclass where the parent class does not implement the method. I did verify that the method is properly called on the child class, which can be seen in the sample project below.
Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint analyze --compiler-log-path <build_log_path>
Analyzing Swift files in current working directory
Collecting 'WebView.swift' (1/4)
Collecting 'AppDelegate.swift' (2/4)
Collecting 'ContentView.swift' (3/4)
Collecting 'SceneDelegate.swift' (4/4)
Analyzing 'WebView.swift' (1/4)
<path>/WebAppTest/WebAppTest/WebView.swift:26:8: error: Unused Declaration Violation: Declarations should be referenced at least once within all files linted. (unused_declaration)
Analyzing 'AppDelegate.swift' (2/4)
Analyzing 'ContentView.swift' (3/4)
Analyzing 'SceneDelegate.swift' (4/4)
<path>/WebAppTest/WebAppTest/SceneDelegate.swift:12:7: error: Unused Declaration Violation: Declarations should be referenced at least once within all files linted. (unused_declaration)
Done analyzing! Found 2 violations, 2 serious in 4 files.
Environment
- SwiftLint version (run
swiftlint versionto be sure)?
0.50.3 - Installation method used (Homebrew, CocoaPods, building from source, etc)?
Homebrew - Paste your configuration file:
analyzer_rules:
- unused_declaration
- Are you using nested configurations?
No. - Which Xcode version are you using (check
xcodebuild -version)?
Xcode 14.2
Build version 14C18 - Do you have a sample that shows the issue?
I have attached a minimum sample project that reproduces the false positives, primarily for the WKUIDelegate method, however every project I've tried with a SceneDelegate reports it as unused.
WebAppTest.zip
// This triggers a violation:
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
}
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
Reproduce the unused_declaration reports with the attached sample project, focusing on WebView.swift and SceneDelegate.swift and the swiftlint analyze --compiler-log-path entry point. Trace how the analyzer handles SceneDelegate and WKUIDelegate methods. Done means system-used delegate declarations are no longer reported while genuinely unused declarations still are.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100