Skip to content

Commit

Permalink
fix(scope-capitalization): Update scope regex to be consistent with c…
Browse files Browse the repository at this point in the history
…ommitlint in DangerJS (#6)
  • Loading branch information
tomassebestik authored Jul 31, 2023
1 parent 81324ad commit 78b3a11
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Where:

- `<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).

- `<scope/component>` (optional): the scope or component that the commit pertains to. It should start with a lowercase letter.
- `<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 `_` `/` `.` `,` `*` `-` `.`

- `<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.

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

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

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "conventional_precommit_linter"
version = "1.1.0"
version = "1.2.1"
description = "A pre-commit hook that checks commit messages for Conventional Commits formatting."
readme = "README.md"
license = { file = "LICENSE" }
Expand Down
6 changes: 6 additions & 0 deletions tests/test_custom_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@
False,
ERROR_SCOPE_CAPITALIZATION,
),
(
# Expected FAIL: uppercase in 'scope'
'fix(dangerGH): Update token permissions - allow Danger to add comments to PR',
False,
ERROR_SCOPE_CAPITALIZATION,
),
(
# Expected FAIL: not allowed 'type' with scope and body
'delete(bt): Added new feature with change\n\nThis feature adds functionality',
Expand Down
6 changes: 6 additions & 0 deletions tests/test_default_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@
False,
ERROR_SCOPE_CAPITALIZATION,
),
(
# Expected FAIL: uppercase in 'scope'
'fix(dangerGH): Update token permissions - allow Danger to add comments to PR',
False,
ERROR_SCOPE_CAPITALIZATION,
),
(
# Expected FAIL: not allowed 'type' with scope and body
'delete(bt): Added new feature with change\n\nThis feature adds functionality',
Expand Down

0 comments on commit 78b3a11

Please sign in to comment.