Welcome to SurfSense! As an open-source project, we use pre-commit hooks to maintain code quality, security, and consistency across our multi-component codebase. This guide will help you set up and work with our pre-commit configuration.
Pre-commit is a framework for managing multi-language pre-commit hooks. It runs automatically before each commit to catch issues early, ensuring high code quality and consistency across the project.
SurfSense consists of three main components:
surfsense_backend/- Python backend APIsurfsense_web/- Next.js web applicationsurfsense_browser_extension/- TypeScript browser extension
- Python 3.8 or higher
- Node.js 18+ and pnpm (for frontend components)
- Git
# Install pre-commit globally
pip install pre-commit
# Or using your preferred package manager
# pipx install pre-commit # Recommended for isolation-
Clone the repository:
git clone https://github.com/masabinhok/SurfSense.git cd SurfSense -
Install the pre-commit hooks:
pre-commit install
-
Install commit message hooks (optional, for conventional commits):
pre-commit install --hook-type commit-msg
When you install pre-commit, the following files are part of the setup:
.pre-commit-config.yaml- Main pre-commit configuration.secrets.baseline- Baseline file for secret detection (prevents false positives).github/workflows/pre-commit.yml- CI workflow that runs pre-commit on PRs
- ✅ Trailing whitespace removal
- ✅ YAML, JSON, and TOML validation
- ✅ Large file detection (>10MB)
- ✅ Merge conflict markers
- 🔒 Secret detection using detect-secrets
- 🐍 Black - Code formatting
- 📦 isort - Import sorting
- ⚡ Ruff - Fast linting and formatting
- 🔍 MyPy - Static type checking
- 🛡️ Bandit - Security vulnerability scanning
- 💅 Prettier - Code formatting
- 🔍 ESLint - Linting (Next.js config)
- 📝 TypeScript - Compilation checks
- 📝 Commitizen - Conventional commit format validation
Pre-commit will run automatically when you commit:
git add .
git commit -m "feat: add new feature"
# Pre-commit hooks will run automaticallyRun on staged files only:
pre-commit runRun on specific files:
pre-commit run --files path/to/file.py path/to/file.tsRun all hooks on all files:
pre-commit run --all-files--all-files may generate numerous errors as this codebase has existing linting and type issues that are being gradually resolved.
Update all hooks to latest versions:
pre-commit autoupdateRun only specific hooks:
pre-commit run black # Run only black
pre-commit run --all-files prettier # Run prettier on all filesClean pre-commit cache:
pre-commit cleanSometimes you might need to bypass pre-commit hooks (use sparingly!):
git commit -m "fix: urgent hotfix" --no-verifySKIP=mypy,black git commit -m "feat: work in progress"Available hook IDs to skip:
trailing-whitespace,check-yaml,check-jsondetect-secretsblack,isort,ruff,ruff-format,mypy,banditprettier,eslinttypescript-check-web,typescript-check-extensioncommitizen
If detect-secrets flags legitimate content as secrets:
- Review the detection - Ensure it's not actually a secret
- Update baseline:
detect-secrets scan --baseline .secrets.baseline --update git add .secrets.baseline
Ensure dependencies are installed:
cd surfsense_web && pnpm install
cd surfsense_browser_extension && pnpm installFor Python hooks, ensure you're in the correct environment:
cd surfsense_backend
# If using uv
uv sync
# Or traditional pip
pip install -r requirements.txtIf hooks aren't running:
pre-commit uninstall
pre-commit install --install-hooks- Incremental runs: Pre-commit only runs on changed files by default
- Parallel execution: Many hooks run in parallel for speed
- Caching: Pre-commit caches environments to speed up subsequent runs
Pre-commit also runs in our GitHub Actions CI pipeline on every PR to main. The CI:
- Runs only on changed files for efficiency
- Provides the same feedback as local pre-commit
- Prevents merging code that doesn't pass quality checks
- Install pre-commit early in your development setup
- Fix issues incrementally rather than bypassing hooks
- Update your branch regularly to avoid conflicts with formatting changes
- Run
--all-filesperiodically on feature branches (in small chunks) - Keep the
.secrets.baselineupdated when legitimate secrets-like strings are added
To modify the pre-commit configuration:
- Edit
.pre-commit-config.yaml - Test your changes:
pre-commit run --all-files # Test with caution! - Update the baseline if needed:
detect-secrets scan --baseline .secrets.baseline --update
- Submit a PR with your changes
- Pre-commit docs: https://pre-commit.com/
- Project issues: Open an issue on GitHub
- Hook-specific help: Check individual tool documentation (Black, Ruff, ESLint, etc.)
Thank you for contributing to SurfSense! 🏄♀️ Quality code makes everyone's surfing experience smoother.