diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..00ae454 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,10 @@ +repos: + - repo: https://github.com/psf/black + rev: 24.3.0 + hooks: + - id: black + name: black + entry: black + language: system + types: [python] + files: ^sarif/ \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ab88173..8776615 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,6 +20,7 @@ Pull requests are welcome. 1. Fork the repository. 2. Make and test your changes (see Developer Guide below). 3. Run `poetry run ruff format` and `poetry run black sarif` to format the code. + - Alternatively, install pre-commit hooks to run black automatically before each commit (see [Setting up pre-commit hooks](#setting-up-pre-commit-hooks) below). 4. Run `poetry run pylint sarif` and check for no new errors or warnings. 5. Raise Pull Request in GitHub.com. @@ -142,3 +143,19 @@ poetry update ### Adding resource files to the project Add the file within the `sarif` directory and it will be installed with the Python source. For example, `sarif/operations/templates/sarif_summary.html`. + +### Setting up pre-commit hooks + +This repository uses [pre-commit](https://pre-commit.com/) to automatically run black code formatter before each commit. To set up pre-commit: + +1. Ensure pre-commit is installed in your development environment: +```bash +poetry install +``` + +2. Install the git hooks: +```bash +poetry run pre-commit install +``` + +Once installed, black will automatically run on the files you've changed when you commit. If the formatter makes any changes, the commit will be aborted, allowing you to stage the formatting changes and try again. diff --git a/pyproject.toml b/pyproject.toml index 69b7b6f..1c08e33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,6 +27,7 @@ pyyaml = "^6.0.1" [tool.poetry.dev-dependencies] jsonschema = "^4.23.0" +pre-commit = "^4.2.0" pylint = "^3.2" pytest = "^8.3" pytest-cov = "^5.0"