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
56 changes: 28 additions & 28 deletions scripts/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ echo
# Function to check if tools are available
check_tools() {
local missing_tools=()

for tool in swiftformat swiftlint; do
if ! command_exists "$tool"; then
missing_tools+=("$tool")
fi
done

if [[ ${#missing_tools[@]} -gt 0 ]]; then
log_warning "Missing tools: ${missing_tools[*]}"
log_info "Install with: brew bundle install"
Expand All @@ -54,28 +54,28 @@ check_tools() {
# Run SwiftFormat on staged files
run_swiftformat() {
log_info "πŸ“ Running SwiftFormat..."

local format_failed=false

if $AUTO_FIX; then
# Format staged files
echo "$staged_files" | while read -r file; do
if [[ -f "$file" ]]; then
swiftformat "$file"
fi
done

# Check if any files were modified
local modified_files
modified_files=$(echo "$staged_files" | xargs git diff --name-only 2>/dev/null || true)

if [[ -n "$modified_files" ]]; then
log_info "SwiftFormat made changes to:"
echo "$modified_files" | sed 's/^/ β€’ /'

# Re-stage the formatted files
echo "$modified_files" | xargs git add

log_success "Formatted files re-staged for commit"
else
log_success "No formatting changes needed"
Expand All @@ -90,7 +90,7 @@ run_swiftformat() {
fi
fi
done

if [[ -n "$format_issues" ]]; then
log_error "SwiftFormat issues found in: $format_issues"
log_info "Fix with: ./scripts/format.sh --fix"
Expand All @@ -99,7 +99,7 @@ run_swiftformat() {
log_success "SwiftFormat check passed"
fi
fi

if $format_failed; then
return 1
fi
Expand All @@ -108,18 +108,18 @@ run_swiftformat() {
# Run SwiftLint on staged files
run_swiftlint() {
log_info "πŸ” Running SwiftLint..."

local lint_failed=false
local temp_file=$(mktemp)

# Create temporary file with staged file list
echo "$staged_files" > "$temp_file"
if swiftlint lint --use-stdin-paths < "$temp_file" 2>&1; then

if swiftlint lint < "$temp_file" 2>&1; then
log_success "SwiftLint check passed"
else
local exit_code=$?

if $ALLOW_WARNINGS && [[ $exit_code -eq 2 ]]; then
log_warning "SwiftLint found warnings (allowing commit)"
else
Expand All @@ -128,9 +128,9 @@ run_swiftlint() {
lint_failed=true
fi
fi

rm -f "$temp_file"

if $lint_failed; then
return 1
fi
Expand All @@ -139,9 +139,9 @@ run_swiftlint() {
# Check for common issues
run_basic_checks() {
log_info "βœ… Running basic checks..."

local issues=()

# Check for TODO/FIXME in staged files (informational)
local todo_count=0
echo "$staged_files" | while read -r file; do
Expand All @@ -153,11 +153,11 @@ run_basic_checks() {
fi
fi
done

if [[ $todo_count -gt 0 ]]; then
log_info "Found TODO/FIXME comments in $todo_count file(s) (informational)"
fi

# Check for debug prints (warning)
local debug_prints=()
echo "$staged_files" | while read -r file; do
Expand All @@ -167,33 +167,33 @@ run_basic_checks() {
fi
fi
done

if [[ ${#debug_prints[@]} -gt 0 ]]; then
log_warning "Found print() statements in:"
printf '%s\n' "${debug_prints[@]}" | sed 's/^/ β€’ /'
log_info "Consider removing debug prints before committing"
fi

log_success "Basic checks completed"
}

# Main execution
main() {
check_tools

local checks_failed=false

# Run all checks
if ! run_swiftformat; then
checks_failed=true
fi

if ! run_swiftlint; then
checks_failed=true
fi

run_basic_checks

echo
if $checks_failed; then
log_error "❌ Pre-commit checks failed"
Expand Down
26 changes: 26 additions & 0 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,31 @@ Generated iOS project using SwiftProjectTemplate with:
fi
}

cleanup_template_files() {
log_info "Cleaning up template-specific files..."

# Remove template-validation.yml workflow since this is now a generated project
local template_validation_workflow=".github/workflows/template-validation.yml"
if [[ -f "$template_validation_workflow" ]]; then
rm "$template_validation_workflow"
log_success "Removed template-validation.yml (not needed for generated projects)"
fi

# Remove empty .github/workflows directory if it has no other workflows
local workflows_dir=".github/workflows"
if [[ -d "$workflows_dir" && -z "$(ls -A "$workflows_dir" 2>/dev/null)" ]]; then
rmdir "$workflows_dir"
log_info "Removed empty workflows directory"
fi

# Remove empty .github directory if it has no other content
local github_dir=".github"
if [[ -d "$github_dir" && -z "$(ls -A "$github_dir" 2>/dev/null)" ]]; then
rmdir "$github_dir"
log_info "Removed empty .github directory"
fi
}

display_next_steps() {
log_success "πŸŽ‰ Project setup complete!"
echo
Expand Down Expand Up @@ -1211,6 +1236,7 @@ main() {
verify_or_create_git_repository
setup_git_hooks
create_initial_commit
cleanup_template_files

display_next_steps
}
Expand Down
2 changes: 1 addition & 1 deletion templates/.swiftlint.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ cyclomatic_complexity:
nesting:
type_level:
warning: 3
statement_level:
function_level:
warning: 5

identifier_name:
Expand Down
Loading