mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
Rewrite prefer_nimble rule with SwiftSyntax (#4410)
This commit is contained in:
@@ -106,6 +106,7 @@
|
||||
- `number_separator`
|
||||
- `operator_whitespace`
|
||||
- `nsobject_prefer_isequal`
|
||||
- `prefer_nimble`
|
||||
- `private_action`
|
||||
- `private_over_fileprivate`
|
||||
- `private_outlet`
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
public struct PreferNimbleRule: ASTRule, OptInRule, ConfigurationProviderRule {
|
||||
import SwiftSyntax
|
||||
|
||||
public struct PreferNimbleRule: SwiftSyntaxRule, OptInRule, ConfigurationProviderRule {
|
||||
public var configuration = SeverityConfiguration(.warning)
|
||||
|
||||
public init() {}
|
||||
@@ -22,18 +24,18 @@ public struct PreferNimbleRule: ASTRule, OptInRule, ConfigurationProviderRule {
|
||||
]
|
||||
)
|
||||
|
||||
public func validate(file: SwiftLintFile,
|
||||
kind: SwiftExpressionKind,
|
||||
dictionary: SourceKittenDictionary) -> [StyleViolation] {
|
||||
guard kind == .call,
|
||||
let offset = dictionary.offset,
|
||||
let name = dictionary.name,
|
||||
name.starts(with: "XCTAssert") else {
|
||||
return []
|
||||
public func makeVisitor(file: SwiftLintFile) -> ViolationsSyntaxVisitor {
|
||||
Visitor(viewMode: .sourceAccurate)
|
||||
}
|
||||
}
|
||||
|
||||
private extension PreferNimbleRule {
|
||||
final class Visitor: ViolationsSyntaxVisitor {
|
||||
override func visitPost(_ node: FunctionCallExprSyntax) {
|
||||
if let expr = node.calledExpression.as(IdentifierExprSyntax.self),
|
||||
expr.identifier.text.starts(with: "XCTAssert") {
|
||||
violations.append(node.positionAfterSkippingLeadingTrivia)
|
||||
}
|
||||
}
|
||||
|
||||
return [StyleViolation(ruleDescription: Self.description,
|
||||
severity: configuration.severity,
|
||||
location: Location(file: file, byteOffset: offset))]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user