mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
38 lines
1.3 KiB
Swift
38 lines
1.3 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 acl = declaration.modifiers.first {
|
|
["public", "internal", "package", "fileprivate", "private"].contains($0.name.text)
|
|
}?.name.text ?? "internal"
|
|
let message = #"""
|
|
"Skipping enabled rule '\(Self.identifier)' because it requires SourceKit and SourceKit access is prohibited."
|
|
"""#
|
|
return [
|
|
try ExtensionDeclSyntax("""
|
|
\(raw: acl) extension \(type) {
|
|
private static let postMessage: Void = {
|
|
Issue.genericWarning(\(raw: message)).print()
|
|
}()
|
|
|
|
func notifyRuleDisabledOnce() {
|
|
_ = Self.postMessage
|
|
}
|
|
}
|
|
"""),
|
|
]
|
|
}
|
|
}
|