Skip to content

Commit

Permalink
feat(parser): adjust scope parsing (without braces)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Zaunseder committed Feb 1, 2024
1 parent 91940d2 commit 59db7f4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
5 changes: 3 additions & 2 deletions src/commit.pest
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
commit = { SOI ~ header ~ body? ~ footer? ~ EOI }

header = ${ commit_type ~ scope? ~ "!"? ~ ":" ~ WHITE_SPACE+ ~ subject }
header = ${ commit_type ~ scope_with_braces? ~ "!"? ~ ":" ~ WHITE_SPACE+ ~ subject }

commit_type = @{ ASCII_ALPHANUMERIC+ }

scope = @{ "(" ~ ASCII_ALPHANUMERIC+ ~ ")" }
scope = @{ ASCII_ALPHANUMERIC+ }
scope_with_braces = _{ "(" ~ scope ~ ")" }

subject = @{ text_without_newline }

Expand Down
5 changes: 5 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ mod tests {
commit: String::from("feat: add cool feature\nsome body"),
want_err: true,
},
TestConfig {
name: String::from("random text"),
commit: String::from("Added a cool new feature"),
want_err: true,
},
];

for test_config in test_configs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ commit_type:
start: 0
end: 4
scope:
input: (nice)
start: 4
end: 10
input: nice
start: 5
end: 9
subject:
input: add cool feature
start: 12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ commit_type:
start: 0
end: 4
scope:
input: (nice)
start: 4
end: 10
input: nice
start: 5
end: 9
subject:
input: add cool feature
start: 13
Expand Down
6 changes: 3 additions & 3 deletions src/snapshots/commitlint_rs__parser__tests__complex.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ commit_type:
start: 0
end: 4
scope:
input: (nice)
start: 4
end: 10
input: nice
start: 5
end: 9
subject:
input: add cool feature
start: 12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ commit_type:
start: 0
end: 4
scope:
input: (nice)
start: 4
end: 10
input: nice
start: 5
end: 9
subject:
input: add cool feature
start: 12
Expand Down

0 comments on commit 59db7f4

Please sign in to comment.