-
-
Notifications
You must be signed in to change notification settings - Fork 358
Expand file tree
/
Copy pathswiftlint.sh
More file actions
executable file
·75 lines (61 loc) · 2.28 KB
/
swiftlint.sh
File metadata and controls
executable file
·75 lines (61 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
set -eo pipefail
# Check if an argument is provided
if [ $# -eq 0 ]; then
echo "Usage: $0 <fix|lint>"
exit 1
fi
# Set the mode based on the first argument
mode=$1
SWIFT_PATH=$(which swift 2>/dev/null || true)
if [ -z "$SWIFT_PATH" ]; then
echo "SwiftLint requires swift, which is not installed or not found in PATH"
echo "To install Swift:"
echo " * ubuntu: follow steps here: https://www.swift.org/install/"
echo " * arch: yay -S swift-bin"
exit 1
fi
LINUX_BIN="https://github.com/realm/SwiftLint/releases/download/0.61.0/swiftlint_linux_amd64.zip"
LINUX_SHA="sha256:02f4f580bbb27fb618dbfa24ce2f14c926461c85c26941289f58340151b63ae4"
DARWIN_BIN="https://github.com/realm/SwiftLint/releases/download/0.61.0/portable_swiftlint.zip"
DARWIN_SHA="sha256:2342f3784307a02117e18f745fcd350c6acc6cab0e521c0c0e01c32a53a3b274"
if [[ "$OSTYPE" == "darwin"* ]]; then
EXPECTED_SHA="$DARWIN_SHA"
EXPECTED_BIN="$DARWIN_BIN"
else
EXPECTED_SHA="$LINUX_SHA"
EXPECTED_BIN="$LINUX_BIN"
fi
# Make ../swiftlint folder if it doesn't exist
SWIFTLINT_DIR="$(dirname "$0")/../swiftlint"
mkdir -p "$SWIFTLINT_DIR"
# Skip download if sha256sum swiftlint.sha matches EXPECTED_SHA
SHA_FILE="$SWIFTLINT_DIR/swiftlint.sha"
if [ -f "$SHA_FILE" ] && [ "$(cat "$SHA_FILE")" = "$EXPECTED_SHA" ]; then
echo "SwiftLint already downloaded and verified."
else
echo "Clearing swiftlint folder..."
rm -rf "$SWIFTLINT_DIR"/*
echo "Downloading SwiftLint..."
curl -L "$EXPECTED_BIN" -o "$SWIFTLINT_DIR/swiftlint.zip"
unzip "$SWIFTLINT_DIR/swiftlint.zip" -d "$SWIFTLINT_DIR"
# Save sha256sum of swiftlint.zip to ../swiftlint/swiftlint.sha
echo "$EXPECTED_SHA" > "$SHA_FILE"
# Remove swiftlint.zip
rm "$SWIFTLINT_DIR/swiftlint.zip"
fi
if [ ! -f "$SHA_FILE" ] || [ "$(cat "$SHA_FILE")" != "$EXPECTED_SHA" ]; then
echo "Invalid SwiftLint, sha doesn't match the expected download."
exit 1
fi
DARWIN_PATH="$(dirname "$0")/../node_modules/@expo/swiftlint/bin/darwin-arm64/swiftlint"
LINUX_PATH="$(dirname "$0")/../node_modules/@expo/swiftlint/bin/linux-x64/swiftlint"
CMD="$(dirname "$0")/../swiftlint/swiftlint"
if [ "$mode" = "fix" ]; then
$CMD --fix
elif [ "$mode" = "lint" ]; then
$CMD --strict
else
echo "Invalid mode. Use 'fix' or 'lint'."
exit 1
fi