Skip to content

Commit

Permalink
Update format_exercises.sh to check lib.cairo formatting too
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNeshi authored Dec 13, 2024
1 parent 01caba2 commit 1633ff6
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions bin/format_exercises.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand All @@ -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

0 comments on commit 1633ff6

Please sign in to comment.