Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions conventional_pre_commit/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def __init__(
@property
def r_types(self):
"""Regex str for valid types."""
return self._r_or(self.types)
return f"(?i:{self._r_or(self.types)})"

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

if self.scope_optional:
return f"(?:{scope_pattern})?"
Expand Down
36 changes: 36 additions & 0 deletions tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,20 @@ def test_r_scope__scopes(conventional_commit_scope_required):
assert not regex.match("(api; client)")


def test_r_scope__scopes_uppercase(conventional_commit_scope_required):
conventional_commit_scope_required.scopes = ["api", "client"]
regex = re.compile(conventional_commit_scope_required.r_scope)

assert regex.match("(API)")
assert regex.match("(CLIENT)")
assert regex.match("(API, CLIENT)")
assert regex.match("(API: CLIENT)")
assert regex.match("(API/CLIENT)")
assert regex.match("(API-CLIENT)")
assert not regex.match("(TEST)")
assert not regex.match("(API; CLIENT)")


def test_r_delim(conventional_commit):
regex = re.compile(conventional_commit.r_delim)

Expand Down Expand Up @@ -565,13 +579,27 @@ def test_is_valid__default_type(conventional_commit, type):
assert conventional_commit.is_valid(input)


@pytest.mark.parametrize("type", ConventionalCommit.DEFAULT_TYPES)
def test_is_valid__default_type_uppercase(conventional_commit, type):
input = f"{type.upper()}: message"

assert conventional_commit.is_valid(input)


@pytest.mark.parametrize("type", ConventionalCommit.CONVENTIONAL_TYPES)
def test_is_valid__conventional_type(conventional_commit, type):
input = f"{type}: message"

assert conventional_commit.is_valid(input)


@pytest.mark.parametrize("type", ConventionalCommit.CONVENTIONAL_TYPES)
def test_is_valid__conventional_type_uppercase(conventional_commit, type):
input = f"{type.upper()}: message"

assert conventional_commit.is_valid(input)


@pytest.mark.parametrize("type", CUSTOM_TYPES)
def test_is_valid__custom_type(type):
input = f"{type}: message"
Expand All @@ -588,6 +616,14 @@ def test_is_valid__conventional_custom_type(type):
assert conventional_commits.is_valid(input)


@pytest.mark.parametrize("type", ConventionalCommit.CONVENTIONAL_TYPES)
def test_is_valid__conventional_custom_type_uppercase(type):
input = f"{type.upper()}: message"
conventional_commits = ConventionalCommit(types=CUSTOM_TYPES)

assert conventional_commits.is_valid(input)


def test_is_valid__breaking_change(conventional_commit):
input = "fix!: message"

Expand Down
Loading