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.
42 lines
1.2 KiB
Swift
42 lines
1.2 KiB
Swift
import SwiftSyntax
|
|
|
|
@SwiftSyntaxRule
|
|
struct IBInspectableInExtensionRule: ConfigurationProviderRule, OptInRule {
|
|
var configuration = SeverityConfiguration<Self>(.warning)
|
|
|
|
static let description = RuleDescription(
|
|
identifier: "ibinspectable_in_extension",
|
|
name: "IBInspectable in Extension",
|
|
description: "Extensions shouldn't add @IBInspectable properties",
|
|
kind: .lint,
|
|
nonTriggeringExamples: [
|
|
Example("""
|
|
class Foo {
|
|
@IBInspectable private var x: Int
|
|
}
|
|
""")
|
|
],
|
|
triggeringExamples: [
|
|
Example("""
|
|
extension Foo {
|
|
↓@IBInspectable private var x: Int
|
|
}
|
|
""")
|
|
]
|
|
)
|
|
}
|
|
|
|
private extension IBInspectableInExtensionRule {
|
|
final class Visitor: ViolationsSyntaxVisitor {
|
|
override var skippableDeclarations: [any DeclSyntaxProtocol.Type] {
|
|
.allExcept(ExtensionDeclSyntax.self, VariableDeclSyntax.self)
|
|
}
|
|
|
|
override func visitPost(_ node: AttributeSyntax) {
|
|
if node.attributeNameText == "IBInspectable" {
|
|
violations.append(node.positionAfterSkippingLeadingTrivia)
|
|
}
|
|
}
|
|
}
|
|
}
|