diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..76ad5c4 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,17 @@ +# Workflow for running pre-commit checks +name: Pre-commit + +on: + pull_request: + push: + branches: [main] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + with: + python-version: "3.12" + - uses: pre-commit/action@v3.0.1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..85eb3f9 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,88 @@ +# Pre-commit configuration file compatible with Trunk.io +# See https://pre-commit.com for more information +# See https://docs.trunk.io/check for Trunk.io integration + +default_language_version: + python: python3.12 + +repos: + # Ruff - Python linter and formatter (replaces Black, isort, flake8, etc.) + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.4.1 + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format + + # Prettier - Code formatter for YAML, JSON, Markdown, etc. + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v3.1.0 + hooks: + - id: prettier + types_or: [yaml, markdown, json] + + # Standard pre-commit hooks + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: check-added-large-files + args: [--maxkb=1000] + - id: check-case-conflict + - id: check-merge-conflict + - id: check-yaml + args: [--unsafe] # Allow custom YAML tags + exclude: ^tests/functional/.*/cassettes/.*\.yaml$ + - id: check-json + - id: check-toml + - id: end-of-file-fixer + exclude: ^tests/functional/.*/cassettes/.*\.yaml$ + - id: trailing-whitespace + exclude: ^tests/functional/.*/cassettes/.*\.yaml$ + - id: mixed-line-ending + - id: detect-private-key + + # yamllint - YAML linter + - repo: https://github.com/adrienverge/yamllint + rev: v1.35.1 + hooks: + - id: yamllint + args: [-c, .trunk/configs/.yamllint.yaml] + exclude: ^tests/functional/.*/cassettes/.*\.yaml$ + + # markdownlint - Markdown linter + - repo: https://github.com/igorshubovych/markdownlint-cli + rev: v0.39.0 + hooks: + - id: markdownlint + args: [-c, .trunk/configs/.markdownlint.yaml] + + # Bandit - Python security linter + - repo: https://github.com/PyCQA/bandit + rev: 1.7.8 + hooks: + - id: bandit + args: [-c, .trunk/configs/bandit.yaml, -r, .] + exclude: ^tests/ + + # TruffleHog - Secret scanning (Trunk.io handles this via trufflehog-pre-commit action) + # To enable, uncomment the following: + # - repo: https://github.com/trufflesecurity/trufflehog + # rev: v3.74.0 + # hooks: + # - id: trufflehog + # args: + # - git + # - file://. + # - --since-commit + # - HEAD + # - --only-verified + # - --fail + + # Commitlint - Commit message linting (Trunk.io handles this via commitlint action) + # To enable, uncomment and run: pre-commit install --hook-type commit-msg + # - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook + # rev: v9.16.0 + # hooks: + # - id: commitlint + # stages: [commit-msg] + # additional_dependencies: ["@commitlint/config-conventional"] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8eb9bad..a043c9e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,10 +17,42 @@ This section guides you through submitting a bug report for `diffbot-kg`. Follow - **Explain which behavior you expected to see instead and why.** - **Include screenshots and/or animated GIFs** which help demonstrate the steps or point out the part of Indeed Job Scraper which the suggestion is related to. +### Development Setup + +#### Pre-commit Hooks + +This project uses [pre-commit](https://pre-commit.com/) hooks to automatically check code quality before commits. The configuration is compatible with [Trunk.io](https://trunk.io/). + +To set up pre-commit hooks: + +```bash +pip install pre-commit +pre-commit install +``` + +The hooks will automatically run on every commit. You can also run them manually: + +```bash +# Run on all files +pre-commit run --all-files + +# Run on specific files +pre-commit run --files src/diffbot_kg/models.py +``` + +The pre-commit configuration includes: +- **Ruff**: Python linting and formatting +- **Prettier**: YAML, JSON, and Markdown formatting +- **yamllint**: YAML linting +- **markdownlint**: Markdown linting +- **Bandit**: Python security checks +- Standard checks: trailing whitespace, file endings, merge conflicts, etc. + ### Pull Requests Please follow these steps to have your contribution considered by the maintainer: +- Set up pre-commit hooks (see Development Setup above) to ensure code quality. - After you submit your pull request, verify that all status checks are passing. - While the maintainer reviews your PR, you can also ask for specific people to review your changes. - Once your pull request is created, it will be reviewed by the maintainer of the project. You may be asked to make changes to your pull request. There's always a chance your pull request won't be accepted.