Add --disable-sourcekit flag to disable SourceKit (#6439)

This commit is contained in:
Danny Mösch
2026-01-15 20:30:52 +01:00
committed by GitHub
parent faa5859155
commit 8978ae2ccb
6 changed files with 23 additions and 5 deletions
+4 -1
View File
@@ -12,7 +12,10 @@
### Enhancements
* None.
* Add a `--disable-sourcekit` flag to the `lint` command to disable SourceKit when needed.
The environment variable `SWIFTLINT_DISABLE_SOURCEKIT` can still be used as well.
[SimplyDanny](https://github.com/SimplyDanny)
[#6282](https://github.com/realm/SwiftLint/issues/6282)
### Bug Fixes
@@ -2,15 +2,17 @@ import Foundation
import SourceKittenFramework
public extension Request {
static let disableSourceKit = {
nonisolated(unsafe) static var disableSourceKitOverride = false
static var disableSourceKit: Bool {
#if SWIFTLINT_DISABLE_SOURCEKIT
// Compile-time
true
#else
// Runtime
ProcessInfo.processInfo.environment["SWIFTLINT_DISABLE_SOURCEKIT"] != nil
ProcessInfo.processInfo.environment["SWIFTLINT_DISABLE_SOURCEKIT"] != nil || disableSourceKitOverride
#endif
}()
}
func sendIfNotDisabled() throws -> [String: any SourceKitRepresentable] {
// Skip safety checks if explicitly allowed (e.g., for testing or specific operations)
@@ -45,7 +47,7 @@ public extension Request {
}
guard !Self.disableSourceKit else {
queuedFatalError("SourceKit is disabled by `SWIFTLINT_DISABLE_SOURCEKIT`.")
queuedFatalError("SourceKit is disabled by configuration.")
}
return try send()
}
@@ -3,6 +3,7 @@
#endif
import Dispatch
import Foundation
import SourceKittenFramework
// swiftlint:disable file_length
@@ -53,6 +54,7 @@ package struct LintOrAnalyzeOptions {
let onlyRule: [String]
let autocorrect: Bool
let format: Bool
let disableSourceKit: Bool
let compilerLogPath: String?
let compileCommands: String?
let checkForUpdates: Bool
@@ -81,6 +83,7 @@ package struct LintOrAnalyzeOptions {
onlyRule: [String],
autocorrect: Bool,
format: Bool,
disableSourceKit: Bool,
compilerLogPath: String?,
compileCommands: String?,
checkForUpdates: Bool) {
@@ -108,6 +111,7 @@ package struct LintOrAnalyzeOptions {
self.onlyRule = onlyRule
self.autocorrect = autocorrect
self.format = format
self.disableSourceKit = disableSourceKit
self.compilerLogPath = compilerLogPath
self.compileCommands = compileCommands
self.checkForUpdates = checkForUpdates
@@ -124,6 +128,7 @@ package struct LintOrAnalyzeOptions {
package struct LintOrAnalyzeCommand {
package static func run(_ options: LintOrAnalyzeOptions) async throws {
Request.disableSourceKitOverride = options.mode == .lint && options.disableSourceKit
if let workingDirectory = options.workingDirectory {
if !FileManager.default.changeCurrentDirectoryPath(workingDirectory) {
throw SwiftLintError.usageError(
+1
View File
@@ -44,6 +44,7 @@ extension SwiftLint {
onlyRule: common.onlyRule,
autocorrect: common.fix,
format: common.format,
disableSourceKit: false,
compilerLogPath: compilerLogPath,
compileCommands: compileCommands,
checkForUpdates: common.checkForUpdates
+6
View File
@@ -19,6 +19,11 @@ extension SwiftLint {
var noCache = false
@Flag(help: "Run all rules, even opt-in and disabled ones, ignoring `only_rules`.")
var enableAllRules = false
@Flag(
name: .customLong("disable-sourcekit"),
help: "Do not dynamically load SourceKit at runtime. Skip and report rules that require it."
)
var disableSourceKit = false
@Argument(help: pathsArgumentDescription(for: .lint))
var paths = [String]()
@@ -56,6 +61,7 @@ extension SwiftLint {
onlyRule: common.onlyRule,
autocorrect: common.fix,
format: common.format,
disableSourceKit: disableSourceKit,
compilerLogPath: nil,
compileCommands: nil,
checkForUpdates: common.checkForUpdates
@@ -64,6 +64,7 @@ private extension LintOrAnalyzeOptions {
onlyRule: [],
autocorrect: false,
format: false,
disableSourceKit: false,
compilerLogPath: nil,
compileCommands: nil,
checkForUpdates: false