From bebe41e01861f51aa6b34afc6b43b0c5da888ffd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 May 2025 18:11:42 +0000 Subject: [PATCH 1/5] Initial plan for issue From 03ba37e895b16344798c4d4a306750f7148eebbd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 May 2025 18:16:18 +0000 Subject: [PATCH 2/5] Add pre-commit configuration and update documentation Co-authored-by: debonte <12820898+debonte@users.noreply.github.com> --- .pre-commit-config.yaml | 10 ++++++++++ CONTRIBUTING.md | 17 +++++++++++++++++ pyproject.toml | 1 + 3 files changed, 28 insertions(+) create mode 100644 .pre-commit-config.yaml 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" From 5aeffec023225ebdb351fed083eed40946551873 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 May 2025 18:17:32 +0000 Subject: [PATCH 3/5] Test pre-commit --- sarif/test_formatting.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 sarif/test_formatting.py diff --git a/sarif/test_formatting.py b/sarif/test_formatting.py new file mode 100644 index 0000000..b3d622f --- /dev/null +++ b/sarif/test_formatting.py @@ -0,0 +1,3 @@ +def test_func(): + x = 1 + return x From 2a12d9fad34890e98e85fbd30e70eeb5a2555694 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 May 2025 18:18:20 +0000 Subject: [PATCH 4/5] Test black formatting --- sarif/unformatted_test.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 sarif/unformatted_test.py diff --git a/sarif/unformatted_test.py b/sarif/unformatted_test.py new file mode 100644 index 0000000..3f6b3bc --- /dev/null +++ b/sarif/unformatted_test.py @@ -0,0 +1,5 @@ +def unformatted_function(param1, param2, param3): + # This function is purposely unformatted + x = 1 + 2 + y = 3 + 4 + return x + y From 3954275de73b11d89c998c17c1d4fa31a9045ec2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 28 May 2025 18:18:48 +0000 Subject: [PATCH 5/5] Remove test files and complete implementation Co-authored-by: debonte <12820898+debonte@users.noreply.github.com> --- sarif/test_formatting.py | 3 --- sarif/unformatted_test.py | 5 ----- 2 files changed, 8 deletions(-) delete mode 100644 sarif/test_formatting.py delete mode 100644 sarif/unformatted_test.py diff --git a/sarif/test_formatting.py b/sarif/test_formatting.py deleted file mode 100644 index b3d622f..0000000 --- a/sarif/test_formatting.py +++ /dev/null @@ -1,3 +0,0 @@ -def test_func(): - x = 1 - return x diff --git a/sarif/unformatted_test.py b/sarif/unformatted_test.py deleted file mode 100644 index 3f6b3bc..0000000 --- a/sarif/unformatted_test.py +++ /dev/null @@ -1,5 +0,0 @@ -def unformatted_function(param1, param2, param3): - # This function is purposely unformatted - x = 1 + 2 - y = 3 + 4 - return x + y