diff --git a/bin/format_exercises.sh b/bin/format_exercises.sh index b97c21a7..07354b58 100755 --- a/bin/format_exercises.sh +++ b/bin/format_exercises.sh @@ -9,6 +9,8 @@ repo=$(git rev-parse --show-toplevel) # directory and format Cairo files exercises="$repo/exercises/*/*" +FMT_ARGS="$@" + for exercise_dir in $exercises; do cd "$exercise_dir" @@ -19,6 +21,16 @@ for exercise_dir in $exercises; do continue fi + if [ -f "./src/lib.cairo" ]; then + scaffold_solution="./src/lib.cairo" + else + echo "Could not locate scaffold implementation for $exercise" + exit 1 + fi + + # check scaffold solution formatting + scarb fmt $FMT_ARGS + # scarb fmt cannot currently format individual files, so we have to # temporarily move the solution files into the Cairo package, where # 'scarb fmt' can format it as well @@ -34,13 +46,17 @@ for exercise_dir in $exercises; do exit 1 fi - # move the solution file into the package - cp "$solution_file" "$tmp_file" + # backup scaffold solution + cp "$scaffold_solution" "$tmp_file" + + # copy the example solution file into the package + cp "$solution_file" "$scaffold_solution" - scarb fmt "$@" + # check example solution formatting + scarb fmt $FMT_ARGS - # move the solution file back - cp "$tmp_file" "$solution_file" + # copy the scaffold solution back + cp "$tmp_file" "$scaffold_solution" rm "$tmp_file" done