diff --git a/CHANGELOG.md b/CHANGELOG.md index d844c64fe8..b9321f829b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Source/SwiftLintFramework/Models/Command.swift b/Source/SwiftLintFramework/Models/Command.swift index ff008ebec9..81b6d2cf52 100644 --- a/Source/SwiftLintFramework/Models/Command.swift +++ b/Source/SwiftLintFramework/Models/Command.swift @@ -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 != "*/" } diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index 07d7186622..0bc447d127 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -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), @@ -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), diff --git a/Tests/SwiftLintFrameworkTests/LineEndingTests.swift b/Tests/SwiftLintFrameworkTests/LineEndingTests.swift new file mode 100644 index 0000000000..b9357b3515 --- /dev/null +++ b/Tests/SwiftLintFrameworkTests/LineEndingTests.swift @@ -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 + ) + } +}