Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Stream rules

--swiftversion 5.3
--swiftversion 5.10

# Use 'swiftformat --options' to list all of the possible options

Expand Down
19 changes: 0 additions & 19 deletions Makefile

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public struct PrefixLogFormatter: ILogFormatter {
public func format(message: String, with logLevel: LogLevel) -> String {
switch logLevel {
case .fault:
return "🚨🚨🚨 [\(name)] => \(message)"
"🚨🚨🚨 [\(name)] => \(message)"
case .error:
return "💣💥💣💥 [\(name)] => \(message)"
"💣💥💣💥 [\(name)] => \(message)"
default:
return "[\(name)] => \(message)"
"[\(name)] => \(message)"
}
}
}
2 changes: 1 addition & 1 deletion Sources/Log/Classes/Core/Logger/Logger.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// log
// Copyright © 2024 Space Code. All rights reserved.
// Copyright © 2023 Space Code. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/Log/Classes/Core/Printers/ConsolePrinter.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// log
// Copyright © 2024 Space Code. All rights reserved.
// Copyright © 2023 Space Code. All rights reserved.
//

import Foundation
Expand Down
12 changes: 6 additions & 6 deletions Sources/Log/Classes/Core/Printers/OSPrinter.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// log
// Copyright © 2024 Space Code. All rights reserved.
// Copyright © 2023 Space Code. All rights reserved.
//

import Foundation
Expand Down Expand Up @@ -65,15 +65,15 @@ extension OSPrinter {
private func sysLogPriority(_ logLevel: LogLevel) -> OSLogType {
switch logLevel {
case .debug:
return .debug
.debug
case .info:
return .info
.info
case .fault:
return .fault
.fault
case .error:
return .error
.error
default:
return .default
.default
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// log
// Copyright © 2024 Space Code. All rights reserved.
// Copyright © 2023 Space Code. All rights reserved.
//

import Foundation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// log
// Copyright © 2024 Space Code. All rights reserved.
// Copyright © 2023 Space Code. All rights reserved.
//

import Foundation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// log
// Copyright © 2024 Space Code. All rights reserved.
// Copyright © 2023 Space Code. All rights reserved.
//

import Foundation
Expand Down
14 changes: 6 additions & 8 deletions Sources/Log/Classes/Helpers/Writers/OSWriter/OSWriter.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// log
// Copyright © 2024 Space Code. All rights reserved.
// Copyright © 2023 Space Code. All rights reserved.
//

import Foundation
Expand All @@ -20,13 +20,11 @@ final class OSWriter: IOSWriter {
private var osLog: OSLog { OSLog(subsystem: subsystem, category: category) }

/// An internal lazy property for initializing WriteStrategy instance.
private lazy var writerStrategy: IOSWriterStrategy = {
if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) {
return os.Logger(osLog)
} else {
return LegacyOSLogger(osLog: osLog)
}
}()
private lazy var writerStrategy: IOSWriterStrategy = if #available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) {
os.Logger(osLog)
} else {
LegacyOSLogger(osLog: osLog)
}

// MARK: Initialization

Expand Down
2 changes: 1 addition & 1 deletion Tests/LogTests/Mocks/ConsoleWriterMock.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// log
// Copyright © 2024 Space Code. All rights reserved.
// Copyright © 2023 Space Code. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Tests/LogTests/Mocks/OSWriterMock.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// log
// Copyright © 2024 Space Code. All rights reserved.
// Copyright © 2023 Space Code. All rights reserved.
//

@testable import Log
Expand Down
2 changes: 1 addition & 1 deletion Tests/LogTests/UnitTests/ConsolePrinterTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// log
// Copyright © 2024 Space Code. All rights reserved.
// Copyright © 2023 Space Code. All rights reserved.
//

@testable import Log
Expand Down
2 changes: 1 addition & 1 deletion Tests/LogTests/UnitTests/LogTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// log
// Copyright © 2024 Space Code. All rights reserved.
// Copyright © 2023 Space Code. All rights reserved.
//

import Log
Expand Down
2 changes: 1 addition & 1 deletion Tests/LogTests/UnitTests/OSPrinterTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// log
// Copyright © 2024 Space Code. All rights reserved.
// Copyright © 2023 Space Code. All rights reserved.
//

@testable import Log
Expand Down
46 changes: 16 additions & 30 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,38 +1,24 @@
#!/bin/bash

echo "🔍 Running linters..."

echo "📝 Formatting staged Swift files..."
git diff --diff-filter=d --staged --name-only | grep -e '\.swift$' | while read line; do
if [[ $line == *"/Generated"* ]]; then
echo "IGNORING GENERATED FILE: " "$line";
echo "⏭️ Skipping generated file: $line"
else
mint run swiftformat swiftformat "${line}";
git add "$line";
echo "✨ Formatting: $line"
mise exec swiftformat -- swiftformat "${line}"
git add "$line"
fi
done

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 ! mise run lint; then
echo "❌ Lint failed. Please fix the issues before committing."
echo "💡 Tip: Run 'mise run format' to auto-fix some issues"
echo "⚠️ To skip this hook, use: git commit --no-verify"
exit 1
fi

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
echo "✅ All checks passed!"
exit 0
10 changes: 10 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[tools]
git-cliff = "2.9.1"
swiftlint = "0.62.2"
swiftformat = "0.58.7"

[settings]
experimental = true

[hooks]
postinstall = "mise run install"
57 changes: 57 additions & 0 deletions mise/tasks/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

set -e

echo "🔧 Installing git hooks..."

# Find git repository root
GIT_ROOT=$(git rev-parse --show-toplevel 2>/dev/null)

if [ -z "$GIT_ROOT" ]; then
echo "❌ Error: Not a git repository"
exit 1
fi

echo "📁 Git root: $GIT_ROOT"

# Create hooks directory if it doesn't exist
mkdir -p "$GIT_ROOT/.git/hooks"

# Create pre-commit hook
cat > "$GIT_ROOT/.git/hooks/pre-commit" <<'HOOK_EOF'
#!/bin/bash

echo "🔍 Running linters..."

echo "📝 Formatting staged Swift files..."
git diff --diff-filter=d --staged --name-only | grep -e '\.swift$' | while read line; do
if [[ $line == *"/Generated"* ]]; then
echo "⏭️ Skipping generated file: $line"
else
echo "✨ Formatting: $line"
mise exec swiftformat -- swiftformat "${line}"
git add "$line"
fi
done

if ! mise run lint; then
echo "❌ Lint failed. Please fix the issues before committing."
echo "💡 Tip: Run 'mise run format' to auto-fix some issues"
echo "⚠️ To skip this hook, use: git commit --no-verify"
exit 1
fi

echo "✅ All checks passed!"
exit 0
HOOK_EOF

chmod +x "$GIT_ROOT/.git/hooks/pre-commit"

echo "✅ Git hooks installed successfully!"
echo "📍 Hook location: $GIT_ROOT/.git/hooks/pre-commit"
echo ""
echo "Pre-commit hook will:"
echo " 1. Format staged Swift files (except /Generated)"
echo " 2. Run mise lint"
echo ""
echo "To skip the hook, use: git commit --no-verify"
13 changes: 13 additions & 0 deletions mise/tasks/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
#MISE description="Lint the log package using SwiftLint and SwiftFormat"
#MISE usage flag "-f --fix" help="Fix the fixable issues"

set -eo pipefail

if [ "$usage_fix" = "true" ]; then
swiftformat Sources Tests
swiftlint lint --fix --strict --config .swiftlint.yml Sources Tests
else
swiftformat Sources Tests --lint
swiftlint lint --strict --config .swiftlint.yml Sources Tests
fi
Loading