Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to put comment commands on the same line as an import statement #881

Merged
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
2 changes: 1 addition & 1 deletion Sources/SyntaxAnalysis/ImportSyntaxVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public final class ImportSyntaxVisitor: PeripherySyntaxVisitor {
isTestable: attributes.contains("testable"),
isExported: attributes.contains("_exported") || node.modifiers.contains { $0.name.text == "public" },
location: location,
commentCommands: CommentCommand.parseCommands(in: node.leadingTrivia)
commentCommands: CommentCommand.parseCommands(in: node.leadingTrivia.merging(node.trailingTrivia))
)
importStatements.append(statement)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Foundation
// periphery:ignore
import CoreFoundation
import Swift // periphery:ignore
39 changes: 39 additions & 0 deletions Tests/PeripheryTests/Syntax/ImportVisitTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Foundation
@testable import SourceGraph
@testable import SyntaxAnalysis
@testable import TestShared
import XCTest

final class ImportVisitTest: XCTestCase {
private var results: [ImportStatement]!

override func setUpWithError() throws {
try super.setUpWithError()
let multiplexingVisitor = try MultiplexingSyntaxVisitor(file: fixturePath)
let visitor = multiplexingVisitor.add(ImportSyntaxVisitor.self)
multiplexingVisitor.visit()
results = visitor.importStatements
}

override func tearDown() {
results = nil
super.tearDown()
}

func testCommentCommands() {
let expectedIgnored = ["CoreFoundation", "Swift"]
let actualIgnored = results.filter { $0.commentCommands.contains(.ignore) }.map(\.module)
XCTAssertEqual(actualIgnored, expectedIgnored, "Ignored modules did not match the expected set")

let actualUnignored = results.filter { !$0.commentCommands.contains(.ignore) }.map(\.module)
let expectedUnignored = ["Foundation"]
XCTAssertEqual(actualUnignored, expectedUnignored, "Unignored modules did not match the expected set")
}

// MARK: - Private

private var fixturePath: SourceFile {
let path = FixturesProjectPath.appending("Sources/DeclarationVisitorFixtures/ImportFixture.swift")
return SourceFile(path: path, modules: ["DeclarationVisitorFixtures"])
}
}
Loading