Skip to content

Commit 6d68308

Browse files
authored
[FIX] - Pre-commit hook over staged files (#394)
* fix: pre-commit hook updated to only apply prettier and taplo over staged files * update llms.txt
1 parent f0056eb commit 6d68308

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

.husky/pre-commit

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,36 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
echo "Running Prettier on .snippets/code/**/*.{js,json,html}"
5-
npx prettier --write .snippets/code/**/*.{js,json,html}
6-
7-
# Find all TOML files and normalize paths
8-
ALL_FILES=$(find .snippets/code/ -type f -name "*.toml" | sed 's|//|/|g')
9-
10-
# Run Taplo if there are files to format
11-
if [ -n "$ALL_FILES" ]; then
12-
echo "Formatting files with Taplo..."
13-
echo "$ALL_FILES" | while read -r file; do
14-
echo "Formatting $file"
15-
npx taplo fmt "$file"
16-
if [ $? -ne 0 ]; then
17-
echo "Error: Taplo formatting failed."
18-
exit 1
19-
fi
20-
done
4+
# Get list of staged files that match our patterns
5+
STAGED_JS_JSON_HTML=$(git diff --cached --name-only --diff-filter=AM | grep -E '^.snippets/code/.*\.(js|json|html)$' || true)
6+
STAGED_TOML=$(git diff --cached --name-only --diff-filter=AM | grep -E '^.snippets/code/.*\.toml$' || true)
7+
8+
# Format JavaScript, JSON, and HTML files if any exist
9+
if [ -n "$STAGED_JS_JSON_HTML" ]; then
10+
echo "Running Prettier on staged files..."
11+
echo "$STAGED_JS_JSON_HTML" | while read -r file; do
12+
if [ -f "$file" ]; then
13+
echo "Formatting $file"
14+
npx prettier --write "$file" || exit 1
15+
git add "$file"
16+
fi
17+
done
2118
else
22-
echo "No files to format."
19+
echo "No JavaScript, JSON, or HTML files to format."
20+
fi
21+
22+
# Format TOML files if any exist
23+
if [ -n "$STAGED_TOML" ]; then
24+
echo "Formatting TOML files with Taplo..."
25+
echo "$STAGED_TOML" | while read -r file; do
26+
if [ -f "$file" ]; then
27+
echo "Formatting $file"
28+
npx taplo fmt "$file" || exit 1
29+
git add "$file"
30+
fi
31+
done
32+
else
33+
echo "No TOML files to format."
2334
fi
2435

2536
echo "Adding formatted files back to the commit..."

llms.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24532,7 +24532,7 @@ To prepare an account, follow these steps:
2453224532

2453324533
![](/images/tutorials/polkadot-sdk/parachains/zero-to-hero/deploy-to-testnet/deploy-to-testnet-4.webp)
2453424534

24535-
After a few seconds, you will receive 100 PAS tokens in your account.
24535+
After a few seconds, you will receive 5000 PAS tokens in your account.
2453624536

2453724537
## Reserve a Parachain Identifier
2453824538

0 commit comments

Comments
 (0)