@@ -73,51 +73,29 @@ struct StaticOverFinalClassRule: Rule {
7373)
7474}
7575
76- // Stack of flags indicating whether each level in the tree is a final class
77- private typealias LevelIsFinalClassStack = Stack < Bool >
78-
79- private extension LevelIsFinalClassStack {
80- var lastIsFinalClass : Bool { peek ( ) == true }
81- }
82-
8376private extension StaticOverFinalClassRule {
8477final class Visitor : ViolationsSyntaxVisitor < ConfigurationType > {
85- private var levels = LevelIsFinalClassStack ( )
78+ private var classContexts = Stack < Bool > ( )
8679
8780override func visit( _ node: ClassDeclSyntax ) -> SyntaxVisitorContinueKind {
88- levels . push ( node. modifiers. contains ( keyword: . final) )
81+ classContexts . push ( node. modifiers. contains ( keyword: . final) )
8982return . visitChildren
9083}
9184
9285override func visitPost( _ node: ClassDeclSyntax ) {
93- levels. pop ( )
94- }
95-
96- override func visit( _ node: FunctionDeclSyntax ) -> SyntaxVisitorContinueKind {
97- validateNode ( at: node. positionAfterSkippingLeadingTrivia, with: node. modifiers)
98- return . visitChildren
86+ classContexts. pop ( )
9987}
10088
10189override func visitPost( _ node: FunctionDeclSyntax ) {
102- levels. pop ( )
103- }
104-
105- override func visit( _ node: VariableDeclSyntax ) -> SyntaxVisitorContinueKind {
10690validateNode ( at: node. positionAfterSkippingLeadingTrivia, with: node. modifiers)
107- return . visitChildren
10891}
10992
11093override func visitPost( _ node: VariableDeclSyntax ) {
111- levels. pop ( )
112- }
113-
114- override func visit( _ node: SubscriptDeclSyntax ) -> SyntaxVisitorContinueKind {
11594validateNode ( at: node. positionAfterSkippingLeadingTrivia, with: node. modifiers)
116- return . visitChildren
11795}
11896
11997override func visitPost( _ node: SubscriptDeclSyntax ) {
120- levels . pop ( )
98+ validateNode ( at : node . positionAfterSkippingLeadingTrivia , with : node . modifiers )
12199}
122100
123101 // MARK: -
@@ -126,11 +104,9 @@ private extension StaticOverFinalClassRule {
126104 modifiers. contains ( keyword: . class) {
127105 violations. append ( position)
128106} else if modifiers. contains ( keyword: . class) ,
129- levels . lastIsFinalClass {
107+ classContexts . peek ( ) == true {
130108 violations. append ( position)
131109}
132-
133- levels. push ( false )
134110}
135111}
136112}