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.
This commit is contained in:
Philipp Albrecht 2023-06-30 11:03:19 +02:00
parent d9e8b638bf
commit 6f727664a9
1 changed files with 20 additions and 0 deletions

View File

@ -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()