Skip to content

Commit 78b3a11

Browse files
fix(scope-capitalization): Update scope regex to be consistent with commitlint in DangerJS (#6)
1 parent 81324ad commit 78b3a11

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Where:
7474

7575
- `<type>`: a descriptor of the performed change, e.g., `feat`, `fix`, `refactor`, etc. Use one of the specified types (either default or provided using the `--types` parameter).
7676

77-
- `<scope/component>` (optional): the scope or component that the commit pertains to. It should start with a lowercase letter.
77+
- `<scope/component>` (optional): the scope or component that the commit pertains to. It should be written in lower case without whitespace, allowed special characters in `scope` are `_` `/` `.` `,` `*` `-` `.`
7878

7979
- `<summary>`: a short, concise description of the change. It should not end with a period, and be between `subject_min_length` and `subject_max_length` characters long (as specified by script parameters). If the `--summary-uppercase` flag is used, then the summary must start with a uppercase letter.
8080

conventional_precommit_linter/hook.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
ERROR_EMPTY_MESSAGE = 'Commit message seems to be empty.'
1010
ERROR_MISSING_COLON = "Missing colon after 'type' or 'scope'. Ensure the commit message has the format '<type><(scope/component)>: <summary>'." # noqa: E501
1111
ERROR_TYPE = "Issue with 'type'. Ensure the type is one of [{}]."
12-
ERROR_SCOPE_CAPITALIZATION = "Issue with 'scope'. Ensure the scope starts with a lowercase letter. Allowed special characters in `scope` are _ / . , * -" # noqa: E501
12+
ERROR_SCOPE_CAPITALIZATION = "Issue with 'scope'. Ensure the 'scope' is written in lower case without whitespace. Allowed special characters in 'scope' are _ / . , * -" # noqa: E501
1313
ERROR_SUMMARY_LENGTH = "Issue with 'summary'. Ensure the summary is between {} and {} characters long."
1414
ERROR_SUMMARY_CAPITALIZATION = "Issue with 'summary'. Ensure the summary starts with an uppercase letter."
1515
ERROR_SUMMARY_PERIOD = "Issue with 'summary'. Ensure the summary does not end with a period."
@@ -50,7 +50,7 @@ def raise_error(message: str, error: str, types: str, args: argparse.Namespace)
5050
5151
commit message rules:
5252
- use one of the following types: [{types}]
53-
- 'scope/component' is optional, but if used, it must start with a lowercase letter
53+
- 'scope/component' is optional, but if used, must be written in lower case without whitespace
5454
- 'summary' must not end with a period
5555
- 'summary' must be between {args.subject_min_length} and {args.subject_max_length} characters long
5656
- 'body' is optional, but if used, lines must be no longer than {args.body_max_line_length} characters
@@ -122,7 +122,7 @@ def parse_commit_message(args: argparse.Namespace, input_commit_message: str) ->
122122
raise_error(message_title, error, types, args)
123123

124124
# If 'scope' is provided, check for valid 'scope'
125-
REGEX_SCOPE = r'^[a-z][a-zA-Z0-9_/.,*-]*$'
125+
REGEX_SCOPE = r'^[a-z0-9_/.,*-]*$'
126126
if commit_scope and not re.match(REGEX_SCOPE, commit_scope):
127127
raise_error(message_title, ERROR_SCOPE_CAPITALIZATION, types, args)
128128

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "conventional_precommit_linter"
3-
version = "1.1.0"
3+
version = "1.2.1"
44
description = "A pre-commit hook that checks commit messages for Conventional Commits formatting."
55
readme = "README.md"
66
license = { file = "LICENSE" }

tests/test_custom_args.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@
114114
False,
115115
ERROR_SCOPE_CAPITALIZATION,
116116
),
117+
(
118+
# Expected FAIL: uppercase in 'scope'
119+
'fix(dangerGH): Update token permissions - allow Danger to add comments to PR',
120+
False,
121+
ERROR_SCOPE_CAPITALIZATION,
122+
),
117123
(
118124
# Expected FAIL: not allowed 'type' with scope and body
119125
'delete(bt): Added new feature with change\n\nThis feature adds functionality',

tests/test_default_args.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@
106106
False,
107107
ERROR_SCOPE_CAPITALIZATION,
108108
),
109+
(
110+
# Expected FAIL: uppercase in 'scope'
111+
'fix(dangerGH): Update token permissions - allow Danger to add comments to PR',
112+
False,
113+
ERROR_SCOPE_CAPITALIZATION,
114+
),
109115
(
110116
# Expected FAIL: not allowed 'type' with scope and body
111117
'delete(bt): Added new feature with change\n\nThis feature adds functionality',

0 commit comments

Comments
 (0)