Skip to content

Commit 77a5f3e

Browse files
committed
feat: initialize project with husky for pre-commit formatting and add format check workflow
1 parent 0a330e1 commit 77a5f3e

4 files changed

Lines changed: 83 additions & 0 deletions

File tree

.github/workflows/format-check.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Format Check
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**.sol'
7+
8+
jobs:
9+
check:
10+
name: Check Code Formatting
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: 📥 Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: 🔧 Install Foundry
18+
uses: foundry-rs/foundry-toolchain@v1
19+
with:
20+
version: nightly
21+
22+
- name: 🔍 Check formatting
23+
run: |
24+
if ! forge fmt --check; then
25+
echo ""
26+
echo "❌ Code is not properly formatted!"
27+
echo "💡 Run 'forge fmt' locally and commit the changes"
28+
echo ""
29+
exit 1
30+
fi
31+
echo "✅ All code is properly formatted!"

.husky/pre-commit

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
echo ""
5+
echo "🔨 Formatting Solidity code..."
6+
7+
# Run forge fmt
8+
forge fmt
9+
10+
# Check for changes and stage them
11+
if [ -n "$(git diff --name-only *.sol **/*.sol 2>/dev/null)" ]; then
12+
echo "✨ Code formatted! Adding to commit..."
13+
git add *.sol **/*.sol 2>/dev/null || true
14+
echo "✅ Formatted files staged"
15+
else
16+
echo "✅ No formatting needed"
17+
fi
18+
19+
echo ""

package-lock.json

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"devDependencies": {
3+
"husky": "^9.1.7"
4+
}
5+
}

0 commit comments

Comments
 (0)