Skip to content

Commit a7db476

Browse files
committed
fix: add misisng validation.py module
1 parent 3a37fe7 commit a7db476

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
Feature validation utilities.
3+
4+
Shared validation functions for feature names and descriptions.
5+
"""
6+
7+
import re
8+
from typing import Tuple
9+
10+
11+
# Valid description prefixes (conventional commits style)
12+
VALID_PREFIXES = ("feat:", "fix:", "build:", "chore:", "series:")
13+
14+
15+
def validate_description(description: str) -> Tuple[bool, str]:
16+
"""Validate description has required prefix.
17+
18+
Returns:
19+
Tuple of (is_valid, error_message)
20+
"""
21+
description = description.strip()
22+
if not description:
23+
return False, "Description cannot be empty"
24+
25+
if not any(description.startswith(prefix) for prefix in VALID_PREFIXES):
26+
return False, f"Description must start with one of: {', '.join(VALID_PREFIXES)}"
27+
28+
return True, ""
29+
30+
31+
def validate_feature_name(name: str) -> Tuple[bool, str]:
32+
"""Validate feature name format.
33+
34+
Feature names should be lowercase kebab-case identifiers.
35+
36+
Returns:
37+
Tuple of (is_valid, error_message)
38+
"""
39+
if not name:
40+
return False, "Feature name cannot be empty"
41+
42+
if " " in name:
43+
return False, "Feature name cannot contain spaces (use hyphens instead)"
44+
45+
if ":" in name:
46+
return False, "Feature name cannot contain ':' (did you pass a description as the name?)"
47+
48+
if name != name.lower():
49+
return False, f"Feature name must be lowercase (got '{name}', use '{name.lower()}')"
50+
51+
# Check for valid characters (alphanumeric, hyphens, underscores)
52+
if not re.match(r'^[a-z0-9][a-z0-9_-]*$', name):
53+
return False, "Feature name must start with a letter/number and contain only lowercase letters, numbers, hyphens, and underscores"
54+
55+
return True, ""

0 commit comments

Comments
 (0)