Skip to content

Commit b12adac

Browse files
committed
refactor: only specify scope delimiters once
1 parent 10d1e31 commit b12adac

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-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/test_format.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,16 @@ def test_match_multiline(conventional_commit):
560560
assert match.group("body").strip() == "body copy"
561561

562562

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+
563573
def test_match_invalid_type(conventional_commit):
564574
match = conventional_commit.match(
565575
"""invalid(scope): subject line

0 commit comments

Comments
 (0)