Files
SwiftLint/Source/SwiftLintCoreMacros/SwiftLintCoreMacros.swift
Danny Mösch 299042a233 Allow to configure only severity in a short form for every rule with a severity (#5509)
The README states that a configuration like `attributes: error` is
valid to only set a different severity level for a rule (the
`attributes` rule here). This was previously only possible for rules
that were accompanied by a plain severity configuration.

I don't think this broke with the automatic parsing code generation.
For some rules it might have worked before, for others not. This change
makes it consistently working for all rules.
2024-03-25 21:40:56 +01:00

40 lines
1.1 KiB
Swift

import SwiftCompilerPlugin
import SwiftDiagnostics
import SwiftSyntax
import SwiftSyntaxMacros
@main
struct SwiftLintCoreMacros: CompilerPlugin {
let providingMacros: [any Macro.Type] = [
AutoApply.self,
MakeAcceptableByConfigurationElement.self,
SwiftSyntaxRule.self
]
}
enum SwiftLintCoreMacroError: String, DiagnosticMessage {
case notStruct = "Attribute can only be applied to structs"
case severityBasedWithoutProperty = """
Severity-based configuration without a 'severityConfiguration' property is invalid
"""
case notEnum = "Attribute can only be applied to enums"
case noStringRawType = "Attribute can only be applied to enums with a 'String' raw type"
case noBooleanLiteral = "Macro argument must be a boolean literal"
var message: String {
rawValue
}
var diagnosticID: MessageID {
MessageID(domain: "SwiftLint", id: "SwiftLintCoreMacro.\(self)")
}
var severity: DiagnosticSeverity {
.error
}
func diagnose(at node: some SyntaxProtocol) -> Diagnostic {
Diagnostic(node: Syntax(node), message: self)
}
}