Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typos hook to pre-commit #68

Merged
merged 4 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:

jobs:
pre-commit:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

Expand All @@ -21,14 +21,14 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install pre-commit
run: pip install pre-commit==${{ env.PRECOMMIT_VERSION }}

- name: Cache pre-commit
uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: precommit-${{ hashFiles('.pre-commit-config.yaml') }}

- name: Install pre-commit
run: pip install pre-commit==${{ env.PRECOMMIT_VERSION }}

- name: Run pre-commit
run: pre-commit run --all-files
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ concurrency:

env:
PYTHON_VERSION: '3.11'
POETRY_VERSION: '1.7.0'
POETRY_VERSION: '1.8.3'

jobs:
test:
Expand All @@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v4

- name: Configure Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

Expand All @@ -30,7 +30,7 @@ jobs:

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-v1-${{ hashFiles('**/poetry.lock') }}
Expand Down
17 changes: 11 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.4.6
hooks:
- id: ruff
- id: ruff-format

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand All @@ -13,17 +19,16 @@ repos:
hooks:
- id: markdownlint-fix

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.4.6
- repo: https://github.com/crate-ci/typos
rev: v1.21.0
hooks:
- id: ruff
types_or: [python, pyi]
- id: ruff-format
- id: typos
args: [--force-exclude]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
hooks:
- id: mypy
args: []
pass_filenames: false
additional_dependencies: [] # Manually add your dependencies here
additional_dependencies: [] # Manually add your runtime dependencies here
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ Run `pre-commit install` after setting up your local environment to enable pre-c

The following hooks have been selected for this CI setup:

- [ruff](https://github.com/charliermarsh/ruff/): An extremely fast Python linter and formatter. Includes lints and formatting popularized by various other tools like `black`, `flake8` and `pyupgrade`, all in one tool. Replaces all linting and autoformatting tools except for `mypy`. Install the [VSCode](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff) or [PyCharm](https://plugins.jetbrains.com/plugin/20574-ruff) extension for the best developer experience. Adjust settings in the `pyproject.toml` as desired.
- [pre-commit-hooks](https://github.com/pre-commit/pre-commit-hooks): Some generic hooks not specific to Python.
- [markdownlint-cli](https://github.com/igorshubovych/markdownlint-cli): Almost all projects will include some documentation in Markdown format. This hook makes sure these files are formatted consistently. Turn specific lints on/off in the `.markdownlint.yml` file.
- [ruff](https://github.com/charliermarsh/ruff/): An extremely fast Python linter and formatter. Includes lints and formatting popularized by various other tools like `black`, `flake8` and `pyupgrade`, all in one tool. Replaces all linting and autoformatting tools except for `mypy`. Install the [VSCode](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff) or [PyCharm](https://plugins.jetbrains.com/plugin/20574-ruff) extension for the best developer experience. Adjust settings in the `pyproject.toml` as desired.
- [typos](https://github.com/crate-ci/typos): A source code spell checker. While it does produce some false positives, it can be helpful. Address false positives by adding ignore patterns to the `typos` section of `pyproject.toml`.
- [mypy](https://mypy.readthedocs.io/): mypy is a static type checker for Python. One of the best things you can do for your code base is add type hints and be consistent with them. In this repo, mypy is configured with [all strictness options](https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-strict) enabled. Note that for mypy to work correctly as a pre-commit hook, **you must define your main dependencies as `additional_dependencies` in the pre-commit hook**. If you have many dependencies, it may be better to remove the mypy pre-commit hook and run mypy alongside your tests.

## pytest
Expand Down
Loading