Skip to content

Commit 09cab3c

Browse files
committed
fix: fix partial type matching
Closes #11
1 parent d995140 commit 09cab3c

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Unreleased
22

3+
- fix: fix partial type matching (#11)
34
- feat: add support for optional `!` in scope (#12)
45

56
## v1.3.0 (2023-11-09)

conventional_precommit_linter/hook.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@
2727
}
2828

2929

30-
def allowed_types(args: argparse.Namespace) -> str:
30+
def allowed_types(args: argparse.Namespace) -> list[str]:
3131
default_types = ['change', 'ci', 'docs', 'feat', 'fix', 'refactor', 'remove', 'revert']
3232
# Provided types take precedence over default types
3333
types = args.types[0].split(',') if args.types else default_types
34-
return ', '.join(types)
34+
return [commit_type.strip() for commit_type in types]
35+
3536

3637

3738
def read_commit_message(file_path: str) -> str:
@@ -139,7 +140,7 @@ def print_report(commit_type: str, commit_scope: Optional[str], commit_summary:
139140

140141
# Rule messages that are always included
141142
rule_messages = [
142-
f"{_get_icon_for_rule(rules_output_status['error_type'])} {_color_purple('<type>')} is mandatory, use one of the following: [{_color_purple(allowed_types(args))}]",
143+
f"{_get_icon_for_rule(rules_output_status['error_type'])} {_color_purple('<type>')} is mandatory, use one of the following: [{_color_purple(', '.join(allowed_types(args)))}]",
143144
f"{_get_icon_for_rule(rules_output_status['error_scope_format'])} {_color_blue('(<optional-scope>)')} if used, must be enclosed in parentheses",
144145
f"{_get_icon_for_rule(rules_output_status['error_scope_capitalization'])} {_color_blue('(<optional-scope>)')} if used, must be written in lower case without whitespace",
145146
f"{_get_icon_for_rule(rules_output_status['error_summary_period'])} {_color_orange('<summary>')} must not end with a period",

tests/test_default_args.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ def commit_message_id(commit_message): # pylint: disable=redefined-outer-name
129129
'Fix(bt): Added new feature with change\n\nThis feature adds functionality',
130130
{'error_type': True},
131131
),
132+
(
133+
# Expected Fail: partial type
134+
'chan: This is commit message with partial type',
135+
{'error_type': True},
136+
),
132137
(
133138
# Expected FAIL: missing blank line between 'summary' and 'body'
134139
'change: Added new feature with change\nThis feature adds functionality',

0 commit comments

Comments
 (0)