Skip to content

Commit 94a48c8

Browse files
authored
Merge pull request #9 from fummicc1/feature/fix-protocol-#8
Skip protocol
2 parents c913120 + 2f65f71 commit 94a48c8

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

Sources/SwiftComplexityCore/Analysis/FunctionDetector.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class FunctionDetector: SyntaxVisitor {
2626
return detectedFunctions
2727
}
2828

29+
override func visit(_ node: ProtocolDeclSyntax) -> SyntaxVisitorContinueKind {
30+
return .skipChildren
31+
}
32+
2933
public override func visit(_ node: FunctionDeclSyntax) -> SyntaxVisitorContinueKind {
3034
let name = extractFunctionName(from: node)
3135
let signature = extractFunctionSignature(from: node)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//
2+
// protocol.swift
3+
// swift-complexity
4+
//
5+
// Created by Fumiya Tanaka on 2025/10/18.
6+
//
7+
8+
protocol P {
9+
var foo: String { get }
10+
func bar()
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//
2+
// protocol_extension_decl.swift
3+
// swift-complexity
4+
//
5+
// Created by Fumiya Tanaka on 2025/10/18.
6+
//
7+
8+
extension P {
9+
func foo() {}
10+
}

Tests/SwiftComplexityCoreTests/SwiftComplexityTests.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,34 @@ struct FunctionDetectionTests {
251251
#expect(names.contains("method1"))
252252
#expect(names.contains("method2"))
253253
}
254+
255+
@Test("protocol")
256+
func protocolDeclTests() async throws {
257+
// Given
258+
let code = try loadFixture("protocol_decl")
259+
let sourceFile = Parser.parse(source: code)
260+
let detector = FunctionDetector(viewMode: .sourceAccurate)
261+
262+
// When
263+
let functions = detector.detectFunctions(in: sourceFile)
264+
265+
// Then
266+
#expect(functions.count == 0)
267+
}
268+
269+
@Test("protocol_extension")
270+
func protocolExtensionDeclTests() async throws {
271+
// Given
272+
let code = try loadFixture("protocol_extension_decl")
273+
let sourceFile = Parser.parse(source: code)
274+
let detector = FunctionDetector(viewMode: .sourceAccurate)
275+
276+
// When
277+
let functions = detector.detectFunctions(in: sourceFile)
278+
279+
// Then
280+
#expect(functions.count == 1)
281+
}
254282
}
255283

256284
// MARK: - Output Formatter Tests

0 commit comments

Comments
 (0)