mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
77050e8c40
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.
35 lines
1.2 KiB
Swift
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
|
|
}
|
|
}
|
|
"""),
|
|
]
|
|
}
|
|
}
|