summaryrefslogtreecommitdiffstats
path: root/scripts/check_whitespace_token.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 11:33:32 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 11:33:32 +0000
commit1f403ad2197fc7442409f434ee574f3e6b46fb73 (patch)
tree0299c6dd11d5edfa918a29b6456bc1875f1d288c /scripts/check_whitespace_token.py
parentInitial commit. (diff)
downloadpygments-1f403ad2197fc7442409f434ee574f3e6b46fb73.tar.xz
pygments-1f403ad2197fc7442409f434ee574f3e6b46fb73.zip
Adding upstream version 2.14.0+dfsg.upstream/2.14.0+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'scripts/check_whitespace_token.py')
-rw-r--r--scripts/check_whitespace_token.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/scripts/check_whitespace_token.py b/scripts/check_whitespace_token.py
new file mode 100644
index 0000000..f5d0970
--- /dev/null
+++ b/scripts/check_whitespace_token.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python
+"""
+ Checker for whitespace tokens
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ Helper script to find whitespace which is not of token type `Whitespace`
+
+ :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+import argparse
+import sys
+import re
+
+from utility import unpack_output_file, process_output_files
+
+
+def check_file(path):
+ whitespace_re = re.compile('\s+')
+
+ for value, token, linenumber in unpack_output_file(path):
+ if whitespace_re.fullmatch(value):
+ # We allow " " if it's inside a Literal.String for example
+ if 'Literal' in token:
+ continue
+
+ # If whitespace is part of a comment, we accept that as well,
+ # as comments may be similarly highlighted to literals
+ if 'Comment' in token:
+ continue
+
+ if 'Whitespace' in token:
+ continue
+
+ print(f'{path}:{linenumber}')
+ return False
+
+ return True
+
+
+def main(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))