From cb0f5ab0074caa62960a69281304a2ae14cadd45 Mon Sep 17 00:00:00 2001 From: Hayashi Tatsuya <62803132+swiftty@users.noreply.github.com> Date: Sun, 21 Jul 2024 00:36:24 +0900 Subject: [PATCH] Verify and document fixed `opening_brace` correction (#5620) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Danny Mösch --- CHANGELOG.md | 6 ++++++ .../Style/OpeningBraceRuleExamples.swift | 20 +++++++++++++++++++ Tests/SwiftLintTestHelpers/TestHelpers.swift | 10 +++++++--- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb32d2899b..968431bc00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -107,6 +107,12 @@ [Martin Redington](https://github.com/mildm8nnered) [#5660](https://github.com/realm/SwiftLint/issues/5660) +* Fix `opening_brace` correction and make sure that disable commands + are taken into account before applying a fix. + [swiftty](https://github.com/swiftty) + [SimplyDanny](https://github.com/SimplyDanny) + [#5598](https://github.com/realm/SwiftLint/issues/5598) + ## 0.55.1: Universal Washing Powder #### Breaking diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/OpeningBraceRuleExamples.swift b/Source/SwiftLintBuiltInRules/Rules/Style/OpeningBraceRuleExamples.swift index f95befcdb8..19cc630465 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/OpeningBraceRuleExamples.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/OpeningBraceRuleExamples.swift @@ -546,5 +546,25 @@ struct OpeningBraceRuleExamples { return } """), + // https://github.com/realm/SwiftLint/issues/5598 + Example(""" + func foo() { + if q1, q2 + { + do1() + } else if q3, q4 + { + do2() + } + } + """): Example(""" + func foo() { + if q1, q2 { + do1() + } else if q3, q4 { + do2() + } + } + """), ] } diff --git a/Tests/SwiftLintTestHelpers/TestHelpers.swift b/Tests/SwiftLintTestHelpers/TestHelpers.swift index 06dc892cd0..032fad3c36 100644 --- a/Tests/SwiftLintTestHelpers/TestHelpers.swift +++ b/Tests/SwiftLintTestHelpers/TestHelpers.swift @@ -216,9 +216,13 @@ private extension Configuration { let linter = collector.collect(into: storage) let corrections = linter.correct(using: storage).sorted { $0.location < $1.location } if expectedLocations.isEmpty { - XCTAssertEqual( - corrections.count, before.code != expected.code ? 1 : 0, #function + ".expectedLocationsEmpty", - file: before.file, line: before.line) + XCTAssertGreaterThanOrEqual( + corrections.count, + before.code != expected.code ? 1 : 0, + #function + ".expectedLocationsEmpty", + file: before.file, + line: before.line + ) } else { XCTAssertEqual( corrections.count,