Skip to content

Commit 5d2940c

Browse files
authored
fix: scope now allows usage of dots (#140)
2 parents 37b5f04 + b12adac commit 5d2940c

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

conventional_pre_commit/format.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ def r_types(self):
126126
@property
127127
def r_scope(self):
128128
"""Regex str for an optional (scope)."""
129+
escaped_delimiters = list(map(re.escape, [":", ",", "-", "/", "."])) # type: ignore
129130
if self.scopes:
130131
scopes = self._r_or(self.scopes)
131-
escaped_delimiters = list(map(re.escape, [":", ",", "-", "/"])) # type: ignore
132132
delimiters_pattern = self._r_or(escaped_delimiters)
133133
scope_pattern = rf"\(\s*(?:(?i:{scopes}))(?:\s*(?:{delimiters_pattern})\s*(?:(?i:{scopes})))*\s*\)"
134134

@@ -137,10 +137,11 @@ def r_scope(self):
137137
else:
138138
return scope_pattern
139139

140+
joined_delimiters = "".join(escaped_delimiters)
140141
if self.scope_optional:
141-
return r"(\([\w \/:,-]+\))?"
142+
return rf"(\([\w {joined_delimiters}]+\))?"
142143
else:
143-
return r"(\([\w \/:,-]+\))"
144+
return rf"(\([\w {joined_delimiters}]+\))"
144145

145146
@property
146147
def r_delim(self):

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ def conventional_utf8_commit_path():
3434
return get_message_path("conventional_commit_utf-8")
3535

3636

37+
@pytest.fixture
38+
def conventional_commit_with_dots_path():
39+
return get_message_path("conventional_commit_with_dots")
40+
41+
3742
@pytest.fixture
3843
def conventional_gbk_commit_path():
3944
return get_message_path("conventional_commit_gbk")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
feat(customer.registration): adds support for oauth2

tests/test_format.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ def test_r_scope__special_chars(conventional_commit_scope_required):
443443
assert regex.match("(some thing)")
444444
assert regex.match("(some:thing)")
445445
assert regex.match("(some,thing)")
446+
assert regex.match("(some.thing)")
446447

447448

448449
def test_r_scope__scopes(conventional_commit_scope_required):
@@ -455,6 +456,7 @@ def test_r_scope__scopes(conventional_commit_scope_required):
455456
assert regex.match("(api: client)")
456457
assert regex.match("(api/client)")
457458
assert regex.match("(api-client)")
459+
assert regex.match("(api.client)")
458460
assert not regex.match("(test)")
459461
assert not regex.match("(api; client)")
460462

@@ -469,6 +471,7 @@ def test_r_scope__scopes_uppercase(conventional_commit_scope_required):
469471
assert regex.match("(API: CLIENT)")
470472
assert regex.match("(API/CLIENT)")
471473
assert regex.match("(API-CLIENT)")
474+
assert regex.match("(API.CLIENT)")
472475
assert not regex.match("(TEST)")
473476
assert not regex.match("(API; CLIENT)")
474477

@@ -557,6 +560,16 @@ def test_match_multiline(conventional_commit):
557560
assert match.group("body").strip() == "body copy"
558561

559562

563+
def test_match_dots(conventional_commit):
564+
match = conventional_commit.match("""feat(foo.bar): hello world""")
565+
assert isinstance(match, re.Match)
566+
assert match.group("type") == "feat"
567+
assert match.group("scope") == "(foo.bar)"
568+
assert match.group("delim") == ":"
569+
assert match.group("subject").strip() == "hello world"
570+
assert match.group("body").strip() == ""
571+
572+
560573
def test_match_invalid_type(conventional_commit):
561574
match = conventional_commit.match(
562575
"""invalid(scope): subject line

tests/test_hook.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ def test_main_success__conventional_utf8(conventional_utf8_commit_path):
5454
assert result == RESULT_SUCCESS
5555

5656

57+
def test_main_success__conventional_commit_with_dots_path(conventional_commit_with_dots_path):
58+
result = main([conventional_commit_with_dots_path])
59+
60+
assert result == RESULT_SUCCESS
61+
62+
5763
def test_main_fail__conventional_gbk(conventional_gbk_commit_path):
5864
result = main([conventional_gbk_commit_path])
5965

0 commit comments

Comments
 (0)