Skip to content

Commit 9cf2ff0

Browse files
vedpawar2254gagan502terriko
authored
ci: Add spell checker in pre-commit (#4859)
* Added codespell to precommit, fixes #2971 * added documentation and codespell to dev-requirements * chore: add explicit version for codespell --------- Co-authored-by: Ved <[email protected]> Co-authored-by: Terri Oda <[email protected]>
1 parent d59a8d1 commit 9cf2ff0

File tree

3 files changed

+87
-54
lines changed

3 files changed

+87
-54
lines changed

.pre-commit-config.yaml

+69-54
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
repos:
2-
- repo: https://github.com/econchick/interrogate
2+
- repo: https://github.com/econchick/interrogate
33
rev: 1.7.0
44
hooks:
55
- id: interrogate
@@ -8,77 +8,92 @@ repos:
88
args: ["-vv", "-i", "-I", "-M", "-C", "-n", "-p", "-f", "60.0"]
99
# args for cut and paste: interrogate -vv -i -I -M -C -n -p -f 60.0
1010

11-
- repo: https://github.com/pycqa/isort
11+
- repo: https://github.com/pycqa/isort
1212
rev: 5.13.2
1313
hooks:
14-
- id: isort
15-
stages: [pre-commit, pre-merge-commit]
16-
exclude: ^fuzz/generated/
14+
- id: isort
15+
stages: [pre-commit, pre-merge-commit]
16+
exclude: ^fuzz/generated/
1717

18-
- repo: https://github.com/psf/black-pre-commit-mirror
18+
- repo: https://github.com/psf/black-pre-commit-mirror
1919
rev: 24.10.0
2020
hooks:
21-
- id: black
22-
exclude: ^fuzz/generated/
21+
- id: black
22+
exclude: ^fuzz/generated/
2323

24-
- repo: https://github.com/asottile/pyupgrade
24+
- repo: https://github.com/asottile/pyupgrade
2525
rev: v3.19.1
2626
hooks:
27-
- id: pyupgrade
28-
exclude: ^fuzz/generated/
29-
args: ["--py38-plus"]
27+
- id: pyupgrade
28+
exclude: ^fuzz/generated/
29+
args: ["--py38-plus"]
3030

31-
- repo: https://github.com/pycqa/flake8
31+
- repo: https://github.com/pycqa/flake8
3232
rev: 7.1.1
3333
hooks:
34-
- id: flake8
35-
exclude: ^fuzz/generated/|bandit\.conf$
34+
- id: flake8
35+
exclude: ^fuzz/generated/|bandit\.conf$
3636

37-
- repo: https://github.com/PyCQA/bandit
37+
- repo: https://github.com/PyCQA/bandit
3838
rev: 1.8.0
3939
hooks:
40-
- id: bandit
41-
exclude: ^fuzz/generated/
42-
args: ["-c", "bandit.conf"]
40+
- id: bandit
41+
exclude: ^fuzz/generated/
42+
args: ["-c", "bandit.conf"]
4343

44-
- repo: https://github.com/jorisroovers/gitlint
44+
- repo: https://github.com/jorisroovers/gitlint
4545
rev: v0.19.1
4646
hooks:
47-
- id: gitlint
47+
- id: gitlint
4848

49-
- repo: https://github.com/pre-commit/mirrors-mypy
49+
- repo: https://github.com/pre-commit/mirrors-mypy
5050
rev: v1.14.1
5151
hooks:
52-
- id: mypy
53-
additional_dependencies:
54-
- types-beautifulsoup4
55-
- types-jsonschema
56-
- types-PyYAML
57-
- types-requests
58-
- types-setuptools
59-
- types-toml
60-
files: |
61-
(?x)^(
62-
cve_bin_tool/parsers/.*|
63-
cve_bin_tool/__init__.py|
64-
cve_bin_tool/async_utils.py|
65-
cve_bin_tool/file.py|
66-
cve_bin_tool/linkify.py|
67-
cve_bin_tool/log.py|
68-
cve_bin_tool/strings.py|
69-
cve_bin_tool/theme.py|
70-
cve_bin_tool/util.py|
71-
cve_bin_tool/validator.py|
72-
cve_bin_tool/version.py|
73-
doc/.*|
74-
test/test_data/.*|
75-
test/__init__.py|
76-
test/test_file.py|s
77-
test/test_requirements.py|
78-
test/test_strings.py|
79-
test/test_triage.py|
80-
test/test_version.py|
81-
test/utils.py|
82-
)$
83-
52+
- id: mypy
53+
additional_dependencies:
54+
- types-beautifulsoup4
55+
- types-jsonschema
56+
- types-PyYAML
57+
- types-requests
58+
- types-setuptools
59+
- types-toml
60+
files: |
61+
(?x)^(
62+
cve_bin_tool/parsers/.*|
63+
cve_bin_tool/__init__.py|
64+
cve_bin_tool/async_utils.py|
65+
cve_bin_tool/file.py|
66+
cve_bin_tool/linkify.py|
67+
cve_bin_tool/log.py|
68+
cve_bin_tool/strings.py|
69+
cve_bin_tool/theme.py|
70+
cve_bin_tool/util.py|
71+
cve_bin_tool/validator.py|
72+
cve_bin_tool/version.py|
73+
doc/.*|
74+
test/test_data/.*|
75+
test/__init__.py|
76+
test/test_file.py|s
77+
test/test_requirements.py|
78+
test/test_strings.py|
79+
test/test_triage.py|
80+
test/test_version.py|
81+
test/utils.py|
82+
)$
8483
84+
- repo: https://github.com/codespell-project/codespell
85+
rev: v1.16.0
86+
hooks:
87+
- id: codespell
88+
name: codespell
89+
description: Checks for common misspellings in text files.
90+
args:
91+
[
92+
"-I",
93+
".github/actions/spelling/allow.txt",
94+
".github/actions/spelling/only.txt",
95+
".github/actions/spelling/expect.txt",
96+
".github/actions/spelling/excludes.txt",
97+
]
98+
language: python
99+
types: [text]

CONTRIBUTING.md

+17
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ CVE Binary Tool uses a few tools to improve code quality and readability:
209209
- `gitlint` helps ensure that the commit messages follow [Conventional Commits](https://conventionalcommits.org).
210210
- `mypy` helps ensure type definitions are correct when provided.
211211
- `interrogate` checks your code base for missing docstrings.
212+
- `codespell` Detects common misspellings in text files.
212213

213214
We provide a `dev-requirements.txt` file which includes all the precise versions of tools as they'll be used in GitHub Actions. You an install them all using pip:
214215

@@ -317,6 +318,22 @@ You can specify a file or directory if you just want to check the files you chan
317318

318319
Interrogate shows some [report examples in their docs](https://interrogate.readthedocs.io/en/latest/#usage) or you can look at the [current cve-bin-tool reports in our linter runs on GitHub Actions](https://github.com/intel/cve-bin-tool/actions/workflows/linting.yml)
319320

321+
### Running codespell by itself
322+
323+
`codespell` is a spell checker designed to detect and correct common misspellings in text files, including code comments and documentation.
324+
325+
Run `codespell` in all files of the current directory:
326+
```
327+
codespell
328+
```
329+
330+
Run `codespell` in specific files or directories (specified via their names or glob patterns):
331+
```
332+
codespell filename some_dir/ *.ext
333+
```
334+
335+
for more detailed explanation you can checkout [codespell documentation](https://github.com/codespell-project/codespell)
336+
320337
### Other linting tools
321338

322339
As well as `black` for automatically making sure code adheres to the style guide, we use `flake8` to help us find things like unused imports. The [flake8 documentation](https://flake8.pycqa.org/en/latest/user/index.html) covers what you need to know about running it.

dev-requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ isort; python_version < "3.8"
44
isort==5.13.2; python_version >= "3.8"
55
pre-commit; python_version <= "3.8"
66
pre-commit==4.1.0; python_version > "3.8"
7+
codespell==1.16.0
78
flake8; python_version < "3.8"
89
flake8==7.1.1; python_version >= "3.8"
910
bandit==1.7.10; python_version <= "3.8"

0 commit comments

Comments
 (0)