summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMatthäus G. Chajdas <dev@anteru.net>2023-02-01 21:18:44 +0100
committerMatthäus G. Chajdas <dev@anteru.net>2023-02-01 21:18:44 +0100
commit9d561d47ad32e5290708d7a290bac45d54ab9688 (patch)
treeac2efdbfc41bf046a52db5df0e19bc5db5646c38 /scripts
parent6ad47050a5d10412ec8697df87ec412e1acdaa64 (diff)
downloadpygments-git-9d561d47ad32e5290708d7a290bac45d54ab9688.tar.gz
Fix various linter issues.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/check_repeated_token.py23
-rwxr-xr-xscripts/check_sources.py2
-rw-r--r--scripts/check_whitespace_token.py15
-rwxr-xr-xscripts/count_token_references.py17
-rw-r--r--scripts/utility.py9
5 files changed, 34 insertions, 32 deletions
diff --git a/scripts/check_repeated_token.py b/scripts/check_repeated_token.py
index 16362813..2c2d8240 100755
--- a/scripts/check_repeated_token.py
+++ b/scripts/check_repeated_token.py
@@ -55,16 +55,7 @@ def check_file(path, threshold, single_only):
return True
-def main(args):
- def check_file_callback(path):
- return check_file(path, args.threshold, args.single)
-
- if process_output_files(args.TEST_ROOT, check_file_callback) > 0:
- return 1
- return 0
-
-
-if __name__ == '__main__':
+def main():
parser = argparse.ArgumentParser()
parser.add_argument('TEST_ROOT',
help='Root directory containing the tests')
@@ -74,4 +65,14 @@ if __name__ == '__main__':
parser.add_argument('-s', '--single', action='store_true', default=False,
help='Only look at tokens matching a single character')
args = parser.parse_args()
- sys.exit(main(args))
+
+ def check_file_callback(path):
+ return check_file(path, args.threshold, args.single)
+
+ if process_output_files(args.TEST_ROOT, check_file_callback) > 0:
+ return 1
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main())
diff --git a/scripts/check_sources.py b/scripts/check_sources.py
index 1feb1a33..f625cb19 100755
--- a/scripts/check_sources.py
+++ b/scripts/check_sources.py
@@ -37,7 +37,7 @@ copyright_re = re.compile(r'^ :copyright: Copyright 2006-2022 by '
r'the Pygments team, see AUTHORS\.$')
copyright_2_re = re.compile(r'^ %s(, %s)*[,.]$' %
(name_mail_re, name_mail_re))
-is_const_re = re.compile(r'if.*?==\s+(None|False|True)\b')
+is_const_re = re.compile(r'if.*?==\s+(None|False|True)\b')
misspellings = ["developement", "adress", "verificate", # ALLOW-MISSPELLING
"informations", "unlexer"] # ALLOW-MISSPELLING
diff --git a/scripts/check_whitespace_token.py b/scripts/check_whitespace_token.py
index f5d09703..ffa1e8d7 100644
--- a/scripts/check_whitespace_token.py
+++ b/scripts/check_whitespace_token.py
@@ -16,7 +16,7 @@ from utility import unpack_output_file, process_output_files
def check_file(path):
- whitespace_re = re.compile('\s+')
+ whitespace_re = re.compile('\\s+')
for value, token, linenumber in unpack_output_file(path):
if whitespace_re.fullmatch(value):
@@ -38,15 +38,16 @@ def check_file(path):
return True
-def main(args):
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('TEST_ROOT',
+ help='Root directory containing the tests')
+ args = parser.parse_args()
+
if process_output_files(args.TEST_ROOT, check_file) > 0:
return 1
return 0
if __name__ == '__main__':
- parser = argparse.ArgumentParser()
- parser.add_argument('TEST_ROOT',
- help='Root directory containing the tests')
- args = parser.parse_args()
- sys.exit(main(args))
+ sys.exit(main())
diff --git a/scripts/count_token_references.py b/scripts/count_token_references.py
index 8e798c2d..08083677 100755
--- a/scripts/count_token_references.py
+++ b/scripts/count_token_references.py
@@ -50,17 +50,17 @@ def lookup_all_lexers():
This should create all tokens that any of the lexers produce.
"""
count = 0
- for (name, aliases, patterns, mimetypes) in lexers.get_all_lexers():
- for a in aliases:
- l = lexers.get_lexer_by_name(a)
+ for (_, aliases, patterns, mimetypes) in lexers.get_all_lexers():
+ for alias in aliases:
+ _ = lexers.get_lexer_by_name(alias)
break
else:
- for p in patterns:
- l = lexers.get_lexer_for_filename(p)
+ for pattern in patterns:
+ _ = lexers.get_lexer_for_filename(pattern)
break
else:
- for m in mimetypes:
- l = lexers.get_lexer_for_mimetype(m)
+ for mimetype in mimetypes:
+ _ = lexers.get_lexer_for_mimetype(mimetype)
break
count += 1
return count
@@ -71,7 +71,8 @@ def fetch_lexer_sources():
Return the source code of all lexers as a dictionary, mapping filenames
to a list of lines.
"""
- lexer_dir = (pathlib.Path(__file__).parent / "../pygments/lexers").resolve()
+ lexer_dir = pathlib.Path(__file__).parent / "../pygments/lexers"
+ lexer_dir = lexer_dir.resolve()
lexer_sources = {
fn: fn.read_text(encoding='utf-8').splitlines(keepends=False)
for fn in lexer_dir.glob("*.py")
diff --git a/scripts/utility.py b/scripts/utility.py
index 48056f2c..6f02538d 100644
--- a/scripts/utility.py
+++ b/scripts/utility.py
@@ -29,9 +29,8 @@ def unpack_output_file(path):
if skip_until_tokens:
if line != '---tokens---':
continue
- else:
- skip_until_tokens = False
- continue
+
+ skip_until_tokens = False
# Line can start with ' or ", so let's check which one it is
# and find the matching one
@@ -55,14 +54,14 @@ def process_output_files(root_directory, callback):
``False``.
"""
errors = 0
- for dir, _, files in os.walk(root_directory):
+ for directory, _, files in os.walk(root_directory):
for file in files:
_, ext = os.path.splitext(file)
if ext not in {'.txt', '.output'}:
continue
- path = os.path.join(dir, file)
+ path = os.path.join(directory, file)
if not callback(path):
errors += 1