Skip to content

Commit

Permalink
Fix false positives when line ends with carriage return + line feed (#…
Browse files Browse the repository at this point in the history
…3061)

Fixes: #3060
  • Loading branch information
john-mueller authored Feb 2, 2020
1 parent 057bcb8 commit be44017
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
* Fix crash when non-closed #if was present in file.
[PaulTaykalo](https://github.com/PaulTaykalo)

* Fix false positives when line ends with carriage return + line feed
[John Mueller](https://github.com/john-mueller)
[#3060](https://github.com/realm/SwiftLint/issues/3060)

## 0.38.2: Machine Repair Manual

#### Breaking
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Models/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public struct Command: Equatable {
let startOfCommentPastDelimiter = scanner.scanLocation + Command.commentDelimiter.count
trailingComment = scanner.string.bridge().substring(from: startOfCommentPastDelimiter)
}
let ruleTexts = rawRuleTexts.components(separatedBy: .whitespaces).filter {
let ruleTexts = rawRuleTexts.components(separatedBy: .whitespacesAndNewlines).filter {
let component = $0.trimmingCharacters(in: .whitespaces)
return !component.isEmpty && component != "*/"
}
Expand Down
7 changes: 7 additions & 0 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,12 @@ extension LetVarWhitespaceRuleTests {
]
}

extension LineEndingTests {
static var allTests: [(String, (LineEndingTests) -> () throws -> Void)] = [
("testCarriageReturnDoesNotCauseError", testCarriageReturnDoesNotCauseError)
]
}

extension LineLengthConfigurationTests {
static var allTests: [(String, (LineLengthConfigurationTests) -> () throws -> Void)] = [
("testLineLengthConfigurationInitializerSetsLength", testLineLengthConfigurationInitializerSetsLength),
Expand Down Expand Up @@ -1735,6 +1741,7 @@ XCTMain([
testCase(LegacyNSGeometryFunctionsRuleTests.allTests),
testCase(LegacyRandomRuleTests.allTests),
testCase(LetVarWhitespaceRuleTests.allTests),
testCase(LineEndingTests.allTests),
testCase(LineLengthConfigurationTests.allTests),
testCase(LineLengthRuleTests.allTests),
testCase(LinterCacheTests.allTests),
Expand Down
12 changes: 12 additions & 0 deletions Tests/SwiftLintFrameworkTests/LineEndingTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@testable import SwiftLintFramework
import XCTest

class LineEndingTests: XCTestCase {
func testCarriageReturnDoesNotCauseError() {
XCTAssert(
violations(
"//swiftlint:disable all\r\nprint(123)\r\n"
).isEmpty
)
}
}

0 comments on commit be44017

Please sign in to comment.