Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Sources/SwiftComplexityCore/Analysis/FunctionDetector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class FunctionDetector: SyntaxVisitor {
return detectedFunctions
}

override func visit(_ node: ProtocolDeclSyntax) -> SyntaxVisitorContinueKind {
return .skipChildren
}

public override func visit(_ node: FunctionDeclSyntax) -> SyntaxVisitorContinueKind {
let name = extractFunctionName(from: node)
let signature = extractFunctionSignature(from: node)
Expand Down
11 changes: 11 additions & 0 deletions Tests/SwiftComplexityCoreTests/Fixtures/protocol_decl.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// protocol.swift
// swift-complexity
//
// Created by Fumiya Tanaka on 2025/10/18.
//

protocol P {
var foo: String { get }
func bar()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// protocol_extension_decl.swift
// swift-complexity
//
// Created by Fumiya Tanaka on 2025/10/18.
//

extension P {
func foo() {}
}
28 changes: 28 additions & 0 deletions Tests/SwiftComplexityCoreTests/SwiftComplexityTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,34 @@ struct FunctionDetectionTests {
#expect(names.contains("method1"))
#expect(names.contains("method2"))
}

@Test("protocol")
func protocolDeclTests() async throws {
// Given
let code = try loadFixture("protocol_decl")
let sourceFile = Parser.parse(source: code)
let detector = FunctionDetector(viewMode: .sourceAccurate)

// When
let functions = detector.detectFunctions(in: sourceFile)

// Then
#expect(functions.count == 0)
}

@Test("protocol_extension")
func protocolExtensionDeclTests() async throws {
// Given
let code = try loadFixture("protocol_extension_decl")
let sourceFile = Parser.parse(source: code)
let detector = FunctionDetector(viewMode: .sourceAccurate)

// When
let functions = detector.detectFunctions(in: sourceFile)

// Then
#expect(functions.count == 1)
}
}

// MARK: - Output Formatter Tests
Expand Down
Loading