Rule
public protocol Rule
An executable value that can identify issues (violations) in Swift source code.
-
A verbose description of many of this rule’s properties.
Declaration
Swift
static var description: RuleDescription { get }
-
A description of how this rule has been configured to run. It can be built using the annotated result builder.
Declaration
Swift
@RuleConfigurationDescriptionBuilder var configurationDescription: Documentable { get }
-
A default initializer for rules. All rules need to be trivially initializable.
Declaration
Swift
init()
-
Creates a rule by applying its configuration.
Throws
Throws if the configuration didn’t match the expected format.
Declaration
Swift
init(configuration: Any) throws
Parameters
configuration
The untyped configuration value to apply.
-
validate(file:
Default implementationcompilerArguments: ) Executes the rule on a file and returns any violations to the rule’s expectations.
Default Implementation
Declaration
Swift
func validate(file: SwiftLintFile, compilerArguments: [String]) -> [StyleViolation]
Parameters
file
The file for which to execute the rule.
compilerArguments
The compiler arguments needed to compile this file.
Return Value
All style violations to the rule’s expectations.
-
Executes the rule on a file and returns any violations to the rule’s expectations.
Declaration
Swift
func validate(file: SwiftLintFile) -> [StyleViolation]
Parameters
file
The file for which to execute the rule.
Return Value
All style violations to the rule’s expectations.
-
isEqualTo(_:
Default implementation) Whether or not the specified rule is equivalent to the current rule.
Default Implementation
Declaration
Swift
func isEqualTo(_ rule: Rule) -> Bool
Parameters
rule
The
rule
value to compare against.Return Value
Whether or not the specified rule is equivalent to the current rule.
-
collectInfo(for:
Default implementationinto: compilerArguments: ) Collects information for the specified file in a storage object, to be analyzed by a
CollectedLinter
.Note
This function is called by the linter and is always implemented in extensions.
Default Implementation
Declaration
Swift
func collectInfo(for file: SwiftLintFile, into storage: RuleStorage, compilerArguments: [String])
Parameters
file
The file for which to collect info.
storage
The storage object where collected info should be saved.
compilerArguments
The compiler arguments needed to compile this file.
-
validate(file:
Default implementationusing: compilerArguments: ) Executes the rule on a file after collecting file info for all files and returns any violations to the rule’s expectations.
Note
This function is called by the linter and is always implemented in extensions.
Default Implementation
Declaration
Swift
func validate(file: SwiftLintFile, using storage: RuleStorage, compilerArguments: [String]) -> [StyleViolation]
Parameters
file
The file for which to execute the rule.
storage
The storage object containing all collected info.
compilerArguments
The compiler arguments needed to compile this file.
Return Value
All style violations to the rule’s expectations.
-
cacheDescription
Extension methodThe cache description which will be used to determine if a previous cached value is still valid given the new cache value.
Declaration
Swift
var cacheDescription: String { get }
-
identifier
Extension methodThe rule’s unique identifier which is the same as
Rule.description.identifier
.Declaration
Swift
static var identifier: String { get }