From 2a7cda2c5d10a92302751774b868c55ee63cd97e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Mon, 25 Apr 2022 17:58:50 +0200 Subject: [PATCH 1/5] Update formula to version 0.9.1 --- Formula/anylint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Formula/anylint.rb b/Formula/anylint.rb index 9171057..1ba9688 100644 --- a/Formula/anylint.rb +++ b/Formula/anylint.rb @@ -1,7 +1,7 @@ class Anylint < Formula desc "Lint anything by combining the power of Swift & regular expressions" homepage "https://github.com/FlineDev/AnyLint" - url "https://github.com/FlineDev/AnyLint.git", :tag => "0.9.0", :revision => "77e24fdedb70413dd8f750799dedc4b309b7c8eb" + url "https://github.com/FlineDev/AnyLint.git", :tag => "0.9.1", :revision => "80c757d7e36fefba27e6a3f3e6fd25644c576a02" head "https://github.com/FlineDev/AnyLint.git" depends_on :xcode => ["12.5", :build] From 1856dac69c637f2839fffd7f47b434dec31a96bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Mon, 25 Apr 2022 18:07:38 +0200 Subject: [PATCH 2/5] Fix tests after adding violationLocation param --- Tests/AnyLintTests/CheckInfoTests.swift | 2 +- Tests/AnyLintTests/Checkers/FileContentsCheckerTests.swift | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Tests/AnyLintTests/CheckInfoTests.swift b/Tests/AnyLintTests/CheckInfoTests.swift index ad69b2e..91e25ee 100644 --- a/Tests/AnyLintTests/CheckInfoTests.swift +++ b/Tests/AnyLintTests/CheckInfoTests.swift @@ -29,6 +29,6 @@ final class CheckInfoTests: XCTestCase { let checkInfo4: CheckInfo = "test4: hint4" XCTAssertEqual(checkInfo4.id, "test4") XCTAssertEqual(checkInfo4.hint, "hint4") - XCTAssertEqual(checkInfo4.severity, .error) + XCTAssertEqual(checkInfo4.severity, .warning) } } diff --git a/Tests/AnyLintTests/Checkers/FileContentsCheckerTests.swift b/Tests/AnyLintTests/Checkers/FileContentsCheckerTests.swift index f1eefa7..5f51209 100644 --- a/Tests/AnyLintTests/Checkers/FileContentsCheckerTests.swift +++ b/Tests/AnyLintTests/Checkers/FileContentsCheckerTests.swift @@ -21,6 +21,7 @@ final class FileContentsCheckerTests: XCTestCase { let violations = try FileContentsChecker( checkInfo: checkInfo, regex: #"(let|var) \w+=\w+"#, + violationLocation: .init(range: .fullMatch, bound: .lower), filePathsToCheck: filePathsToCheck, autoCorrectReplacement: nil, repeatIfAutoCorrected: false @@ -52,6 +53,7 @@ final class FileContentsCheckerTests: XCTestCase { let violations = try FileContentsChecker( checkInfo: checkInfo, regex: #"(let|var) \w+=\w+"#, + violationLocation: .init(range: .fullMatch, bound: .lower), filePathsToCheck: filePathsToCheck, autoCorrectReplacement: nil, repeatIfAutoCorrected: false @@ -84,6 +86,7 @@ final class FileContentsCheckerTests: XCTestCase { let violations = try FileContentsChecker( checkInfo: checkInfo, regex: #"(let|var) \w+=\w+"#, + violationLocation: .init(range: .fullMatch, bound: .lower), filePathsToCheck: filePathsToCheck, autoCorrectReplacement: nil, repeatIfAutoCorrected: false @@ -134,6 +137,7 @@ final class FileContentsCheckerTests: XCTestCase { let violations = try FileContentsChecker( checkInfo: checkInfo, regex: #"(let|var) (\w+)\s*=\s*(\w+)"#, + violationLocation: .init(range: .fullMatch, bound: .lower), filePathsToCheck: filePathsToCheck, autoCorrectReplacement: "$1 $2 = $3", repeatIfAutoCorrected: false @@ -164,6 +168,7 @@ final class FileContentsCheckerTests: XCTestCase { let violations = try FileContentsChecker( checkInfo: checkInfo, regex: #"(? Date: Mon, 25 Apr 2022 18:15:18 +0200 Subject: [PATCH 3/5] Fix linter config & warnings --- .swiftlint.yml | 1 - CHANGELOG.md | 8 ++++---- Sources/AnyLint/Statistics.swift | 2 +- Sources/AnyLint/ViolationLocationConfig.swift | 13 +++++++++++++ lint.swift | 2 +- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index b51b982..c1c1009 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -56,7 +56,6 @@ opt_in_rules: - prohibited_super_call - reduce_into - redundant_nil_coalescing -- redundant_type_annotation - single_test_class - sorted_first_last - sorted_imports diff --git a/CHANGELOG.md b/CHANGELOG.md index 1edb153..16cbdb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,12 +38,12 @@ If needed, pluralize to `Tasks`, `PRs` or `Authors` and list multiple entries se ## [0.9.0] - 2022-04-24 ### Added -- Added new option `violationLocation` parameter for `checkFileContents` for specifying position of violation marker using `.init(range:bound:)`, where `range` can be one of `.fullMatch` or `.captureGroup(index:)` and bound one of `.lower` or `.upper`. - +- Added new option `violationLocation` parameter for `checkFileContents` for specifying position of violation marker using `.init(range:bound:)`, where `range` can be one of `.fullMatch` or `.captureGroup(index:)` and bound one of `.lower` or `.upper`. + ## [0.8.5] - 2022-04-24 ### Fixed -- Fixed an issue where first violation can't be shown in Xcode due to 'swift-driver version: 1.45.2' printed on same line. - +- Fixed an issue where first violation can't be shown in Xcode due to 'swift-driver version: 1.45.2' printed on same line. + ## [0.8.4] - 2022-04-01 ### Fixed - Fixed an issue with pointing to the wrong Swift-SH path on Apple Silicon Macs. Should also fix the path on Linux. diff --git a/Sources/AnyLint/Statistics.swift b/Sources/AnyLint/Statistics.swift index 3a4c26c..07c7303 100644 --- a/Sources/AnyLint/Statistics.swift +++ b/Sources/AnyLint/Statistics.swift @@ -51,7 +51,7 @@ final class Statistics { func logCheckSummary() { // make sure first violation reports in a new line when e.g. 'swift-driver version: 1.45.2' is printed - print("\n") + print("\n") // AnyLint.skipHere: Logger if executedChecks.isEmpty { log.message("No checks found to perform.", level: .warning) diff --git a/Sources/AnyLint/ViolationLocationConfig.swift b/Sources/AnyLint/ViolationLocationConfig.swift index 4679d44..0bb5f89 100644 --- a/Sources/AnyLint/ViolationLocationConfig.swift +++ b/Sources/AnyLint/ViolationLocationConfig.swift @@ -1,19 +1,32 @@ import Foundation +/// Configuration for the position of the violation marker violations should be reported at. public struct ViolationLocationConfig { + /// The range to use for pointer reporting. One of `.fullMatch` or `.captureGroup(index:)`. public enum Range { + /// Uses the full matched range of the Regex. case fullMatch + + /// Uses the capture group range of the provided index. case captureGroup(index: Int) } + /// The bound to use for pionter reporting. One of `.lower` or `.upper`. public enum Bound { + /// Uses the lower end of the provided range. case lower + + /// Uses the upper end of the provided range. case upper } let range: Range let bound: Bound + /// Initializes a new instance with given range and bound. + /// - Parameters: + /// - range: The range to use for pointer reporting. One of `.fullMatch` or `.captureGroup(index:)`. + /// - bound: The bound to use for pionter reporting. One of `.lower` or `.upper`. public init(range: Range, bound: Bound) { self.range = range self.bound = bound diff --git a/lint.swift b/lint.swift index d72738e..df3ebcd 100755 --- a/lint.swift +++ b/lint.swift @@ -1,4 +1,4 @@ -#!/opt/local/bin/swift-sh +#!/opt/homebrew/bin/swift-sh import AnyLint // . import Utility import ShellOut // @JohnSundell From 546786089a701ee5db33d25f3196ccab2e4997fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Mon, 25 Apr 2022 19:07:51 +0200 Subject: [PATCH 4/5] Allow `customCheck` closure to be throwing by re-throwing if they are --- CHANGELOG.md | 3 ++- Sources/AnyLint/Lint.swift | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16cbdb1..f557ed5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,8 @@ If needed, pluralize to `Tasks`, `PRs` or `Authors` and list multiple entries se ## [Unreleased] ### Added -- None. +- Allow `customCheck` closure to be throwing by re-throwing if they are. + Author: [Cihat Gündüz](https://github.com/Jeehut) ### Changed - None. ### Deprecated diff --git a/Sources/AnyLint/Lint.swift b/Sources/AnyLint/Lint.swift index 8f19d37..81394f8 100644 --- a/Sources/AnyLint/Lint.swift +++ b/Sources/AnyLint/Lint.swift @@ -138,13 +138,13 @@ public enum Lint { /// - Parameters: /// - checkInfo: The info object providing some general information on the lint check. /// - customClosure: The custom logic to run which produces an array of `Violation` objects for any violations. - public static func customCheck(checkInfo: CheckInfo, customClosure: (CheckInfo) -> [Violation]) { + public static func customCheck(checkInfo: CheckInfo, customClosure: (CheckInfo) throws -> [Violation]) rethrows { guard !Options.validateOnly else { Statistics.shared.executedChecks.append(checkInfo) return } - Statistics.shared.found(violations: customClosure(checkInfo), in: checkInfo) + Statistics.shared.found(violations: try customClosure(checkInfo), in: checkInfo) } /// Logs the summary of all detected violations and exits successfully on no violations or with a failure, if any violations. From ae0a1dbf966577310baa5b9ace44093602481fd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Mon, 25 Apr 2022 19:08:51 +0200 Subject: [PATCH 5/5] Bump version num & finalize new changelog section --- CHANGELOG.md | 8 ++++++-- README.md | 4 ++-- Sources/Utility/Constants.swift | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f557ed5..30ad1fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,8 +19,7 @@ If needed, pluralize to `Tasks`, `PRs` or `Authors` and list multiple entries se ## [Unreleased] ### Added -- Allow `customCheck` closure to be throwing by re-throwing if they are. - Author: [Cihat Gündüz](https://github.com/Jeehut) +- None. ### Changed - None. ### Deprecated @@ -32,6 +31,11 @@ If needed, pluralize to `Tasks`, `PRs` or `Authors` and list multiple entries se ### Security - None. +## [0.9.2] - 2022-04-25 +### Added +- Allow `customCheck` closure to be throwing by re-throwing if they are. + Author: [Cihat Gündüz](https://github.com/Jeehut) + ## [0.9.1] - 2022-04-25 ### Changed - Default violation level was changed from `error` to `warning`. diff --git a/README.md b/README.md index c399ced..532dfab 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ alt="Coverage"/> - Version: 0.9.1 + Version: 0.9.2