When running the unused_import rule, the following triggers a false-positive:
XCTAssertTrue(someFoo is Foo)
In this case, the import Foo is flagged as unused, even though it's used within the comparison statement.
Worth noting that the following does not trigger the same false positive:
XCTAssertNotNil(someFoo as? Foo)
@rebello95: Hello, Michael.
I tried to reproduce this on version 0.35 but I couldn't. Here is the command:
swiftlint analyze --compiler-log-path <path-to-xcodebuild.log> --config <path-to-testconfig.yml> <path-to-SwiftlintTest.xcodeproj>
SwiftlintTest project:
SwiftlintTest.zip
contents of testConfig.yml:
analyzer_rules:
- unused_import
Does this bug reproduce now? If it does, could you post full example of your code to reproduce it?
Thanks for taking a look.
I ran your project locally but was getting the following output after adding a .swiftlint.yml file:
mrebello-mbp151:SwiftlintTest mrebello$ swiftlint analyze --compiler-log-path /Users/mrebello/Downloads/output.txt --config /Users/mrebello/Downloads/SwiftlintTest/.swiftlint.yml /Users/mrebello/Downloads/SwiftlintTest/SwiftlintTest.xcodeproj
Loading configuration from '/Users/mrebello/Downloads/SwiftlintTest/.swiftlint.yml'
Analyzing Swift files at paths /Users/mrebello/Downloads/SwiftlintTest/SwiftlintTest.xcodeproj
No lintable files found at paths: '/Users/mrebello/Downloads/SwiftlintTest/SwiftlintTest.xcodeproj'
However, I did read through the code in the AppDelegate, and it looks like you're explicitly instantiating the type. I believe this should repro the issue:
import UIKit
import SwiftlintTestLibrary
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let someFoo: Any = ""
XCTAssertTrue(someFoo is SwiftlintTestLibrary)
return true
}
private func XCTAssertTrue(_ isFoo: Bool) {
print("\(isFoo)")
}
}
@rebello95: tried to use your example, but still no errors.
You are using swiftlint 0.35, aren't you? Could you attach your .swiftlint.yml file or more exact code sample?
Very weird, I'm now unable to reproduce this issue. I'll re-open this issue if I come across this again and am able to repro. Thanks for investigating.
This seems to be related to SR-12047
Sounds like this is fixed in 5.2 https://bugs.swift.org/browse/SR-8616
Most helpful comment
Sounds like this is fixed in 5.2 https://bugs.swift.org/browse/SR-8616