-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: apply suggestions from code review
Co-authored-by: Sugat Bajracharya <[email protected]>
- Loading branch information
Showing
5 changed files
with
110 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
[pytest] | ||
pythonpath = src | ||
python_files = test_*.py | ||
addopts = -vvv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# type: ignore | ||
# pylint: disable=all | ||
from typing import List, Tuple | ||
|
||
from commitlint.constants import COMMIT_HEADER_MAX_LENGTH | ||
from commitlint.messages import ( | ||
COMMIT_TYPE_INVALID_ERROR, | ||
COMMIT_TYPE_MISSING_ERROR, | ||
DESCRIPTION_FULL_STOP_END_ERROR, | ||
DESCRIPTION_LINE_BREAK_ERROR, | ||
DESCRIPTION_MISSING_ERROR, | ||
DESCRIPTION_MULTIPLE_SPACE_START_ERROR, | ||
DESCRIPTION_NO_LEADING_SPACE_ERROR, | ||
HEADER_LENGTH_ERROR, | ||
INCORRECT_FORMAT_ERROR, | ||
SCOPE_EMPTY_ERROR, | ||
SCOPE_WHITESPACE_ERROR, | ||
SPACE_AFTER_COMMIT_TYPE_ERROR, | ||
SPACE_AFTER_SCOPE_ERROR, | ||
) | ||
|
||
# LINTER_FIXTURE_PARAMS contains test data for the function `lint_commit_message`. The | ||
# purpose of creating this data is to ensure consistent results for both detailed and | ||
# quick commit message linting processes. | ||
# | ||
# The data consists of tuples, each representing a test case with the following | ||
# structure: | ||
# (commit_message, expected_success, expected_errors) | ||
# | ||
# - commit_message: The commit message to be tested. | ||
# - expected_success: A boolean indicating whether the commit message is expected to | ||
# pass or fail the linting. | ||
# - expected_errors: A list of error messages expected for detailed linting (not for | ||
# quick linting). | ||
LINTER_FIXTURE_PARAMS: Tuple[Tuple[str, bool, List[str], List[str]], ...] = ( | ||
# success | ||
("feat: add new feature", True, []), | ||
("feat: add new feature\n\nthis is body", True, []), | ||
( | ||
"feat: add new feature\n\nthis is body" + "a" * COMMIT_HEADER_MAX_LENGTH, | ||
True, | ||
[], | ||
), | ||
("feat: add new feature\n\nthis is body\n\ntest", True, []), | ||
("feat: add new feature\n", True, []), | ||
("build(deps-dev): bump @babel/traverse from 7.22.17 to 7.24.0", True, []), | ||
("feat(scope): add new feature\n#this is a comment", True, []), | ||
( | ||
"fix: fixed a bug\n\nthis is body\n" | ||
"# ------------------------ >8 ------------------------\nDiff message", | ||
True, | ||
[], | ||
), | ||
("Merge pull request #123", True, []), | ||
# incorrect format check | ||
("feat add new feature", False, [INCORRECT_FORMAT_ERROR]), | ||
# header length check | ||
("feat: " + "a" * (COMMIT_HEADER_MAX_LENGTH - 1), False, [HEADER_LENGTH_ERROR]), | ||
("feat: " + "a" * (COMMIT_HEADER_MAX_LENGTH - 1), False, [HEADER_LENGTH_ERROR]), | ||
( | ||
"Test " + "a" * (COMMIT_HEADER_MAX_LENGTH + 1), | ||
False, | ||
[HEADER_LENGTH_ERROR, INCORRECT_FORMAT_ERROR], | ||
), | ||
# commit type check | ||
(": add new feature", False, [COMMIT_TYPE_MISSING_ERROR]), | ||
("(invalid): add new feature", False, [COMMIT_TYPE_MISSING_ERROR]), | ||
("invalid: add new feature", False, [COMMIT_TYPE_INVALID_ERROR % "invalid"]), | ||
("feat (test): add new feature", False, [SPACE_AFTER_COMMIT_TYPE_ERROR]), | ||
( | ||
"invalid (test): add new feature", | ||
False, | ||
[COMMIT_TYPE_INVALID_ERROR % "invalid", SPACE_AFTER_COMMIT_TYPE_ERROR], | ||
), | ||
# scope check | ||
("feat(): add new feature", False, [SCOPE_EMPTY_ERROR]), | ||
("feat( ): add new feature", False, [SCOPE_WHITESPACE_ERROR]), | ||
("feat(hello world): add new feature", False, [SCOPE_WHITESPACE_ERROR]), | ||
("feat(test) : add new feature", False, [SPACE_AFTER_SCOPE_ERROR]), | ||
( | ||
"feat (test) : add new feature", | ||
False, | ||
[SPACE_AFTER_COMMIT_TYPE_ERROR, SPACE_AFTER_SCOPE_ERROR], | ||
), | ||
# description check | ||
("feat:add new feature", False, [DESCRIPTION_NO_LEADING_SPACE_ERROR]), | ||
("feat: add new feature", False, [DESCRIPTION_MULTIPLE_SPACE_START_ERROR]), | ||
("feat: add new feature\nhello baby", False, [DESCRIPTION_LINE_BREAK_ERROR]), | ||
("feat(test):", False, [DESCRIPTION_MISSING_ERROR]), | ||
("feat(test): ", False, [DESCRIPTION_MISSING_ERROR]), | ||
("feat(test): add new feature.", False, [DESCRIPTION_FULL_STOP_END_ERROR]), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters