feat: ensure Godot file naming convention correctly.
This commit is contained in:
parent
a85f44e963
commit
dc1120f2c7
|
|
@ -6,6 +6,7 @@
|
|||
types: [text]
|
||||
exclude: |
|
||||
(?x)(
|
||||
^.pre-commit-config.yaml
|
||||
^.vscode/.* |
|
||||
^project/addons/.*
|
||||
)
|
||||
stages: [pre-commit, pre-merge-commit, manual]
|
||||
|
|
|
|||
|
|
@ -4,14 +4,40 @@ from pathlib import Path
|
|||
from click import argument, command, echo
|
||||
|
||||
|
||||
def check_path(path: Path) -> bool:
|
||||
str_path = str(path)
|
||||
valid_file_name = set([
|
||||
".editorconfig",
|
||||
".gitattributes",
|
||||
".gitignore",
|
||||
".gitkeep",
|
||||
".pre-commit-config.yaml",
|
||||
"__init__.py",
|
||||
"README.md",
|
||||
])
|
||||
|
||||
if path.suffix == ".cs":
|
||||
if re.search(r"^[a-zA-Z\\\/\._]*$", str_path) is None:
|
||||
pascal_case_extensions = set([
|
||||
".cs",
|
||||
".csproj",
|
||||
".sln",
|
||||
])
|
||||
|
||||
def check_path(path: Path) -> bool:
|
||||
|
||||
# folder names must use snake_case.
|
||||
for parent in path.parents:
|
||||
if parent.stem != "" and re.search(r"^[a-z]+(?:_[a-z0-9]+)*$", parent.stem) is None:
|
||||
return False
|
||||
|
||||
# File name exceptions.
|
||||
if valid_file_name.__contains__(path.name):
|
||||
return True
|
||||
|
||||
if pascal_case_extensions.__contains__(path.suffix):
|
||||
# Check that file name use PascalCase.
|
||||
if re.search(r"[A-Z][a-z0-9]*(?:[A-Z][a-z0-9]*)*(?:[A-Z]?)$", path.stem) is None:
|
||||
return False
|
||||
else:
|
||||
if re.search(r"^[a-z\\\/\._]*$", str_path) is None:
|
||||
# Check that file name use snake_case.
|
||||
if re.search(r"[a-z]+(?:_[a-z0-9]+)*$", path.stem) is None:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
|
|
|||
Loading…
Reference in New Issue