From 83282b85880080fcff829ec86f91c2a6f3d2903e Mon Sep 17 00:00:00 2001 From: Leo Singer Date: Fri, 2 Aug 2024 11:01:06 -0400 Subject: [PATCH] Add pre-commit hooks --- .github/workflows/{tox.yml => test.yml} | 18 +++++++++++- .pre-commit-config.yaml | 39 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) rename .github/workflows/{tox.yml => test.yml} (57%) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/tox.yml b/.github/workflows/test.yml similarity index 57% rename from .github/workflows/tox.yml rename to .github/workflows/test.yml index c571e45..36963f5 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,23 @@ on: pull_request: jobs: - test: + pre-commit: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install dependencies + run: pip install pre-commit poetry + + - name: Run pre-commit checks + run: pre-commit run --all-files + tox: uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1 with: coverage: 'codecov' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..ec43c1c --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,39 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: check-added-large-files + # Prevent giant files from being committed. + - id: check-case-conflict + # Check for files with names that would conflict on a case-insensitive + # filesystem like MacOS HFS+ or Windows FAT. + - id: check-json + # Attempts to load all json files to verify syntax. + - id: check-merge-conflict + # Check for files that contain merge conflict strings. + - id: check-symlinks + # Checks for symlinks which do not point to anything. + - id: check-toml + # Attempts to load all TOML files to verify syntax. + - id: check-xml + # Attempts to load all xml files to verify syntax. + - id: check-yaml + # Attempts to load all yaml files to verify syntax. + - id: detect-private-key + # Checks for the existence of private keys. + - id: end-of-file-fixer + # Makes sure files end in a newline and only a newline. + - id: trailing-whitespace + # Trims trailing whitespace. + exclude_types: [python] # Covered by Ruff W291. + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.5.5 + hooks: + # Run the linter. + - id: ruff + args: ["--extend-select", "I", "--fix"] + # Run the formatter. + - id: ruff-format