Skip to content

Commit 9ca0617

Browse files
committed
fix: make TypeScript checking optional with clear project-wide scope warning
TypeScript's tsc command requires full project context for accurate type checking and cannot be limited to only staged files. This change: - Adds SKIP_TS_CHECK environment variable to bypass the check - Warns users that TypeScript checks the entire project - Provides clear instructions when check fails on unrelated errors - Improves error messages to explain the project-wide scope Usage: - One-time skip: SKIP_TS_CHECK=1 git commit - Permanent skip: export SKIP_TS_CHECK=1 (add to shell profile) This prevents blocking commits due to unrelated TypeScript errors while still allowing teams to enforce TypeScript checking when desired.
1 parent ad7ad23 commit 9ca0617

File tree

2 files changed

+653
-5
lines changed

2 files changed

+653
-5
lines changed

.husky/pre-commit

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,24 @@ main() {
203203
log_info "⏭️ Skipping Markdown validation (no markdown files staged)"
204204
fi
205205

206-
# 5. TypeScript type checking (only if TS files are staged)
207-
if has_staged_files "\.(ts|tsx)$"; then
208-
log_step "Running TypeScript type checking..."
209-
time_command yarn typecheck || exit_with_error "TypeScript type checking failed. Fix type errors before committing."
210-
log_success "TypeScript type checking passed"
206+
# 5. TypeScript type checking (optional - checks entire project, not just staged files)
207+
# Note: TypeScript requires full project context for accurate type checking,
208+
# so it cannot be limited to only staged files like prettier/markdownlint.
209+
# Set SKIP_TS_CHECK=1 to skip this check if it's blocking on unrelated errors.
210+
if [ "${SKIP_TS_CHECK:-0}" = "1" ]; then
211+
log_info "⏭️ Skipping TypeScript check (SKIP_TS_CHECK=1)"
212+
elif has_staged_files "\.(ts|tsx)$"; then
213+
log_warning "Running TypeScript check on entire project (not just staged files)"
214+
log_info "💡 Set SKIP_TS_CHECK=1 to skip this check if it blocks on unrelated errors"
215+
if time_command yarn typecheck; then
216+
log_success "TypeScript type checking passed"
217+
else
218+
log_error "TypeScript type checking failed on project-wide check"
219+
log_info "💡 This may include errors in files you didn't modify"
220+
log_info "💡 To commit anyway: SKIP_TS_CHECK=1 git commit"
221+
log_info "💡 To disable permanently: Add 'export SKIP_TS_CHECK=1' to your shell profile"
222+
exit 1
223+
fi
211224
else
212225
log_info "⏭️ Skipping TypeScript check (no TypeScript files staged)"
213226
fi

0 commit comments

Comments
 (0)