From 9f2aa621976679cd4b286e4e882196016cba8093 Mon Sep 17 00:00:00 2001 From: swiftty <62803132+swiftty@users.noreply.github.com> Date: Tue, 11 Jun 2024 23:22:02 +0900 Subject: [PATCH 1/7] Add #5598 example --- .../Style/OpeningBraceRuleExamples.swift | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/OpeningBraceRuleExamples.swift b/Source/SwiftLintBuiltInRules/Rules/Style/OpeningBraceRuleExamples.swift index 37d05fb1b2..f144b6c8c5 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() + } + } + """), ] } From 65964d6cdcb2787ddfb276730fbdc191ae1d462e Mon Sep 17 00:00:00 2001 From: swiftty <62803132+swiftty@users.noreply.github.com> Date: Wed, 12 Jun 2024 00:19:44 +0900 Subject: [PATCH 2/7] Fix multiple corrections in opening_brace --- Tests/SwiftLintTestHelpers/TestHelpers.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Tests/SwiftLintTestHelpers/TestHelpers.swift b/Tests/SwiftLintTestHelpers/TestHelpers.swift index 5418b7377e..525a12c623 100644 --- a/Tests/SwiftLintTestHelpers/TestHelpers.swift +++ b/Tests/SwiftLintTestHelpers/TestHelpers.swift @@ -217,8 +217,11 @@ private extension Configuration { 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) + corrections.count, + before.code != expected.code ? max(corrections.count, 1) : 0, + #function + ".expectedLocationsEmpty", + file: before.file, line: before.line + ) } else { XCTAssertEqual( corrections.count, From 15f7d17fb64b6be5bdfa141507d62cc674f89c19 Mon Sep 17 00:00:00 2001 From: swiftty <62803132+swiftty@users.noreply.github.com> Date: Wed, 12 Jun 2024 00:38:46 +0900 Subject: [PATCH 3/7] Fix correction when correction range is before the violation location --- Source/SwiftLintCore/Extensions/SwiftLintFile+Regex.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/SwiftLintCore/Extensions/SwiftLintFile+Regex.swift b/Source/SwiftLintCore/Extensions/SwiftLintFile+Regex.swift index f833e94553..e860e5343c 100644 --- a/Source/SwiftLintCore/Extensions/SwiftLintFile+Regex.swift +++ b/Source/SwiftLintCore/Extensions/SwiftLintFile+Regex.swift @@ -273,6 +273,7 @@ extension SwiftLintFile { return violatingRanges.filter { range in let region = fileRegions.first { $0.contains(Location(file: self, characterOffset: range.location)) + || $0.contains(Location(file: self, characterOffset: range.location + range.length - 1)) } return region?.isRuleEnabled(rule) ?? true } From bd02f2ec2aedf859bcff498df7b2dd897e4f836e Mon Sep 17 00:00:00 2001 From: swiftty <62803132+swiftty@users.noreply.github.com> Date: Sun, 23 Jun 2024 13:04:28 +0900 Subject: [PATCH 4/7] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb32d2899b..ab57ad4de2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -106,6 +106,9 @@ nested within each other. [Martin Redington](https://github.com/mildm8nnered) [#5660](https://github.com/realm/SwiftLint/issues/5660) +* Fix `opening_brace` correction. + [swiftty](https://github.com/swiftty) + [#issue_number](https://github.com/realm/SwiftLint/issues/issue_number) ## 0.55.1: Universal Washing Powder From 964b19803a468bbbe704be7683ccc93e34f99282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Sat, 20 Jul 2024 17:06:03 +0200 Subject: [PATCH 5/7] Update CHANGELOG entry --- CHANGELOG.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab57ad4de2..968431bc00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -106,9 +106,12 @@ nested within each other. [Martin Redington](https://github.com/mildm8nnered) [#5660](https://github.com/realm/SwiftLint/issues/5660) -* Fix `opening_brace` correction. + +* Fix `opening_brace` correction and make sure that disable commands + are taken into account before applying a fix. [swiftty](https://github.com/swiftty) - [#issue_number](https://github.com/realm/SwiftLint/issues/issue_number) + [SimplyDanny](https://github.com/SimplyDanny) + [#5598](https://github.com/realm/SwiftLint/issues/5598) ## 0.55.1: Universal Washing Powder From ccbe2516d13071cdc0427efdf3d97920fab150fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Sat, 20 Jul 2024 17:06:16 +0200 Subject: [PATCH 6/7] Revert "Fix correction when correction range is before the violation location" This reverts commit 15f7d17fb64b6be5bdfa141507d62cc674f89c19. --- Source/SwiftLintCore/Extensions/SwiftLintFile+Regex.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/SwiftLintCore/Extensions/SwiftLintFile+Regex.swift b/Source/SwiftLintCore/Extensions/SwiftLintFile+Regex.swift index e860e5343c..f833e94553 100644 --- a/Source/SwiftLintCore/Extensions/SwiftLintFile+Regex.swift +++ b/Source/SwiftLintCore/Extensions/SwiftLintFile+Regex.swift @@ -273,7 +273,6 @@ extension SwiftLintFile { return violatingRanges.filter { range in let region = fileRegions.first { $0.contains(Location(file: self, characterOffset: range.location)) - || $0.contains(Location(file: self, characterOffset: range.location + range.length - 1)) } return region?.isRuleEnabled(rule) ?? true } From e8b0b61c0cb08f3d887a323694ada077be40a670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Sat, 20 Jul 2024 17:08:08 +0200 Subject: [PATCH 7/7] Prefer `XCTAssertGreaterThanOrEqual` --- Tests/SwiftLintTestHelpers/TestHelpers.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Tests/SwiftLintTestHelpers/TestHelpers.swift b/Tests/SwiftLintTestHelpers/TestHelpers.swift index 525a12c623..7c965b4642 100644 --- a/Tests/SwiftLintTestHelpers/TestHelpers.swift +++ b/Tests/SwiftLintTestHelpers/TestHelpers.swift @@ -216,11 +216,12 @@ private extension Configuration { let linter = collecter.collect(into: storage) let corrections = linter.correct(using: storage).sorted { $0.location < $1.location } if expectedLocations.isEmpty { - XCTAssertEqual( + XCTAssertGreaterThanOrEqual( corrections.count, - before.code != expected.code ? max(corrections.count, 1) : 0, + before.code != expected.code ? 1 : 0, #function + ".expectedLocationsEmpty", - file: before.file, line: before.line + file: before.file, + line: before.line ) } else { XCTAssertEqual(