diff --git a/.github/workflows/lint-prettier-cli.yml b/.github/workflows/lint-prettier-cli.yml deleted file mode 100644 index 31520c7c0..000000000 --- a/.github/workflows/lint-prettier-cli.yml +++ /dev/null @@ -1,22 +0,0 @@ -# Prettier -# Prettier is a code formatter. We mostly use it for the markdown files. -# https://prettier.io/ -# --- -# Action failing? Run npx prettier --write . locally to execute formatting. ---- -name: Prettier -on: [push, pull_request] - -jobs: - Prettier: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-node@v3 - - - name: Install Prettier - run: npm install -g prettier - - - name: Run Prettier --check - run: prettier --check ${GITHUB_WORKSPACE} diff --git a/.github/workflows/lint-ruff.yml b/.github/workflows/lint-ruff.yml deleted file mode 100644 index 19e243387..000000000 --- a/.github/workflows/lint-ruff.yml +++ /dev/null @@ -1,30 +0,0 @@ -# Lint Python - Ruff -# Ruff replaces both black (formatting) and pylint (linting). -# --- -# Action failing? -# - Run `ruff check .` and `ruff format --check .` locally to see issues. -# - Run `ruff check --fix .` and `ruff format .` to auto-fix. ---- -name: Ruff - -on: - push: - paths: - - "**.py" - - "pyproject.toml" - pull_request: - paths: - - "**.py" - - "pyproject.toml" - -jobs: - ruff: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Install ruff - run: pip install ruff==0.15.2 - - name: Check linting - run: ruff check . - - name: Check formatting - run: ruff format --check . diff --git a/.github/workflows/lint-yaml.yml b/.github/workflows/lint-yaml.yml deleted file mode 100644 index 962bd80a4..000000000 --- a/.github/workflows/lint-yaml.yml +++ /dev/null @@ -1,26 +0,0 @@ -# Yamtllint: Lint Yaml files. -# A linter for YAML files. Checks for: -# - syntax validity -# - weirdnesses like key repetition and cosmetic problems such as: -# - lines length -# - trailing spaces -# - indentation -# etc. -# --- -# Action failing? Manually fix any errors locally. ---- -name: Yamllint -on: [push] -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: yaml-lint - uses: ibiqlik/action-yamllint@v3 - with: - config_data: | - extends: default - rules: - line-length: - max: 120 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..0a980aaf5 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,21 @@ +# Lint (via prek) +# All linting and formatting hooks are defined in .pre-commit-config.yaml +# and run together via prek: +# - ruff Python linting and formatting +# - prettier Markdown, JSON, YAML, and other non-Python files +# - yamllint YAML style and syntax +# --- +# Action failing? +# Install prek: download from https://github.com/j178/prek/releases +# Run locally: prek run --all-files +--- +name: Lint + +on: [push, pull_request] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: j178/prek-action@v1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..496f519f9 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,40 @@ +# Pre-commit hooks configuration +# --- +# Managed by prek (https://prek.j178.dev) — a fast, Rust-based, drop-in +# replacement for pre-commit. Uses the same .pre-commit-config.yaml format. +# +# Install prek: +# Download from https://github.com/j178/prek/releases +# or: cargo install prek +# +# Install git hooks (run once after cloning): +# prek install +# +# Run all hooks manually without committing: +# prek run --all-files + +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.15.3 + hooks: + # Linter — auto-fixes violations where possible before the commit lands + - id: ruff + args: [--fix] + # Formatter — enforces consistent code style + - id: ruff-format + + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v3.1.0 + hooks: + # Formatter for Markdown, JSON, YAML, and other non-Python files + - id: prettier + additional_dependencies: + # The pre-commit mirror doesn't update prettier anymore, + # so need to specify real version like this + - prettier@3.8.1 + + - repo: https://github.com/adrienverge/yamllint + rev: v1.38.0 + hooks: + - id: yamllint + args: ["-d", "{extends: default, rules: {line-length: {max: 120}}}"] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bebb92c9e..9b2b3d36e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,23 @@ If you would like to contribute to this project... +## Developer Setup + +### Pre-commit hooks + +This project uses [prek](https://prek.j178.dev) to manage git pre-commit hooks (a fast, Rust-based drop-in for `pre-commit`). + +Install prek from the [releases page](https://github.com/j178/prek/releases), then install the hooks into your local clone: + +```bash +prek install +``` + +After that, ruff linting and formatting checks run automatically on every `git commit`. To run all hooks manually at any time: + +```bash +prek run --all-files +``` + **Thank you, any suggestions and / or contributions are very appreciated** If you would like to suggest a change, please go to the issues tab and fill out and issue. If you would like to contribute with code, follow the steps below: diff --git a/SPRINTLOG.md b/SPRINTLOG.md index 8f3bf066c..0dfdde879 100644 --- a/SPRINTLOG.md +++ b/SPRINTLOG.md @@ -526,3 +526,4 @@ _Empty sprint_ - Configure Renovate ([#876](https://github.com/ScilifelabDataCentre/dds_cli/pull/876)) - replace click-pathlib dependency with `click.Path(path_type=pathlib.Path)`([#926](https://github.com/ScilifelabDataCentre/dds_cli/pull/926)) - Switch from pylint+black to ruff([#927](https://github.com/ScilifelabDataCentre/dds_cli/pull/927)) +- Add pre-commit config to repository ([#932](https://github.com/ScilifelabDataCentre/dds_cli/pull/932))