Skip to content

Commit d5017f8

Browse files
committed
style: add pre-commit hooks and editorconfig
Without wanting to overload the pre-commit hooks, this adds a few checks on the commits to ensure validity of files. More time-consuming checks for linting and formatting are done pre-push to avoid impacting the developer experience during local development. These are covered by `prettier` (for markdown, yaml, json, ...), `black` for Python and `ruff` for Python linting. To help standardise formatting in the future, an `.editorconfig` file has also been added to the repository. By virtue of using `pre-commit`, only modified files are checked which ensures older files are incrementally updated. Signed-off-by: JP-Ellis <josh@jpellis.me>
1 parent ed5f86c commit d5017f8

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

.editorconfig

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
end_of_line = lf
9+
indent_size = 2
10+
indent_style = space
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[*.py]
15+
indent_size = 4
16+
17+
[Makefile]
18+
indent_size = 4
19+
indent_style = tab
20+
21+
[*.md]
22+
indent_size = 4

.pre-commit-config.yaml

+51
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,55 @@
1+
default_install_hook_types:
2+
- commit-msg
3+
- pre-commit
4+
- pre-push
5+
16
repos:
7+
# Generic hooks that apply to a lot of files
8+
- repo: https://github.com/pre-commit/pre-commit-hooks
9+
rev: v4.4.0
10+
hooks:
11+
- id: check-added-large-files
12+
- id: check-case-conflict
13+
- id: check-executables-have-shebangs
14+
- id: check-shebang-scripts-are-executable
15+
- id: check-symlinks
16+
- id: destroyed-symlinks
17+
- id: end-of-file-fixer
18+
- id: mixed-line-ending
19+
- id: trailing-whitespace
20+
21+
# The following only check that the files are parseable and does _not_
22+
# modify the formatting.
23+
- id: check-toml
24+
- id: check-xml
25+
- id: check-yaml
26+
27+
- repo: https://gitlab.com/bmares/check-json5
28+
rev: v1.0.0
29+
hooks:
30+
# As above, this only checks for valid JSON files. This implementation
31+
# allows for comments within JSON files.
32+
- id: check-json5
33+
34+
- repo: https://github.com/pre-commit/mirrors-prettier
35+
rev: v3.0.3
36+
hooks:
37+
- id: prettier
38+
stages: [pre-push]
39+
40+
- repo: https://github.com/astral-sh/ruff-pre-commit
41+
rev: v0.0.289
42+
hooks:
43+
- id: ruff
44+
args: [--fix, --exit-non-zero-on-fix]
45+
stages: [pre-push]
46+
47+
- repo: https://github.com/psf/black
48+
rev: 23.9.1
49+
hooks:
50+
- id: black
51+
stages: [pre-push]
52+
253
- repo: https://github.com/commitizen-tools/commitizen
354
rev: master
455
hooks:

0 commit comments

Comments
 (0)