Files
SwiftLint/Source/SwiftLintCoreMacros/DisabledWithoutSourceKit.swift
T
Danny Mösch 77050e8c40 Enable a fully statically linked Linux executable (#6211)
If SwiftLint is built from this state using the Swift SDK, we'll get a
large self-contained Linux executable that runs without loading SourceKit.
It can do that by disabling any rule that requires SourceKit.

With `SWIFTLINT_DISABLE_SOURCEKIT` set on a normally (dynamically linked)
binary, the behavior is the same. That's different from the previously
reported more serious warnings.
2025-08-30 10:02:38 -04:00

35 lines
1.2 KiB
Swift

import SwiftSyntax
import SwiftSyntaxBuilder
import SwiftSyntaxMacros
enum DisabledWithoutSourceKit: ExtensionMacro {
static func expansion(
of _: AttributeSyntax,
attachedTo declaration: some DeclGroupSyntax,
providingExtensionsOf type: some TypeSyntaxProtocol,
conformingTo _: [TypeSyntax],
in context: some MacroExpansionContext
) throws -> [ExtensionDeclSyntax] {
guard declaration.is(StructDeclSyntax.self) else {
context.diagnose(SwiftLintCoreMacroError.notStruct.diagnose(at: declaration))
return []
}
let message = #"""
"Skipping enabled rule '\(Self.identifier)' because it requires SourceKit and SourceKit access is prohibited."
"""#
return [
try ExtensionDeclSyntax("""
extension \(type) {
private static let postMessage: Void = {
Issue.genericWarning(\(raw: message)).print()
}()
func notifyRuleDisabledOnce() {
_ = Self.postMessage
}
}
"""),
]
}
}