Skip to content

Commit 77f98df

Browse files
committed
lint: convert spell check lint test to python
1 parent 15220ec commit 77f98df

File tree

2 files changed

+40
-21
lines changed

2 files changed

+40
-21
lines changed

test/lint/lint-spelling.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright (c) 2022 The Bitcoin Core developers
4+
# Distributed under the MIT software license, see the accompanying
5+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
6+
7+
"""
8+
Warn in case of spelling errors.
9+
Note: Will exit successfully regardless of spelling errors.
10+
"""
11+
12+
from subprocess import check_output, STDOUT, CalledProcessError
13+
14+
IGNORE_WORDS_FILE = 'test/lint/spelling.ignore-words.txt'
15+
FILES_ARGS = ['git', 'ls-files', '--', ":(exclude)build-aux/m4/", ":(exclude)contrib/seeds/*.txt", ":(exclude)depends/", ":(exclude)doc/release-notes/", ":(exclude)src/leveldb/", ":(exclude)src/crc32c/", ":(exclude)src/qt/locale/", ":(exclude)src/qt/*.qrc", ":(exclude)src/secp256k1/", ":(exclude)src/minisketch/", ":(exclude)src/univalue/", ":(exclude)contrib/builder-keys/keys.txt", ":(exclude)contrib/guix/patches"]
16+
17+
18+
def check_codespell_install():
19+
try:
20+
check_output(["codespell", "--version"])
21+
except FileNotFoundError:
22+
print("Skipping spell check linting since codespell is not installed.")
23+
exit(0)
24+
25+
26+
def main():
27+
check_codespell_install()
28+
29+
files = check_output(FILES_ARGS).decode("utf-8").splitlines()
30+
codespell_args = ['codespell', '--check-filenames', '--disable-colors', '--quiet-level=7', '--ignore-words={}'.format(IGNORE_WORDS_FILE)] + files
31+
32+
try:
33+
check_output(codespell_args, stderr=STDOUT)
34+
except CalledProcessError as e:
35+
print(e.output.decode("utf-8"), end="")
36+
print('^ Warning: codespell identified likely spelling errors. Any false positives? Add them to the list of ignored words in {}'.format(IGNORE_WORDS_FILE))
37+
38+
39+
if __name__ == "__main__":
40+
main()

test/lint/lint-spelling.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)