Skip to content

Commit

Permalink
fix: recognize BREAKING-CHANGE trailers (#40)
Browse files Browse the repository at this point in the history
> 16. `BREAKING-CHANGE` MUST be synonymous with `BREAKING CHANGE`, when used as a token in a footer.
> -- https://www.conventionalcommits.org/en/v1.0.0/#specification

Fixes #39
  • Loading branch information
SKalt authored May 19, 2023
1 parent 6c14f8b commit 9d8c81e
Show file tree
Hide file tree
Showing 4 changed files with 23,814 additions and 23,609 deletions.
5 changes: 4 additions & 1 deletion corpus/body.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,14 @@ BREAKING CHANGE
test

BREAKING CHANGE: My message

BREAKING-CHANGE: also valid
--------------------------------------------------------------------------------

(source
(message
(breaking_change
(token)
(value))
(breaking_change
(token)
(value))))
8 changes: 7 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const COMMENT_TITLE = /[^\n\r:\uff1a]+[:\uff1a]\s*\r?\n/;
const TRAILER_TOKEN = /[a-zA-Z-]+[ ]*[:\uff1a] /;
const GENERATED_COMMENT_TITLE = /[^\n\r:\uff1a]+[:\uff1a][ ]*/;
const NUMBER = /\d+/;
const BREAKING_CHANGE = /BREAKING[- ]CHANGE/;

module.exports = grammar({
name: 'gitcommit',
Expand Down Expand Up @@ -56,7 +57,12 @@ module.exports = grammar({
seq(alias(TRAILER_TOKEN, $.token), alias(ANYTHING, $.value)),

breaking_change: ($) =>
seq(alias('BREAKING CHANGE', $.token), alias(ANYTHING, $.value)),
seq(
// BREAKING_CHANGE conflicts with TRAILER_TOKEN, an so requires higher
// lexical precedence
alias(token(prec(1, BREAKING_CHANGE)), $.token),
alias(ANYTHING, $.value)
),

comment: ($) =>
seq(
Expand Down
11 changes: 9 additions & 2 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,15 @@
{
"type": "ALIAS",
"content": {
"type": "STRING",
"value": "BREAKING CHANGE"
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "BREAKING[- ]CHANGE"
}
}
},
"named": true,
"value": "token"
Expand Down
Loading

0 comments on commit 9d8c81e

Please sign in to comment.