Skip to content

Commit

Permalink
Update pre-commit hook (#5)
Browse files Browse the repository at this point in the history
* Update `pre-commit` hook

* Fix `SwiftLint` warnings

* Update `CHANGELOG.md`
  • Loading branch information
ns-vasilev authored Nov 6, 2023
1 parent b02025c commit c2a00c2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion Sources/Atomic/Classes/Core/Atomic/Atomic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public final class Atomic<Value> {

extension Atomic: Equatable where Value: Equatable {
public static func == (lhs: Atomic<Value>, rhs: Atomic<Value>) -> Bool {
lhs.read { left in rhs.read { right in left == right }}
lhs.read { left in rhs.read { right in left == right } }
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Atomic/Classes/Helpers/Lock/UnfairLock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
29 changes: 28 additions & 1 deletion hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,31 @@ git diff --diff-filter=d --staged --name-only | grep -e '\.swift$' | while read
fi
done

swiftlint
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

0 comments on commit c2a00c2

Please sign in to comment.