From 1f403ad2197fc7442409f434ee574f3e6b46fb73 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 13:33:32 +0200 Subject: Adding upstream version 2.14.0+dfsg. Signed-off-by: Daniel Baumann --- scripts/check_whitespace_token.py | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 scripts/check_whitespace_token.py (limited to 'scripts/check_whitespace_token.py') 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)) -- cgit v1.2.3