mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-03-29 10:16:52 +00:00
Added check_naming_convention hook
This commit is contained in:
parent
aae27b8a3e
commit
5802220a75
1 changed files with 20 additions and 0 deletions
20
pre_commit_hooks/check_naming_convention.py
Normal file
20
pre_commit_hooks/check_naming_convention.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import re
|
||||
import sys
|
||||
import os
|
||||
|
||||
def check_naming_convention(files):
|
||||
for file_path in files:
|
||||
with open(file_path, 'r') as file:
|
||||
lines = file.readlines()
|
||||
for line_num, line in enumerate(lines, start=1):
|
||||
words = re.findall(r'\b[a-zA-Z0-9_]+\b', line)
|
||||
for word in words:
|
||||
if re.match(r'^[a-z]+(?:_[a-z]+)*$', word):
|
||||
continue # Valid snake_case
|
||||
elif re.match(r'^[A-Z][a-zA-Z0-9]*$', word):
|
||||
if '_' in word:
|
||||
print(f"WARNING: CamelCase with underscores found in {os.path.basename(file_path)}:{line_num}: {word}")
|
||||
continue # Valid CamelCase
|
||||
else:
|
||||
print(f"ERROR: Invalid naming convention in {os.path.basename(file_path)}:{line_num}: {word}")
|
||||
sys.exit(1)
|
||||
Loading…
Add table
Add a link
Reference in a new issue