Skip to content

Commit

Permalink
fix(check): do match start of line and end of line for the default sc…
Browse files Browse the repository at this point in the history
…ope regex

Refs: #145
  • Loading branch information
hdevalke committed Sep 18, 2023
1 parent 81f59f1 commit 9986150
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/conventional/commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ pub struct CommitParserBuilder {
impl CommitParserBuilder {
pub fn new() -> Self {
Self {
scope_regex: "[[:alnum:]]+(?:[-_/][[:alnum:]]+)*".into(),
scope_regex: "^[[:alnum:]]+(?:[-_/][[:alnum:]]+)*$".into(),
references_regex: "(#)([0-9]+)".into(),
strip_regex: "".into(),
}
Expand Down Expand Up @@ -368,6 +368,16 @@ mod tests {
assert!(!commit.is_breaking());
}

#[test]
fn test_with_invalid_scope() {
let msg = "feat(invalid scope): add a foo to new bar";
let err = parser().parse(msg).expect_err("space not allowed");
assert_eq!(
err.to_string(),
"scope does not match regex: ^[[:alnum:]]+(?:[-_/][[:alnum:]]+)*$"
);
}

#[test]
fn test_with_breaking() {
let msg = "refactor!: drop support for Node 6";
Expand Down
8 changes: 4 additions & 4 deletions src/conventional/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub(crate) struct Config {
pub(crate) commit_template: Option<PathBuf>,
/// `scopeRegex`. A regex to define possible scopes.
/// For this project this could be `"changelog|check|commit|version"`.
/// Defaults to `"[[:alnum:]]+(?:[-_/][[:alnum:]]+)*"`.
/// Defaults to `"^[[:alnum:]]+(?:[-_/][[:alnum:]]+)*$"`.
#[serde(default = "default_scope_regex")]
pub(crate) scope_regex: String,
/// Default number of characters in a single line of the CHANGELOG.
Expand Down Expand Up @@ -116,7 +116,7 @@ impl Default for Config {
repository: None,
template: None,
commit_template: None,
scope_regex: "[[:alnum:]]+(?:[-_/][[:alnum:]]+)*".to_string(),
scope_regex: "^[[:alnum:]]+(?:[-_/][[:alnum:]]+)*$".to_string(),
link_compare: true,
link_references: true,
merges: false,
Expand Down Expand Up @@ -215,7 +215,7 @@ fn default_issue_prefixes() -> Vec<String> {
}

fn default_scope_regex() -> String {
"[[:alnum:]]+(?:[-_/][[:alnum:]]+)*".to_string()
"^[[:alnum:]]+(?:[-_/][[:alnum:]]+)*$".to_string()
}

fn default_strip_regex() -> String {
Expand Down Expand Up @@ -432,7 +432,7 @@ mod tests {
repository: None,
template: None,
commit_template: None,
scope_regex: "[[:alnum:]]+(?:[-_/][[:alnum:]]+)*".to_string(),
scope_regex: "^[[:alnum:]]+(?:[-_/][[:alnum:]]+)*$".to_string(),
link_compare: true,
link_references: true,
merges: false,
Expand Down

0 comments on commit 9986150

Please sign in to comment.