From 5b4484e40116a24ba7afe702aad50457342a8845 Mon Sep 17 00:00:00 2001 From: Ralph Sennhauser Date: Wed, 11 Sep 2024 19:15:07 +0200 Subject: [PATCH] Add pre-commit hook for filenames Closes: #6327 --- .pre-commit-config.yaml | 7 +++++++ lint/pre-commit-hooks/sane_filenames.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100755 lint/pre-commit-hooks/sane_filenames.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 40bf599453..0c74535cca 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -75,3 +75,10 @@ repos: args: - --strict exclude: ^build/premake/premake5/ + - repo: local + hooks: + - id: sane-filenames + name: sane-filenames + language: python + types: [file] + entry: ./lint/pre-commit-hooks/sane_filenames.py diff --git a/lint/pre-commit-hooks/sane_filenames.py b/lint/pre-commit-hooks/sane_filenames.py new file mode 100755 index 0000000000..b272eeb1f7 --- /dev/null +++ b/lint/pre-commit-hooks/sane_filenames.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 + +import re +import sys + + +re_allowed_name = re.compile("^[-_./A-Za-z0-9]*$") + +has_error = False +for f in sys.argv[1:]: + if not re_allowed_name.match(f): + has_error = True + print(f) + +if has_error: + sys.exit(1)