|
3 | 3 | # Check for verbose flag |
4 | 4 | VERBOSE=false |
5 | 5 | if [[ "$*" == *"--verbose"* ]]; then |
6 | | - VERBOSE=true |
| 6 | + VERBOSE=true |
7 | 7 | fi |
8 | 8 |
|
9 | 9 | # Accept --verbose before check/fix |
10 | 10 | if [[ "$1" == "--verbose" ]]; then |
11 | | - MODE="${2:-check}" |
| 11 | + MODE="${2:-check}" |
12 | 12 | else |
13 | | - MODE="${1:-check}" |
| 13 | + MODE="${1:-check}" |
14 | 14 | fi |
15 | 15 |
|
16 | 16 | # Validate the mode |
17 | 17 | if [[ "$MODE" != "check" && "$MODE" != "fix" ]]; then |
18 | | - echo "❌ Invalid mode: $MODE" |
19 | | - echo "Usage: $0 [check|fix] [--verbose]" |
20 | | - echo " check: Run linters in check mode (default)" |
21 | | - echo " fix: Run linters in fix mode to auto-fix issues" |
22 | | - echo " --verbose: Show detailed output from linters" |
23 | | - exit 1 |
| 18 | + echo "❌ Invalid mode: $MODE" |
| 19 | + echo "Usage: $0 [check|fix] [--verbose]" |
| 20 | + echo " check: Run linters in check mode (default)" |
| 21 | + echo " fix: Run linters in fix mode to auto-fix issues" |
| 22 | + echo " --verbose: Show detailed output from linters" |
| 23 | + exit 1 |
24 | 24 | fi |
25 | 25 |
|
26 | 26 | print_install_instructions() { |
27 | | - echo "🔧 FIX:" |
28 | | - echo " Shopify employee? Run 'dev up'" |
29 | | - echo " Not a Shopify employee? Install Mint and run 'mint bootstrap':" |
30 | | - echo " brew install mint" |
31 | | - echo " mint bootstrap" |
32 | | - echo " See: https://github.com/yonaskolb/Mint" |
| 27 | + echo "🔧 FIX:" |
| 28 | + echo " Shopify employee? Run 'dev up'" |
| 29 | + echo " Not a Shopify employee? Install Mint and run 'mint bootstrap':" |
| 30 | + echo " brew install mint" |
| 31 | + echo " mint bootstrap" |
| 32 | + echo " See: https://github.com/yonaskolb/Mint" |
33 | 33 | } |
34 | 34 |
|
35 | 35 | if ! command -v mint >/dev/null; then |
36 | | - echo "❌ Mint is not installed" |
37 | | - print_install_instructions |
38 | | - exit 1 |
| 36 | + echo "❌ Mint is not installed" |
| 37 | + print_install_instructions |
| 38 | + exit 1 |
39 | 39 | fi |
40 | 40 |
|
41 | 41 | if [ ! -f "Mintfile" ]; then |
42 | | - echo "❌ Mintfile not found in the current directory" |
43 | | - exit 1 |
| 42 | + echo "❌ Mintfile not found in the current directory" |
| 43 | + exit 1 |
44 | 44 | fi |
45 | 45 |
|
46 | | -SWIFTLINT="mint run swiftlint" |
47 | | -SWIFTFORMAT="mint run swiftformat" |
| 46 | +expected_swiftlint="$(sed -n 's#^realm/SwiftLint@##p' Mintfile)" |
| 47 | +expected_swiftformat="$(sed -n 's#^nicklockwood/SwiftFormat@##p' Mintfile)" |
| 48 | + |
| 49 | +if [ -z "$expected_swiftlint" ] || [ -z "$expected_swiftformat" ]; then |
| 50 | + echo "❌ Could not read SwiftLint and SwiftFormat versions from Mintfile" |
| 51 | + print_install_instructions |
| 52 | + exit 1 |
| 53 | +fi |
| 54 | + |
| 55 | +mint_package_has_version() { |
| 56 | + local package_name=$1 |
| 57 | + local package_version=$2 |
| 58 | + |
| 59 | + mint list | awk -v package_name="$package_name" -v package_version="$package_version" ' |
| 60 | + $1 == package_name { in_package = 1; next } |
| 61 | + in_package && $1 !~ /^-/ { exit 1 } |
| 62 | + in_package && $1 == "-" && $2 == package_version { found = 1; exit 0 } |
| 63 | + END { exit found ? 0 : 1 } |
| 64 | + ' |
| 65 | +} |
| 66 | + |
| 67 | +if ! mint_package_has_version "SwiftLint" "$expected_swiftlint"; then |
| 68 | + echo "❌ SwiftLint $expected_swiftlint is not installed" |
| 69 | + print_install_instructions |
| 70 | + exit 1 |
| 71 | +fi |
| 72 | + |
| 73 | +if ! mint_package_has_version "SwiftFormat" "$expected_swiftformat"; then |
| 74 | + echo "❌ SwiftFormat $expected_swiftformat is not installed" |
| 75 | + print_install_instructions |
| 76 | + exit 1 |
| 77 | +fi |
| 78 | + |
| 79 | +swiftlint_bin="$(mint which swiftlint)" |
| 80 | +swiftformat_bin="$(mint which swiftformat)" |
| 81 | + |
| 82 | +if [ "$("$swiftlint_bin" version)" != "$expected_swiftlint" ]; then |
| 83 | + echo "❌ SwiftLint version mismatch. Expected $expected_swiftlint, found $("$swiftlint_bin" version)" |
| 84 | + print_install_instructions |
| 85 | + exit 1 |
| 86 | +fi |
| 87 | + |
| 88 | +if [ "$("$swiftformat_bin" --version)" != "$expected_swiftformat" ]; then |
| 89 | + echo "❌ SwiftFormat version mismatch. Expected $expected_swiftformat, found $("$swiftformat_bin" --version)" |
| 90 | + print_install_instructions |
| 91 | + exit 1 |
| 92 | +fi |
| 93 | + |
| 94 | +SWIFTLINT="$swiftlint_bin" |
| 95 | +SWIFTFORMAT="$swiftformat_bin" |
48 | 96 |
|
49 | 97 | QUIET_FLAG="" |
50 | 98 | if [[ "$VERBOSE" == "false" ]]; then |
51 | | - QUIET_FLAG="--quiet" |
| 99 | + QUIET_FLAG="--quiet" |
52 | 100 | fi |
53 | 101 |
|
54 | 102 | if [[ "$MODE" == "fix" ]]; then |
55 | | - $SWIFTLINT lint --fix $QUIET_FLAG |
| 103 | + $SWIFTLINT lint --fix --no-cache $QUIET_FLAG |
56 | 104 | fi |
57 | 105 |
|
58 | 106 | # SwiftLint doesn't report errors when running in fix mode |
59 | 107 | # Running again in strict mode to ensure no errors are missed. |
60 | 108 | # Run from the directory containing .swiftlint.yml so its `included:` paths |
61 | | -# resolve consistently — in the monorepo that's the repo root, not the |
62 | | -# script's CWD (which is swift/, where Mintfile lives). |
| 109 | +# resolve consistently. |
63 | 110 | PROJECT_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)" |
64 | | -(cd "$PROJECT_ROOT" && $SWIFTLINT lint --strict $QUIET_FLAG) |
| 111 | +(cd "$PROJECT_ROOT" && $SWIFTLINT lint --strict --no-cache $QUIET_FLAG) |
65 | 112 | LINT_STATUS=$? |
66 | 113 |
|
67 | 114 | if [ $LINT_STATUS -eq 0 ]; then |
68 | | - echo "✅ SwiftLint exit status: $LINT_STATUS" |
| 115 | + echo "✅ SwiftLint exit status: $LINT_STATUS" |
69 | 116 | else |
70 | | - echo "❌ SwiftLint exit status: $LINT_STATUS" |
| 117 | + echo "❌ SwiftLint exit status: $LINT_STATUS" |
71 | 118 | fi |
72 | 119 |
|
73 | | -echo "" |
74 | | - |
75 | 120 | # Run SwiftFormat |
76 | 121 | if [[ "$MODE" == "fix" ]]; then |
77 | | - $SWIFTFORMAT . $QUIET_FLAG |
78 | | - FORMAT_STATUS=$? |
| 122 | + $SWIFTFORMAT . $QUIET_FLAG |
| 123 | + FORMAT_STATUS=$? |
79 | 124 | else |
80 | | - $SWIFTFORMAT . $QUIET_FLAG --lint |
81 | | - FORMAT_STATUS=$? |
| 125 | + $SWIFTFORMAT . $QUIET_FLAG --lint |
| 126 | + FORMAT_STATUS=$? |
82 | 127 | fi |
83 | 128 |
|
84 | 129 | if [ $FORMAT_STATUS -eq 0 ]; then |
85 | | - echo "✅ SwiftFormat exit status: $FORMAT_STATUS" |
| 130 | + echo "✅ SwiftFormat exit status: $FORMAT_STATUS" |
86 | 131 | else |
87 | | - echo "❌ SwiftFormat exit status: $FORMAT_STATUS" |
| 132 | + echo "❌ SwiftFormat exit status: $FORMAT_STATUS" |
88 | 133 | fi |
89 | 134 |
|
90 | 135 | # Function to print error messages for linting issues |
91 | 136 | print_linting_error() { |
92 | | - local tool_name=$1 |
93 | | - echo "❌ $tool_name detected issues that need to be fixed." |
94 | | - if [[ "$MODE" == "check" ]]; then |
95 | | - echo "🔧 How to fix:" |
96 | | - echo " Shopify employee? Run 'dev fix' and resolve remaining issues" |
97 | | - echo " Not a Shopify employee? Run './Scripts/lint fix' and resolve remaining issues" |
98 | | - else |
99 | | - echo "🔧 These files will need to be fixed manually" |
100 | | - fi |
| 137 | + local tool_name=$1 |
| 138 | + echo "❌ $tool_name detected issues that need to be fixed." |
| 139 | + if [[ "$MODE" == "check" ]]; then |
| 140 | + echo "🔧 How to fix:" |
| 141 | + echo " Shopify employee? Run 'dev fix' and resolve remaining issues" |
| 142 | + echo " Not a Shopify employee? Run './Scripts/lint fix' and resolve remaining issues" |
| 143 | + else |
| 144 | + echo "🔧 These files will need to be fixed manually" |
| 145 | + fi |
101 | 146 | } |
102 | 147 |
|
103 | | -# Handle exit codes for check mode |
104 | | -echo "" |
105 | | - |
106 | 148 | if [ $LINT_STATUS -ne 0 ]; then |
107 | | - print_linting_error "SwiftLint" |
108 | | - exit 1 |
| 149 | + print_linting_error "SwiftLint" |
| 150 | + exit 1 |
109 | 151 | fi |
110 | 152 |
|
111 | 153 | if [ $FORMAT_STATUS -ne 0 ]; then |
112 | | - print_linting_error "SwiftFormat" |
113 | | - exit 1 |
| 154 | + print_linting_error "SwiftFormat" |
| 155 | + exit 1 |
114 | 156 | fi |
115 | 157 |
|
116 | 158 | # Run CocoaPods lint (check mode only, not applicable to fix) |
117 | 159 | # Skip with --skip-pod (e.g. in CI where pod lint runs as a separate job) |
118 | 160 | SKIP_POD=false |
119 | 161 | if [[ "$*" == *"--skip-pod"* ]]; then |
120 | | - SKIP_POD=true |
| 162 | + SKIP_POD=true |
121 | 163 | fi |
122 | 164 |
|
123 | 165 | if [[ "$MODE" == "check" && "$SKIP_POD" == "false" ]]; then |
124 | | - echo "" |
125 | | - echo "🔍 Running CocoaPods lint..." |
126 | | - bundle exec pod lib lint --allow-warnings |
127 | | - POD_STATUS=$? |
128 | | - |
129 | | - if [ $POD_STATUS -eq 0 ]; then |
130 | | - echo "✅ CocoaPods lint exit status: $POD_STATUS" |
131 | | - else |
132 | | - echo "❌ CocoaPods lint exit status: $POD_STATUS" |
133 | | - echo "❌ CocoaPods detected issues that need to be fixed." |
134 | | - echo "🔧 Run 'bundle exec pod lib lint --allow-warnings --verbose' for details" |
135 | | - exit 1 |
136 | | - fi |
| 166 | + echo "🔍 Running CocoaPods lint..." |
| 167 | + |
| 168 | + POD_LOG="" |
| 169 | + if [[ "$VERBOSE" == "true" ]]; then |
| 170 | + bundle exec pod lib lint --allow-warnings |
| 171 | + else |
| 172 | + POD_LOG="$(mktemp "${TMPDIR:-/tmp}/checkout-kit-pod-lint.XXXXXX")" |
| 173 | + bundle exec pod lib lint --allow-warnings >"$POD_LOG" 2>&1 |
| 174 | + fi |
| 175 | + POD_STATUS=$? |
| 176 | + |
| 177 | + if [ $POD_STATUS -eq 0 ]; then |
| 178 | + echo "✅ CocoaPods lint exit status: $POD_STATUS" |
| 179 | + else |
| 180 | + if [ -n "$POD_LOG" ]; then |
| 181 | + cat "$POD_LOG" |
| 182 | + rm -f "$POD_LOG" |
| 183 | + fi |
| 184 | + |
| 185 | + echo "❌ CocoaPods lint exit status: $POD_STATUS" |
| 186 | + echo "❌ CocoaPods detected issues that need to be fixed." |
| 187 | + echo "🔧 Run 'bundle exec pod lib lint --allow-warnings --verbose' for details" |
| 188 | + exit 1 |
| 189 | + fi |
| 190 | + |
| 191 | + if [ -n "$POD_LOG" ]; then |
| 192 | + rm -f "$POD_LOG" |
| 193 | + fi |
137 | 194 | fi |
0 commit comments