From 6f727664a9d8945e1f536b69ea0f3b0aae9e29e0 Mon Sep 17 00:00:00 2001 From: Philipp Albrecht Date: Fri, 30 Jun 2023 11:03:19 +0200 Subject: Add misc check to prevent vim modelines We deprecated vim modelines. The introduced misc check will keep old pull requests from re-introducing vim modelines. --- scripts/dev/misc_checks.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scripts/dev/misc_checks.py b/scripts/dev/misc_checks.py index 82c3d48c1..a1df9e51d 100644 --- a/scripts/dev/misc_checks.py +++ b/scripts/dev/misc_checks.py @@ -397,6 +397,25 @@ def check_userscript_shebangs(_args: argparse.Namespace) -> bool: return ok +def check_vim_modelines(args: argparse.Namespace) -> bool: + """Check that we're not using vim modelines.""" + ok = True + try: + for path in _get_files(verbose=args.verbose): + with tokenize.open(str(path)) as f: + for num, line in enumerate(f, start=1): + if not line.startswith("# vim:"): + continue + print(f"{path}:{num}: Remove vim modeline " + "(deprecated in favor of .editorconfig)") + ok = False + except Exception: + traceback.print_exc() + ok = False + + return ok + + def main() -> int: checkers = { 'git': check_git, @@ -406,6 +425,7 @@ def main() -> int: 'userscript-descriptions': check_userscripts_descriptions, 'userscript-shebangs': check_userscript_shebangs, 'changelog-urls': check_changelog_urls, + 'vim-modelines': check_vim_modelines, } parser = argparse.ArgumentParser() -- cgit v1.2.3-54-g00ecf