Skip to content

Commit

Permalink
Reduce length of hook names to <50
Browse files Browse the repository at this point in the history
resolves #59
  • Loading branch information
sirosen committed Nov 27, 2023
1 parent 211a1d2 commit 06236e9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ repos:
rev: 5.12.0
hooks:
- id: isort
- repo: local
hooks:
- id: check-hook-name-length
name: 'Check hook name length'
language: python
entry: ./scripts/check-hook-name-length.py
files: ^\.pre-commit-hooks\.yaml$
2 changes: 1 addition & 1 deletion .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
language: python
types: [text]
- id: fix-spaces
name: 'Fix irregular space characters by normalizing to "space"'
name: 'Normalize irregular space characters to "space"'
description: 'Replace non-breaking spaces and other characters with the standard space character'
entry: fix-spaces
language: python
Expand Down
34 changes: 34 additions & 0 deletions scripts/check-hook-name-length.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python
import os
import sys

ROOTDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
HOOK_FILE = os.path.join(ROOTDIR, ".pre-commit-hooks.yaml")


def iter_hook_names():
with open(HOOK_FILE) as fp:
for line in fp:
line = line.strip()
if line.startswith(("name: ", "- name: ")):
name = line.partition(":")[2].strip()
if name.startswith("'"):
yield name.strip("'")
elif name.startswith('"'):
yield name.strip('"')
else:
yield name


def main():
success = True
for hook_name in iter_hook_names():
if len(hook_name) > 50:
print(f"ERROR: hook name too long: '{hook_name}'")
success = False
if not success:
sys.exit(1)


if __name__ == "__main__":
main()

0 comments on commit 06236e9

Please sign in to comment.