mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
# Conflicts: # Tests/BuiltInRulesTests/FileHeaderRuleTests.swift # Tests/BuiltInRulesTests/FileNameNoSpaceRuleTests.swift # Tests/BuiltInRulesTests/IndentationWidthRuleTests.swift # Tests/CoreTests/RegexConfigurationTests.swift # Tests/CoreTests/SwiftLintFileTests.swift # Tests/FileSystemAccessTests/BaselineTests.swift # Tests/FileSystemAccessTests/ConfigurationTests+Mock.swift # Tests/FileSystemAccessTests/ConfigurationTests.swift # Tests/FileSystemAccessTests/GlobTests.swift # Tests/FileSystemAccessTests/MultipleConfigurationsTests.swift # Tests/FileSystemAccessTests/ReporterTests.swift # Tests/FileSystemAccessTests/SourceKitCrashTests.swift # Tests/FrameworkTests/CustomRulesTests.swift # Tests/FrameworkTests/LinterCacheTests.swift # Tests/FrameworkTests/RuleConfigurationTests.swift # Tests/FrameworkTests/SwiftVersionTests.swift # Tests/GeneratedTests/GeneratedTests_02.swift # Tests/GeneratedTests/GeneratedTests_03.swift # Tests/GeneratedTests/GeneratedTests_04.swift # Tests/GeneratedTests/GeneratedTests_05.swift # Tests/GeneratedTests/GeneratedTests_06.swift # Tests/GeneratedTests/GeneratedTests_07.swift # Tests/GeneratedTests/GeneratedTests_08.swift # Tests/GeneratedTests/GeneratedTests_09.swift # Tests/GeneratedTests/GeneratedTests_10.swift # Tests/IntegrationTests/ConfigPathResolutionTests.swift # Tests/IntegrationTests/IntegrationTests.swift # Tests/TestHelpers/TestHelpers.swift
38 lines
1.4 KiB
Swift
38 lines
1.4 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 = {
|
|
SwiftLintCore.Issue.genericWarning(\(raw: message)).print()
|
|
}()
|
|
|
|
func notifyRuleDisabledOnce() {
|
|
_ = Self.postMessage
|
|
}
|
|
}
|
|
"""),
|
|
]
|
|
}
|
|
}
|