Skip to content

Commit d9c9318

Browse files
Created a script to run all files and fix everything
1 parent 7ad9d19 commit d9c9318

File tree

3 files changed

+137
-6
lines changed

3 files changed

+137
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
.history
1010
.svn/
1111
*.env
12+
*.bak
1213

1314
# IntelliJ related
1415
*.iml

scripts/auto_fix_all.sh

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/bin/bash
2+
# Auto-fix all code quality violations
3+
# Usage:
4+
# ./scripts/auto_fix_all.sh --dry-run # Preview what would be fixed
5+
# ./scripts/auto_fix_all.sh # Apply all auto-fixes
6+
7+
set -e
8+
9+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10+
repo_root="$(cd "$script_dir/.." && pwd)"
11+
cd "$repo_root"
12+
13+
DRY_RUN=false
14+
if [[ "$1" == "--dry-run" ]]; then
15+
DRY_RUN=true
16+
fi
17+
18+
echo "==================================="
19+
echo "🔧 Auto-fixing Code Quality Issues"
20+
echo "==================================="
21+
echo
22+
23+
# Track fixes applied
24+
fixes_applied=0
25+
26+
if [[ "$DRY_RUN" == "true" ]]; then
27+
echo "DRY RUN MODE - No changes will be made"
28+
echo
29+
echo "Would run the following fixes:"
30+
echo "1. Comment spacing fixes"
31+
echo "2. TODO format fixes"
32+
echo "3. One-line if brace removal"
33+
echo "4. File/directory renaming"
34+
echo "5. Dart formatting"
35+
echo
36+
exit 0
37+
fi
38+
39+
echo "🔍 1. Fixing comment spacing..."
40+
if bash scripts/comment_space.sh --fix; then
41+
echo "✅ Comment spacing fixes completed"
42+
fixes_applied=$((fixes_applied + 1))
43+
else
44+
echo "❌ Comment spacing fixes failed"
45+
fi
46+
echo
47+
48+
echo "🔍 2. Fixing TODO comment formats..."
49+
if bash scripts/todo_date_check.sh --fix; then
50+
echo "✅ TODO format fixes completed"
51+
fixes_applied=$((fixes_applied + 1))
52+
else
53+
echo "❌ TODO format fixes failed"
54+
fi
55+
echo
56+
57+
echo "🔍 3. Fixing one-line if statement braces..."
58+
if bash scripts/no_braces_one_line_if.sh --fix; then
59+
echo "✅ One-line if brace fixes completed"
60+
fixes_applied=$((fixes_applied + 1))
61+
else
62+
echo "❌ One-line if brace fixes failed"
63+
fi
64+
echo
65+
66+
echo "🔍 4. Fixing file and directory naming..."
67+
if bash scripts/file_dir_snake_case.sh --fix; then
68+
echo "✅ File/directory naming fixes completed"
69+
fixes_applied=$((fixes_applied + 1))
70+
else
71+
echo "❌ File/directory naming fixes failed"
72+
fi
73+
echo
74+
75+
echo "🎨 5. Running dart format..."
76+
if bash scripts/dart_format_files.sh; then
77+
echo "✅ Dart formatting completed"
78+
else
79+
echo "❌ Dart formatting failed"
80+
fi
81+
echo
82+
83+
echo "==============================="
84+
echo "🎯 Auto-fix Summary"
85+
echo "==============================="
86+
echo "Fix operations completed: $fixes_applied/4"
87+
echo
88+
89+
if [[ $fixes_applied -gt 0 ]]; then
90+
echo "📊 Changes made - you can now commit them:"
91+
echo " git add -A"
92+
echo " git commit -m 'Auto-fix: Code quality improvements'"
93+
echo
94+
95+
echo "🔍 Final quality check..."
96+
echo
97+
98+
echo "Comment spacing status:"
99+
bash scripts/comment_space.sh | tail -2
100+
echo
101+
102+
echo "TODO format status:"
103+
bash scripts/todo_date_check.sh | tail -2
104+
echo
105+
106+
echo "One-line if braces status:"
107+
bash scripts/no_braces_one_line_if.sh | tail -2
108+
echo
109+
110+
echo "File/directory naming status:"
111+
bash scripts/file_dir_snake_case.sh | tail -2
112+
else
113+
echo "No fixes were needed or all fixes failed."
114+
fi
115+
116+
echo
117+
echo "✨ Auto-fix process completed!"

scripts/comment_space.sh

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,17 @@ while IFS=: read -r filepath line_number line_content; do
4646
violations_found=$((violations_found + 1))
4747

4848
if [[ "$MODE" == "fix" ]]; then
49-
# Show suggestion by adding space after //
49+
# Actually fix the file by adding space after //
5050
fixed_line=$(echo "$line_content" | sed 's|//\([^ /]\)|// \1|g')
51-
echo " Suggestion: $fixed_line"
51+
echo " Fixing: $fixed_line"
52+
53+
# Use sed to fix the specific line in the file
54+
# Escape special characters in the line for sed
55+
escaped_line=$(printf '%s\n' "$line_content" | sed 's/[[\.*^$()+?{|]/\\&/g')
56+
escaped_fixed=$(printf '%s\n' "$fixed_line" | sed 's/[[\.*^$()+?{|]/\\&/g')
57+
58+
# Replace the line in the file
59+
sed -i.bak "${line_number}s|${escaped_line}|${escaped_fixed}|" "$filepath"
5260
fi
5361
fi
5462
done < "$temp_file"
@@ -65,10 +73,15 @@ echo "Files scanned: $total_files"
6573
echo "Violations found: $violations_found"
6674

6775
if [[ $violations_found -gt 0 ]]; then
68-
echo "Comments should have a space after //"
69-
echo " GOOD: // This is a proper comment"
70-
echo " BAD: //This comment is missing a space"
71-
exit 1
76+
if [[ "$MODE" == "fix" ]]; then
77+
echo "Fixed $violations_found comment spacing violation(s)."
78+
exit 0
79+
else
80+
echo "Comments should have a space after //"
81+
echo " GOOD: // This is a proper comment"
82+
echo " BAD: //This comment is missing a space"
83+
exit 1
84+
fi
7285
else
7386
echo "All comments have proper spacing after //"
7487
exit 0

0 commit comments

Comments
 (0)