Skip to content

Discard newlines when sorting imports. #169

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

Merged
merged 1 commit into from
Apr 1, 2020
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/SwiftFormatRules/OrderedImports.swift
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ fileprivate class Line {
else {
return ""
}
return importDecl.path.description.trimmingCharacters(in: .whitespaces)
return importDecl.path.description.trimmingCharacters(in: .whitespacesAndNewlines)
}

/// Returns the first `TokenSyntax` in the code block(s) from this Line, or nil when this Line
Expand Down
2 changes: 0 additions & 2 deletions Tests/SwiftFormatPrettyPrintTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@ extension DifferentiationAttributeTests {
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__DifferentiationAttributeTests = [
("testDerivative", testDerivative),
("testDifferentiable", testDifferentiable),
("testTranspose", testTranspose),
]
}

Expand Down
24 changes: 24 additions & 0 deletions Tests/SwiftFormatRulesTests/OrderedImportsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,30 @@ final class OrderedImportsTests: LintOrFormatRuleTestCase {
)
}

func testImportsContainingNewlines() {
let input =
"""
import
zeta
import Zeta
import
Alpha
import Beta
"""

let expected =
"""
import
Alpha
import Beta
import Zeta
import
zeta
"""

XCTAssertFormatting(OrderedImports.self, input: input, expected: expected)
}

func testRemovesDuplicateImports() {
let input =
"""
Expand Down
1 change: 1 addition & 0 deletions Tests/SwiftFormatRulesTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ extension OrderedImportsTests {
("testDuplicateIgnoredImports", testDuplicateIgnoredImports),
("testEmptyFile", testEmptyFile),
("testIgnoredConditionalImports", testIgnoredConditionalImports),
("testImportsContainingNewlines", testImportsContainingNewlines),
("testImportsOrderWithDocComment", testImportsOrderWithDocComment),
("testImportsOrderWithoutModuleType", testImportsOrderWithoutModuleType),
("testInvalidImportsOrder", testInvalidImportsOrder),
Expand Down