Skip to content

Commit aaf4fc0

Browse files
committed
Add basic automatic linting
1 parent be803de commit aaf4fc0

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,29 @@ cd sentire
3030
go build -o sentire ./cmd/sentire
3131
```
3232

33+
## Development Setup
34+
35+
### Git Hooks
36+
37+
To prevent formatting issues and ensure code quality, install the Git hooks:
38+
39+
```bash
40+
# Install pre-commit hook for automatic Go formatting
41+
./scripts/install-hooks.sh
42+
```
43+
44+
The pre-commit hook will automatically format Go files using `gofmt -s` before each commit, ensuring consistency with CI requirements.
45+
46+
To format all Go files manually:
47+
```bash
48+
make fmt
49+
```
50+
51+
To bypass the hook temporarily (not recommended):
52+
```bash
53+
git commit --no-verify
54+
```
55+
3356
## Configuration
3457

3558
Before using sentire, you must set your Sentry API token as an environment variable:

scripts/install-hooks.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
# Install Git hooks for the Sentire project
3+
4+
set -e
5+
6+
# Check if we're in a git repository
7+
if [ ! -d ".git" ]; then
8+
echo "Error: This script must be run from the root of the git repository"
9+
exit 1
10+
fi
11+
12+
# Create hooks directory if it doesn't exist
13+
mkdir -p .git/hooks
14+
15+
# Install pre-commit hook
16+
echo "Installing pre-commit hook..."
17+
cp scripts/pre-commit .git/hooks/pre-commit
18+
chmod +x .git/hooks/pre-commit
19+
20+
echo "✅ Pre-commit hook installed successfully!"
21+
echo ""
22+
echo "The hook will now automatically format Go files before each commit."
23+
echo "To disable the hook temporarily, use: git commit --no-verify"
24+
echo ""
25+
echo "You can also format all Go files manually with: make fmt"

scripts/pre-commit

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
# Pre-commit hook for Go formatting
3+
# This script automatically formats staged Go files using gofmt
4+
5+
# Get list of staged Go files
6+
staged_go_files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.go$')
7+
8+
# Exit early if no Go files are staged
9+
if [ -z "$staged_go_files" ]; then
10+
exit 0
11+
fi
12+
13+
echo "Formatting staged Go files..."
14+
15+
# Format each staged Go file
16+
formatted_files=()
17+
for file in $staged_go_files; do
18+
# Check if file still exists (might have been deleted)
19+
if [ -f "$file" ]; then
20+
# Format the file with gofmt -s (simplify)
21+
gofmt -s -w "$file"
22+
23+
# Check if formatting made changes
24+
if ! git diff --quiet "$file"; then
25+
formatted_files+=("$file")
26+
# Re-stage the formatted file
27+
git add "$file"
28+
fi
29+
fi
30+
done
31+
32+
# Report what was formatted
33+
if [ ${#formatted_files[@]} -gt 0 ]; then
34+
echo "Formatted and re-staged the following files:"
35+
for file in "${formatted_files[@]}"; do
36+
echo " - $file"
37+
done
38+
fi
39+
40+
exit 0

0 commit comments

Comments
 (0)