Skip to content

Commit

Permalink
[ADD] name-non-ascii: Prevents file or directory names with ASCII cha…
Browse files Browse the repository at this point in the history
…racters (#134)
  • Loading branch information
maneandrea authored Aug 14, 2024
1 parent d1f7b31 commit 5644cf5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/pre_commit_vauxoo/cfg/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ repos:
# - --fix
- repo: local
hooks:
- id: name-non-ascii
name: Use only ASCII (no accents or special characters) for filenames and directory names
description: It may raise errors on OS without locale settings configured
entry: Use only ASCII (no accents or special characters) for filenames and directory names
language: fail
files: '[^\x00-\x7F]'
- id: vx-check-deactivate
name: deactivate.jinja syntax check.
description: Validate deactivate.jinja files' syntax.
Expand Down
24 changes: 24 additions & 0 deletions tests/test_pre_commit_vauxoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,30 @@ def test_valid_pylintrc_messages(self):

self.assertFalse(duplicates, f"Duplicate messages found in {rc_file}")

def test_special_char_filename(self):
os.environ["PRECOMMIT_HOOKS_TYPE"] = "mandatory"
fname_wrong = os.path.join(self.tmp_dir, "module_example1", "leéme.rst")
with open(fname_wrong, "w"):
pass
subprocess.check_call(["git", "add", "-A"])
expected_logs = ["ERROR:pre-commit-vauxoo:Mandatory checks failed"]
with self.custom_assert_logs("pre-commit-vauxoo", level="ERROR", expected_logs=expected_logs):
result = self.runner.invoke(main, [])
self.assertEqual(result.exit_code, 1, "Exited without error")

def test_special_char_dirname(self):
os.environ["PRECOMMIT_HOOKS_TYPE"] = "mandatory"
dirname_wrong = os.path.join(self.tmp_dir, "module_example1", "moisé")
os.mkdir(dirname_wrong)
fname = os.path.join(dirname_wrong, "empty_file.txt")
with open(fname, "w"):
pass
subprocess.check_call(["git", "add", "-A"])
expected_logs = ["ERROR:pre-commit-vauxoo:Mandatory checks failed"]
with self.custom_assert_logs("pre-commit-vauxoo", level="ERROR", expected_logs=expected_logs):
result = self.runner.invoke(main, [])
self.assertEqual(result.exit_code, 1, "Exited without error")


if __name__ == "__main__":
unittest.main()

0 comments on commit 5644cf5

Please sign in to comment.