Macros
The following macros are available globally.
-
Macro to be attached to rule configurations. It generates the configuration parsing logic automatically based on the defined
@ConfigurationElement
s.Declaration
Swift
@attached(member, names: named(apply) ) public macro AutoConfigParser() = #externalMacro( module: "SwiftLintCoreMacros", type: "AutoConfigParser" )
-
Macro that lets an enum with a
String
raw type automatically conform toAcceptableByConfigurationElement
.Declaration
Swift
@attached(extension, conformances: AcceptableByConfigurationElement, names: named(init(fromAny:context:) ), named(asOption)) public macro AcceptableByConfigurationElement() = #externalMacro( module: "SwiftLintCoreMacros", type: "AcceptableByConfigurationElement" )
-
Macro that adds a conformance to the
SwiftSyntaxRule
protocol and a defaultmakeVisitor(file:)
implementation that creates a visitor defined in the rule struct.Declaration
Swift
@attached(extension, conformances: SwiftSyntaxRule, SwiftSyntaxCorrectableRule, names: named(makeVisitor(file:) ), named(preprocess(file:)), named(makeRewriter(file:))) public macro SwiftSyntaxRule(foldExpressions: Bool = false, explicitRewriter: Bool = false) = #externalMacro( module: "SwiftLintCoreMacros", type: "SwiftSyntaxRule" )
Parameters
foldExpressions
Setting it to
true
adds an implementation ofpreprocess(file:)
which folds expressions before they are passed to the visitor.explicitRewriter
Set it to
true
to add amakeRewriter(file:)
implementation which creates a rewriter defined in the rule struct. In this case, the rule automatically conforms toSwiftSyntaxCorrectableRule
.