From c2a00c2b100045b0918e23db8adb3026d3ba83ba Mon Sep 17 00:00:00 2001 From: Nikita Vasilev Date: Mon, 6 Nov 2023 11:31:28 +0300 Subject: [PATCH] Update `pre-commit` hook (#5) * Update `pre-commit` hook * Fix `SwiftLint` warnings * Update `CHANGELOG.md` --- CHANGELOG.md | 2 ++ .../Atomic/Classes/Core/Atomic/Atomic.swift | 2 +- .../Classes/Helpers/Lock/UnfairLock.swift | 2 +- hooks/pre-commit | 29 ++++++++++++++++++- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51b251f..3b612d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. ## [Unreleased] ## Added +- Updating pre-commit hook rules + - Added in Pull Request [#5](https://github.com/space-code/atomic/pull/5). - Integrate `CodeCov` - Added in Pull Request [#4](https://github.com/space-code/atomic/pull/4). diff --git a/Sources/Atomic/Classes/Core/Atomic/Atomic.swift b/Sources/Atomic/Classes/Core/Atomic/Atomic.swift index 5afe16c..d9d2709 100644 --- a/Sources/Atomic/Classes/Core/Atomic/Atomic.swift +++ b/Sources/Atomic/Classes/Core/Atomic/Atomic.swift @@ -68,7 +68,7 @@ public final class Atomic { extension Atomic: Equatable where Value: Equatable { public static func == (lhs: Atomic, rhs: Atomic) -> Bool { - lhs.read { left in rhs.read { right in left == right }} + lhs.read { left in rhs.read { right in left == right } } } } diff --git a/Sources/Atomic/Classes/Helpers/Lock/UnfairLock.swift b/Sources/Atomic/Classes/Helpers/Lock/UnfairLock.swift index 97c1f08..3b7a768 100644 --- a/Sources/Atomic/Classes/Helpers/Lock/UnfairLock.swift +++ b/Sources/Atomic/Classes/Helpers/Lock/UnfairLock.swift @@ -17,7 +17,7 @@ final class UnfairLock { // MARK: Initialization /// Initializes an UnfairLock instance. - public init() { + init() { unfairLock = .allocate(capacity: 1) unfairLock.initialize(to: os_unfair_lock()) } diff --git a/hooks/pre-commit b/hooks/pre-commit index 89b3319..956fdcb 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -8,4 +8,31 @@ git diff --diff-filter=d --staged --name-only | grep -e '\.swift$' | while read fi done -swiftlint \ No newline at end of file +LINT=$(which mint) +if [[ -e "${LINT}" ]]; then + # Export files in SCRIPT_INPUT_FILE_$count to lint against later + count=0 + while IFS= read -r file_path; do + export SCRIPT_INPUT_FILE_$count="$file_path" + count=$((count + 1)) + done < <(git diff --name-only --cached --diff-filter=d | grep ".swift$") + export SCRIPT_INPUT_FILE_COUNT=$count + + if [ "$count" -eq 0 ]; then + echo "No files to lint!" + exit 0 + fi + + echo "Found $count lintable files! Linting now.." + mint run swiftlint --use-script-input-files --strict --config .swiftlint.yml + RESULT=$? # swiftline exit value is number of errors + + if [ $RESULT -eq 0 ]; then + echo "🎉 Well done. No violation." + fi + exit $RESULT +else + echo "⚠️ WARNING: SwiftLint not found" + echo "⚠️ You might want to edit .git/hooks/pre-commit to locate your swiftlint" + exit 0 +fi \ No newline at end of file