lint-spelling.py raw
1 #!/usr/bin/env python3
2 #
3 # Copyright (c) 2022 The Limenka 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 from lint_ignore_dirs import SHARED_EXCLUDED_SUBTREES
15
16 IGNORE_WORDS_FILE = 'test/lint/spelling.ignore-words.txt'
17 FILES_ARGS = ['git', 'ls-files', '--', ":(exclude)contrib/seeds/*.txt", ":(exclude)depends/", ":(exclude)doc/release-notes/", ":(exclude)src/qt/locale/", ":(exclude)src/qt/*.qrc", ":(exclude)contrib/guix/patches"]
18 FILES_ARGS += [f":(exclude){dir}" for dir in SHARED_EXCLUDED_SUBTREES]
19
20
21 def check_codespell_install():
22 try:
23 check_output(["codespell", "--version"])
24 except FileNotFoundError:
25 print("Skipping spell check linting since codespell is not installed.")
26 exit(0)
27
28
29 def main():
30 check_codespell_install()
31
32 files = check_output(FILES_ARGS).decode("utf-8").splitlines()
33 codespell_args = ['codespell', '--check-filenames', '--disable-colors', '--quiet-level=7', '--ignore-words={}'.format(IGNORE_WORDS_FILE)] + files
34
35 try:
36 check_output(codespell_args, stderr=STDOUT)
37 except CalledProcessError as e:
38 print(e.output.decode("utf-8"), end="")
39 print('^ Warning: codespell identified likely spelling errors. Any false positives? Add them to the list of ignored words in {}'.format(IGNORE_WORDS_FILE))
40
41
42 if __name__ == "__main__":
43 main()
44