Skip to content

Commit 56ed2f4

Browse files
committed
fix(hooks): replace echo with printf for consistent output
Replaced all echo statements with printf in git hooks for better cross-platform compatibility and consistent output formatting.
1 parent 35c5e57 commit 56ed2f4

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

.git-hooks/commit-msg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ALLOWED_PUBLIC_KEY="sktsec_t_--RAN5U4ivauy4w37-6aoKyYPDt5ZbaT5JBVMqiwKo_api"
1515
ERRORS=0
1616

1717
# Get files in this commit (for security checks).
18-
COMMITTED_FILES=$(git diff --cached --name-only --diff-filter=ACM 2>/dev/null || echo "")
18+
COMMITTED_FILES=$(git diff --cached --name-only --diff-filter=ACM 2>/dev/null || printf "\n")
1919

2020
# Quick checks for critical issues in committed files.
2121
if [ -n "$COMMITTED_FILES" ]; then
@@ -24,7 +24,7 @@ if [ -n "$COMMITTED_FILES" ]; then
2424
# Check for Socket API keys (except allowed).
2525
if grep -E 'sktsec_[a-zA-Z0-9_-]+' "$file" 2>/dev/null | grep -v "$ALLOWED_PUBLIC_KEY" | grep -v 'your_api_key_here' | grep -v 'fake-token' | grep -v 'test-token' | grep -v '\.example' | grep -q .; then
2626
echo "${RED}✗ SECURITY: Potential API key detected in commit!${NC}"
27-
echo "File: $file"
27+
printf "File: %s\n" "$file"
2828
ERRORS=$((ERRORS + 1))
2929
fi
3030

.git-hooks/pre-commit

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,32 @@ fi
2626
ERRORS=0
2727

2828
# Check for .DS_Store files.
29-
echo "Checking for .DS_Store files..."
29+
printf "Checking for .DS_Store files...\n"
3030
if echo "$STAGED_FILES" | grep -q '\.DS_Store'; then
3131
echo "${RED}✗ ERROR: .DS_Store file detected!${NC}"
3232
echo "$STAGED_FILES" | grep '\.DS_Store'
3333
ERRORS=$((ERRORS + 1))
3434
fi
3535

3636
# Check for log files.
37-
echo "Checking for log files..."
37+
printf "Checking for log files...\n"
3838
if echo "$STAGED_FILES" | grep -E '\.log$' | grep -v 'test.*\.log'; then
3939
echo "${RED}✗ ERROR: Log file detected!${NC}"
4040
echo "$STAGED_FILES" | grep -E '\.log$' | grep -v 'test.*\.log'
4141
ERRORS=$((ERRORS + 1))
4242
fi
4343

4444
# Check for .env files.
45-
echo "Checking for .env files..."
45+
printf "Checking for .env files...\n"
4646
if echo "$STAGED_FILES" | grep -E '^\.env(\.local)?$'; then
4747
echo "${RED}✗ ERROR: .env or .env.local file detected!${NC}"
4848
echo "$STAGED_FILES" | grep -E '^\.env(\.local)?$'
49-
echo "These files should never be committed. Use .env.example instead."
49+
printf "These files should never be committed. Use .env.example instead.\n"
5050
ERRORS=$((ERRORS + 1))
5151
fi
5252

5353
# Check for hardcoded user paths (generic detection).
54-
echo "Checking for hardcoded personal paths..."
54+
printf "Checking for hardcoded personal paths...\n"
5555
for file in $STAGED_FILES; do
5656
if [ -f "$file" ]; then
5757
# Skip test files and hook scripts.
@@ -63,26 +63,26 @@ for file in $STAGED_FILES; do
6363
if grep -E '(/Users/[^/\s]+/|/home/[^/\s]+/|C:\\Users\\[^\\]+\\)' "$file" 2>/dev/null | grep -q .; then
6464
echo "${RED}✗ ERROR: Hardcoded personal path found in: $file${NC}"
6565
grep -n -E '(/Users/[^/\s]+/|/home/[^/\s]+/|C:\\Users\\[^\\]+\\)' "$file" | head -3
66-
echo "Replace with relative paths or environment variables."
66+
printf "Replace with relative paths or environment variables.\n"
6767
ERRORS=$((ERRORS + 1))
6868
fi
6969
fi
7070
done
7171

7272
# Check for Socket API keys.
73-
echo "Checking for API keys..."
73+
printf "Checking for API keys...\n"
7474
for file in $STAGED_FILES; do
7575
if [ -f "$file" ]; then
7676
if grep -E 'sktsec_[a-zA-Z0-9_-]+' "$file" 2>/dev/null | grep -v "$ALLOWED_PUBLIC_KEY" | grep -v 'your_api_key_here' | grep -v 'SOCKET_SECURITY_API_KEY=' | grep -v 'fake-token' | grep -v 'test-token' | grep -q .; then
7777
echo "${YELLOW}⚠ WARNING: Potential API key found in: $file${NC}"
7878
grep -n 'sktsec_' "$file" | grep -v "$ALLOWED_PUBLIC_KEY" | grep -v 'your_api_key_here' | grep -v 'fake-token' | grep -v 'test-token' | head -3
79-
echo "If this is a real API key, DO NOT COMMIT IT."
79+
printf "If this is a real API key, DO NOT COMMIT IT.\n"
8080
fi
8181
fi
8282
done
8383

8484
# Check for common secret patterns.
85-
echo "Checking for potential secrets..."
85+
printf "Checking for potential secrets...\n"
8686
for file in $STAGED_FILES; do
8787
if [ -f "$file" ]; then
8888
# Skip test files, example files, and hook scripts.
@@ -113,9 +113,9 @@ for file in $STAGED_FILES; do
113113
done
114114

115115
if [ $ERRORS -gt 0 ]; then
116-
echo ""
116+
printf "\n"
117117
echo "${RED}✗ Security check failed with $ERRORS error(s).${NC}"
118-
echo "Fix the issues above and try again."
118+
printf "Fix the issues above and try again.\n"
119119
exit 1
120120
fi
121121

.git-hooks/pre-push

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ while read local_ref local_sha remote_ref remote_sha; do
7171
printf "Checking files for security issues...\n"
7272

7373
# Get all files changed in these commits.
74-
CHANGED_FILES=$(git diff --name-only "$range" 2>/dev/null || echo "")
74+
CHANGED_FILES=$(git diff --name-only "$range" 2>/dev/null || printf "\n")
7575

7676
if [ -n "$CHANGED_FILES" ]; then
7777
# Check for sensitive files.

.husky/pre-commit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
if [ -z "${DISABLE_PRECOMMIT_LINT}" ]; then
55
pnpm lint --staged
66
else
7-
echo "Skipping lint due to DISABLE_PRECOMMIT_LINT env var"
7+
printf "Skipping lint due to DISABLE_PRECOMMIT_LINT env var\n"
88
fi
99

1010
if [ -z "${DISABLE_PRECOMMIT_TEST}" ]; then
1111
dotenvx -q run -f .env.precommit -- pnpm test --staged
1212
else
13-
echo "Skipping testing due to DISABLE_PRECOMMIT_TEST env var"
13+
printf "Skipping testing due to DISABLE_PRECOMMIT_TEST env var\n"
1414
fi

0 commit comments

Comments
 (0)