Skip to content

Commit 0e63e50

Browse files
authored
Merge pull request #38 from George-Ogden/spell-check
Spell Check Commit Messages
2 parents 1e3d71b + 3802638 commit 0e63e50

18 files changed

+116
-33
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
default_stages: ["pre-commit", "commit-msg", "pre-push"]
1+
default_stages: ["pre-commit"]
22

33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks

.pre-commit-hooks.yaml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,43 @@
11
- id: dbg-check
2-
name: Ensure no `dbg` statements, macros or expressions included in source files.
2+
name: Check for `dbg`
3+
description: Ensure no `dbg` statements, macros or expressions included in source files.
34
entry: ./validate-dbg.sh
45
language: script
56
types: [text]
67

78
- id: pragma-once
8-
name: Ensure all header files have `#pragma once` before any other imports.
9+
name: Check for `#pragma once`
10+
description: Ensure all header files have `#pragma once` before any other imports.
911
entry: ./validate-pragma.sh
1012
language: script
1113
types_or: [c++, file]
1214
files: \.(hpp|h\+\+|hxx|cuh)$
1315

1416
- id: check-merge-conflict
15-
name: Check for merge-conflicts.
17+
name: Check for merge conflicts
18+
description: Check for merge-conflicts.
1619
entry: ./validate-merge-conflict.sh
1720
language: script
1821
types: [file]
1922

2023
- id: mypy
21-
name: MyPy
24+
name: Run MyPy
25+
description: MyPy
2226
entry: ./run-mypy.sh
2327
language: script
2428
types: [python]
2529

2630
- id: todo-check
27-
name: Check for 'todo' or 'fixme' left in source files.
31+
name: Check for `todo`s
32+
description: Check for 'todo' or 'fixme' left in source files.
2833
entry: ./validate-todo.sh
2934
language: script
3035
types: [text]
3136
exclude: ^\.
37+
38+
- id: spell-check-commit-msgs
39+
name: Spell check commit message
40+
description: Check for spelling errors in commit messages.
41+
entry: ./run-spell-check.sh
42+
language: script
43+
stages: [commit-msg]

README.md

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ It may work with other Python versions or operating systems (such as MacOS or WS
1212

1313
This repository provides the following pre-commit hooks:
1414

15-
- [dbg-check](#dbg-check) - ensure no `dbg` statements, macros or imports are included in the source code.
16-
- [todo-check](#todo-check) - ensure no "todo"s or "fixme"s are left in the source code.
17-
- [pragma-once](#pragma-once) - ensure all headers start with `#pragma once`.
18-
- [check-merge-conflict](#check-merge-conflict) - check for merge conflicts.
19-
- [mypy](#mypy) - run [MyPy](#https://github.com/python/mypy).
15+
- [dbg-check](#dbg-check) - ensure no `dbg` statements, macros or imports are included in the source code.
16+
- [todo-check](#todo-check) - ensure no "todo"s or "fixme"s are left in the source code.
17+
- [pragma-once](#pragma-once) - ensure all headers start with `#pragma once`.
18+
- [check-merge-conflict](#check-merge-conflict) - check for merge conflicts.
19+
- [mypy](#mypy) - run [MyPy](#https://github.com/python/mypy).
20+
- [spell-check-commit-msgs](#spell-check-commit-msgs) - check for spelling errors in commit messages.
2021

2122
### dbg-check
2223

@@ -50,32 +51,43 @@ It allows you to pass in a requirements file using the `-r` or `--requirements-f
5051
It requires that you have `pip` installed, but if you're using pre-commit, that shouldn't be an issue.
5152
You can set the MyPy version in the requirements file (eg `mypy==1.17.1`), otherwise, the latest is installed.
5253

54+
### spell-check-commit-msgs
55+
56+
> _[If you] make spelling mistakes in commit messages, it's then a real pain to amend the commit._
57+
> _And god forbid if you pushed._
58+
59+
This uses [`codespell`](https://github.com/codespell-project/codespell) under the hood, and accepts the same flags via the `args` field, but interactive mode is not supported.
60+
`codespell` is installed via [`uv`](https://docs.astral.sh/uv/), so you need to have `pip` installed.
61+
You also need to ensure that you install the `commit-msg` hooks, which you can do with `pre-commit install -t pre-commit -t commit-msg` or adding `default_install_hook_types: ["pre-commit", "commit-msg"]` to the `.pre-commit-config.yaml` (like below).
62+
5363
## Example Use
5464

5565
Here's a sample `.pre-commit-config.yaml`:
5666

5767
```yaml
58-
default_stages: ["pre-commit", "commit-msg", "pre-push"]
68+
default_stages: ["pre-commit"]
69+
default_install_hook_types: ["pre-commit", "commit-msg"]
5970

6071
repos:
61-
- repo: https://github.com/pre-commit/pre-commit-hooks
62-
rev: v6.0.0
63-
hooks:
64-
- id: end-of-file-fixer
65-
- id: mixed-line-ending
66-
- id: trailing-whitespace
67-
68-
- repo: https://github.com/George-Ogden/pre-commit-hooks/
69-
rev: v1.2.5
70-
hooks:
71-
- id: dbg-check
72-
exclude: ^test/
73-
- id: todo-check
74-
exclude: README
75-
- id: pragma-once
76-
- id: check-merge-conflict
77-
- id: mypy
78-
args: [-r, requirements.txt, --strict]
72+
- repo: https://github.com/pre-commit/pre-commit-hooks
73+
rev: v6.0.0
74+
hooks:
75+
- id: end-of-file-fixer
76+
- id: mixed-line-ending
77+
- id: trailing-whitespace
78+
79+
- repo: https://github.com/George-Ogden/pre-commit-hooks/
80+
rev: v1.3.0
81+
hooks:
82+
- id: dbg-check
83+
exclude: ^test/
84+
- id: todo-check
85+
exclude: README
86+
- id: pragma-once
87+
- id: check-merge-conflict
88+
- id: mypy
89+
args: [-r, requirements.txt, --strict]
90+
- id: spell-check-commit-msgs
7991
```
8092
8193
### Development

run-spell-check.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/bash
2+
3+
set -o pipefail
4+
5+
FILENAME="${@: -1}"
6+
ESCAPED_FILENAME=$(printf '%s\n' "$FILENAME" | sed -e 's/[]\/$*.^[]/\\&/g')
7+
8+
pip install uv -qqq && uv pip install codespell -qqq --system && codespell $@ | sed -E "s,$ESCAPED_FILENAME:[[:digit:]]+,commit message error,"

tests/mypy/test_invalid_import.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
set -e
44
DIRECTORY=$(dirname $0)
55

6-
76
pre-commit run --config $DIRECTORY/test_data/import_error/.pre-commit-config.yaml --files $DIRECTORY/test_data/import_error/import_error.py

tests/mypy/test_requirements_file.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
set -e
44
DIRECTORY=$(dirname $0)
55

6-
76
pre-commit run --config $DIRECTORY/test_data/requirements-file/.pre-commit-config.yaml --files $DIRECTORY/test_data/requirements-file/main.py

tests/spell-check/test_data/empty.txt

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
repos:
2+
- repo: .
3+
rev: HEAD
4+
hooks:
5+
- id: spell-check-commit-msgs
6+
args:
7+
- -L wrod,woo
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This uses a Wrod.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Uplod files to repo.
2+
3+
- Includs an error
4+
- Adn another one tooo

0 commit comments

Comments
 (0)