Skip to content

Commit 37b5f04

Browse files
authored
fix: make types and scopes case-insensitive (#135)
2 parents fa1915d + 039089d commit 37b5f04

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

conventional_pre_commit/format.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def __init__(
121121
@property
122122
def r_types(self):
123123
"""Regex str for valid types."""
124-
return self._r_or(self.types)
124+
return f"(?i:{self._r_or(self.types)})"
125125

126126
@property
127127
def r_scope(self):
@@ -130,7 +130,7 @@ def r_scope(self):
130130
scopes = self._r_or(self.scopes)
131131
escaped_delimiters = list(map(re.escape, [":", ",", "-", "/"])) # type: ignore
132132
delimiters_pattern = self._r_or(escaped_delimiters)
133-
scope_pattern = rf"\(\s*(?:{scopes})(?:\s*(?:{delimiters_pattern})\s*(?:{scopes}))*\s*\)"
133+
scope_pattern = rf"\(\s*(?:(?i:{scopes}))(?:\s*(?:{delimiters_pattern})\s*(?:(?i:{scopes})))*\s*\)"
134134

135135
if self.scope_optional:
136136
return f"(?:{scope_pattern})?"

tests/test_format.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,20 @@ def test_r_scope__scopes(conventional_commit_scope_required):
459459
assert not regex.match("(api; client)")
460460

461461

462+
def test_r_scope__scopes_uppercase(conventional_commit_scope_required):
463+
conventional_commit_scope_required.scopes = ["api", "client"]
464+
regex = re.compile(conventional_commit_scope_required.r_scope)
465+
466+
assert regex.match("(API)")
467+
assert regex.match("(CLIENT)")
468+
assert regex.match("(API, CLIENT)")
469+
assert regex.match("(API: CLIENT)")
470+
assert regex.match("(API/CLIENT)")
471+
assert regex.match("(API-CLIENT)")
472+
assert not regex.match("(TEST)")
473+
assert not regex.match("(API; CLIENT)")
474+
475+
462476
def test_r_delim(conventional_commit):
463477
regex = re.compile(conventional_commit.r_delim)
464478

@@ -565,13 +579,27 @@ def test_is_valid__default_type(conventional_commit, type):
565579
assert conventional_commit.is_valid(input)
566580

567581

582+
@pytest.mark.parametrize("type", ConventionalCommit.DEFAULT_TYPES)
583+
def test_is_valid__default_type_uppercase(conventional_commit, type):
584+
input = f"{type.upper()}: message"
585+
586+
assert conventional_commit.is_valid(input)
587+
588+
568589
@pytest.mark.parametrize("type", ConventionalCommit.CONVENTIONAL_TYPES)
569590
def test_is_valid__conventional_type(conventional_commit, type):
570591
input = f"{type}: message"
571592

572593
assert conventional_commit.is_valid(input)
573594

574595

596+
@pytest.mark.parametrize("type", ConventionalCommit.CONVENTIONAL_TYPES)
597+
def test_is_valid__conventional_type_uppercase(conventional_commit, type):
598+
input = f"{type.upper()}: message"
599+
600+
assert conventional_commit.is_valid(input)
601+
602+
575603
@pytest.mark.parametrize("type", CUSTOM_TYPES)
576604
def test_is_valid__custom_type(type):
577605
input = f"{type}: message"
@@ -588,6 +616,14 @@ def test_is_valid__conventional_custom_type(type):
588616
assert conventional_commits.is_valid(input)
589617

590618

619+
@pytest.mark.parametrize("type", ConventionalCommit.CONVENTIONAL_TYPES)
620+
def test_is_valid__conventional_custom_type_uppercase(type):
621+
input = f"{type.upper()}: message"
622+
conventional_commits = ConventionalCommit(types=CUSTOM_TYPES)
623+
624+
assert conventional_commits.is_valid(input)
625+
626+
591627
def test_is_valid__breaking_change(conventional_commit):
592628
input = "fix!: message"
593629

0 commit comments

Comments
 (0)