Skip to content

Commit f6f6be0

Browse files
committed
fix: non angular ignores preceding whitespace and scope
1 parent 7dcad35 commit f6f6be0

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "conventional_commits_linter"
3-
version = "0.8.0"
3+
version = "0.8.1"
44
description = "A tooling and language agnostic Git commit linter for the Conventional Commits specification."
55
authors = ["C <DeveloperC@protonmail.com>"]
66
edition = "2018"

src/linter/allow_angular_type_only/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ use crate::model::LintingError;
55
pub fn lint(commit_message: &str) -> Result<(), LintingError> {
66
lazy_static! {
77
static ref ANGULAR_TYPE_REGEX: Regex = Regex::new(&format!(
8-
r"(?i)^{}(\([[:alpha:]]*\))?{}:",
8+
r"(?i)^{}{}{}{}{}:",
9+
*crate::linter::regex::OPTIONAL_PRECEDING_WHITESPACE,
910
crate::linter::regex::ANGULAR_TYPE,
1011
crate::linter::regex::OPTIONAL_EXCLAMATION,
12+
crate::linter::regex::OPTIONAL_EMPTY_SCOPE_OR_SCOPE,
13+
crate::linter::regex::OPTIONAL_EXCLAMATION,
1114
))
1215
.unwrap();
1316
}

src/linter/tests/generated_tests/mod.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,66 @@ fn test_angular_type_commits_with_no_angular_type_only_assertion() {
6666
}
6767
}
6868
}
69+
70+
#[test]
71+
fn test_non_angular_type_commits_with_angular_type_only_assertion() {
72+
let number_of_variants: usize = 4;
73+
let allow_angular_type_only = true;
74+
75+
for i in 1..2_usize.pow(number_of_variants as u32) {
76+
//Given
77+
let binary_string = format!(
78+
"{:0desired_length$b}",
79+
i,
80+
desired_length = number_of_variants
81+
);
82+
83+
let (commits, mut expected_linting_errors) = generation::generate_non_angular_type_commits(
84+
utilities::is_position_in_binary_string_true(&binary_string, 0),
85+
utilities::is_position_in_binary_string_true(&binary_string, 1),
86+
utilities::is_position_in_binary_string_true(&binary_string, 2),
87+
utilities::is_position_in_binary_string_true(&binary_string, 3),
88+
);
89+
expected_linting_errors.push(LintingError::NonAngularType);
90+
91+
//When/Then
92+
for commit in commits {
93+
assert_linting_errors_eq!(
94+
expected_linting_errors,
95+
lint_commit(&commit, allow_angular_type_only),
96+
commit.message
97+
);
98+
}
99+
}
100+
}
101+
102+
#[test]
103+
fn test_angular_type_commits_with_angular_type_only_assertion() {
104+
let number_of_variants: usize = 4;
105+
let allow_angular_type_only = true;
106+
107+
for i in 1..2_usize.pow(number_of_variants as u32) {
108+
//Given
109+
let binary_string = format!(
110+
"{:0desired_length$b}",
111+
i,
112+
desired_length = number_of_variants
113+
);
114+
115+
let (commits, expected_linting_errors) = generation::generate_angular_type_commits(
116+
utilities::is_position_in_binary_string_true(&binary_string, 0),
117+
utilities::is_position_in_binary_string_true(&binary_string, 1),
118+
utilities::is_position_in_binary_string_true(&binary_string, 2),
119+
utilities::is_position_in_binary_string_true(&binary_string, 3),
120+
);
121+
122+
//When/Then
123+
for commit in commits {
124+
assert_linting_errors_eq!(
125+
expected_linting_errors,
126+
lint_commit(&commit, allow_angular_type_only),
127+
commit.message
128+
);
129+
}
130+
}
131+
}

0 commit comments

Comments
 (0)