Files
SwiftLint/Source/SwiftLintBuiltInRules/Rules/Lint/IBInspectableInExtensionRule.swift
T
Danny Mösch 58928b7e40 Enforce any on existential types (#5273)
This makes syntactically clear which types are rather expensive.
2023-10-12 08:37:23 +02:00

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)
}
}
}
}