summaryrefslogtreecommitdiff
path: root/scripts/dev/misc_checks.py
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2020-11-02 16:48:59 +0100
committerFlorian Bruhin <me@the-compiler.org>2020-11-02 16:50:33 +0100
commit6d04af727d613ea7cfdd25867a2b76003af07e66 (patch)
tree9ea2de17f6947071a520822b5eed45a77b240793 /scripts/dev/misc_checks.py
parent0a5c2114c1f74c7bcad6ff67f64c0d683497657b (diff)
downloadqutebrowser-6d04af727d613ea7cfdd25867a2b76003af07e66.tar.gz
qutebrowser-6d04af727d613ea7cfdd25867a2b76003af07e66.zip
scripts: Improve spell checks in misc_checks.py
- Precompile patterns which leads to a nice speedup (8s -> 2.75s on my machine) - Add an explanation - Output messages in a way we can use GitHub Actions problem matchers - Add those problem matchers
Diffstat (limited to 'scripts/dev/misc_checks.py')
-rw-r--r--scripts/dev/misc_checks.py29
1 files changed, 19 insertions, 10 deletions
diff --git a/scripts/dev/misc_checks.py b/scripts/dev/misc_checks.py
index 7058e168f..f870e9666 100644
--- a/scripts/dev/misc_checks.py
+++ b/scripts/dev/misc_checks.py
@@ -101,6 +101,16 @@ def check_git(_args: argparse.Namespace = None) -> bool:
return status
+def _check_spelling_file(path, fobj, patterns):
+ ok = True
+ for num, line in enumerate(fobj, start=1):
+ for pattern, explanation in patterns:
+ if pattern.search(line):
+ ok = False
+ print(f'{path}:{num}: Found "{pattern.pattern}" ({explanation})')
+ return ok
+
+
def check_spelling(args: argparse.Namespace) -> Optional[bool]:
"""Check commonly misspelled words."""
# Words which I often misspell
@@ -119,6 +129,13 @@ def check_spelling(args: argparse.Namespace) -> Optional[bool]:
'eventloops', 'sizehint', 'statemachine', 'metaobject',
'logrecord'}
+ patterns = [
+ (
+ re.compile(r'[{}{}]{}'.format(w[0], w[0].upper(), w[1:])),
+ "Common misspelling or non-US spelling"
+ ) for w in words
+ ]
+
# Files which should be ignored, e.g. because they come from another
# package
hint_data = pathlib.Path('tests', 'end2end', 'data', 'hints')
@@ -129,20 +146,12 @@ def check_spelling(args: argparse.Namespace) -> Optional[bool]:
hint_data / 'bootstrap' / 'bootstrap.css',
]
- seen = collections.defaultdict(list)
try:
ok = True
for path in _get_files(verbose=args.verbose, ignored=ignored):
with tokenize.open(str(path)) as f:
- for line in f:
- for w in words:
- pattern = '[{}{}]{}'.format(w[0], w[0].upper(), w[1:])
- if (re.search(pattern, line) and
- path not in seen[w] and
- '# pragma: no spellcheck' not in line):
- print('Found "{}" in {}!'.format(w, path))
- seen[w].append(path)
- ok = False
+ if not _check_spelling_file(path, f, patterns):
+ ok = False
print()
return ok
except Exception: