You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
unused_import false positive for import OSLog when using os.Logger #6942
Reproduced on 0.62.2. The same comparison is still in UnusedImportRule on 0.65.1: used modules are SourceKit's defining module name, subtracted from the import list. No open issue mentions OSLog / os.Logger. This is the same gap as #5167 (import SwiftUI vs Combine.ObservableObject) and #5528 (@_exported import).
Bug Description
unused_import reports import OSLog as unused in a file that uses os.Logger. Deleting that import makes the file fail to compile, which is the opposite of the rule description ("All imported modules should be required to make the file compile").
os.Logger is declared in the Swift module os (os.swiftinterface, -module-name os, public struct Logger). The compiler mangles it as $s2os6LoggerV.... import OSLog is a different module, and it is still what brings Logger into scope. SourceKit cursor info reports key.modulename as os. The rule inserts that name into the used-module set and does imports.subtracting(usedModules), so OSLog is left over. Nothing in the file is attributed to OSLog.
swiftlint analyze (0.62.2, macOS, Xcode 26.6) on a file that contains the snippet above:
Example.swift:1:1: warning: Unused Import Violation: All imported modules should be required to make the file compile (unused_import)
import Foundation alone does not provide os.Logger. allowed_transitive_imports can paper over this, but the default rule should not flag an import whose removal breaks the file:
unused_import:
allowed_transitive_imports:
- module: OSLogallowed_transitive_imports:
- os
Environment
SwiftLint version: 0.62.2 (rule source checked against 0.65.1)
Xcode version: Xcode 26.6 (Build version 17F113), Swift 6.3.3
Activity