mirror of
https://github.com/realm/SwiftLint.git
synced 2026-05-07 20:12:49 +00:00
58928b7e40
This makes syntactically clear which types are rather expensive.
38 lines
1.3 KiB
Swift
38 lines
1.3 KiB
Swift
import SwiftSyntax
|
|
|
|
@SwiftSyntaxRule
|
|
struct NoExtensionAccessModifierRule: OptInRule, ConfigurationProviderRule {
|
|
var configuration = SeverityConfiguration<Self>(.error)
|
|
|
|
static let description = RuleDescription(
|
|
identifier: "no_extension_access_modifier",
|
|
name: "No Extension Access Modifier",
|
|
description: "Prefer not to use extension access modifiers",
|
|
kind: .idiomatic,
|
|
nonTriggeringExamples: [
|
|
Example("extension String {}"),
|
|
Example("\n\n extension String {}")
|
|
],
|
|
triggeringExamples: [
|
|
Example("↓private extension String {}"),
|
|
Example("↓public \n extension String {}"),
|
|
Example("↓open extension String {}"),
|
|
Example("↓internal extension String {}"),
|
|
Example("↓fileprivate extension String {}")
|
|
]
|
|
)
|
|
}
|
|
|
|
private extension NoExtensionAccessModifierRule {
|
|
final class Visitor: ViolationsSyntaxVisitor {
|
|
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] { .all }
|
|
|
|
override func visitPost(_ node: ExtensionDeclSyntax) {
|
|
let modifiers = node.modifiers
|
|
if modifiers.isNotEmpty {
|
|
violations.append(modifiers.positionAfterSkippingLeadingTrivia)
|
|
}
|
|
}
|
|
}
|
|
}
|