2021-09-01 23:48:38 +00:00
|
|
|
#!/usr/bin/env python3
|
2021-09-01 23:14:58 +00:00
|
|
|
import re
|
2021-12-26 05:00:49 +00:00
|
|
|
|
|
|
|
from lgrelease import release
|
2021-09-01 23:14:58 +00:00
|
|
|
|
|
|
|
from enchant.tokenize import Filter
|
|
|
|
|
2021-09-01 23:48:38 +00:00
|
|
|
reacronym = re.compile(r'^[A-Z]+s?$')
|
2021-09-01 23:14:58 +00:00
|
|
|
reoption = re.compile(r'^[a-z]+:\w+$')
|
2021-09-01 23:48:38 +00:00
|
|
|
recamel = re.compile(r'^[A-Za-z]+[A-Z]\w+$')
|
2021-09-01 23:14:58 +00:00
|
|
|
repackage = re.compile(r'^[\w-]+-(?:dev|bin)$|^fonts-[\w-]+-ttf$|^virt-manager$')
|
2021-09-01 23:48:38 +00:00
|
|
|
repath = re.compile(r'^/dev/|.*\.\w+$')
|
2021-09-01 23:14:58 +00:00
|
|
|
recrypto = re.compile(r'^[13][A-Za-z0-9]{25,34}$|^0x[0-9a-fA-F]{40}$')
|
|
|
|
|
|
|
|
|
2021-09-01 23:48:38 +00:00
|
|
|
class AcronymFilter(Filter):
|
|
|
|
def _skip(self, word):
|
|
|
|
return reacronym.match(word)
|
|
|
|
|
|
|
|
|
2021-09-01 23:14:58 +00:00
|
|
|
class OptionFilter(Filter):
|
|
|
|
def _skip(self, word):
|
|
|
|
return reoption.match(word) or recamel.match(word)
|
|
|
|
|
|
|
|
|
|
|
|
class PackageFilter(Filter):
|
|
|
|
def _skip(self, word):
|
|
|
|
return repackage.match(word)
|
|
|
|
|
|
|
|
|
|
|
|
class PathFilter(Filter):
|
|
|
|
def _skip(self, word):
|
|
|
|
return repath.match(word)
|
|
|
|
|
|
|
|
|
|
|
|
class CryptoAddressFilter(Filter):
|
|
|
|
def _skip(self, word):
|
|
|
|
return recrypto.match(word)
|
2021-09-01 23:48:38 +00:00
|
|
|
|
|
|
|
|
2021-12-26 05:00:49 +00:00
|
|
|
class VersionFilter(Filter):
|
|
|
|
def _skip(self, word):
|
|
|
|
return word == release
|
|
|
|
|
|
|
|
|
2021-09-01 23:48:38 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from enchant.checker import SpellChecker
|
|
|
|
|
|
|
|
checker = SpellChecker('en_US', sys.stdin.read(), filters=[
|
|
|
|
AcronymFilter, OptionFilter, PackageFilter, PathFilter,
|
|
|
|
])
|
|
|
|
|
|
|
|
with open(os.path.join(os.path.dirname(__file__), 'words.txt')) as f:
|
|
|
|
for line in f:
|
|
|
|
checker.add(line.strip())
|
|
|
|
|
|
|
|
has_error = False
|
|
|
|
for error in checker:
|
|
|
|
print(f'Spelling error: {error.word}')
|
|
|
|
print(f'Context: {error.leading_context(30)}{error.word}{error.trailing_context(30)}')
|
|
|
|
has_error = True
|
|
|
|
sys.exit(has_error)
|