Skip to content

Commit 9d8c81e

Browse files
authored
fix: recognize BREAKING-CHANGE trailers (#40)
> 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
1 parent 6c14f8b commit 9d8c81e

File tree

4 files changed

+23814
-23609
lines changed

4 files changed

+23814
-23609
lines changed

corpus/body.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,14 @@ BREAKING CHANGE
163163
test
164164

165165
BREAKING CHANGE: My message
166-
166+
BREAKING-CHANGE: also valid
167167
--------------------------------------------------------------------------------
168168

169169
(source
170170
(message
171+
(breaking_change
172+
(token)
173+
(value))
171174
(breaking_change
172175
(token)
173176
(value))))

grammar.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const COMMENT_TITLE = /[^\n\r:\uff1a]+[:\uff1a]\s*\r?\n/;
1313
const TRAILER_TOKEN = /[a-zA-Z-]+[ ]*[:\uff1a] /;
1414
const GENERATED_COMMENT_TITLE = /[^\n\r:\uff1a]+[:\uff1a][ ]*/;
1515
const NUMBER = /\d+/;
16+
const BREAKING_CHANGE = /BREAKING[- ]CHANGE/;
1617

1718
module.exports = grammar({
1819
name: 'gitcommit',
@@ -56,7 +57,12 @@ module.exports = grammar({
5657
seq(alias(TRAILER_TOKEN, $.token), alias(ANYTHING, $.value)),
5758

5859
breaking_change: ($) =>
59-
seq(alias('BREAKING CHANGE', $.token), alias(ANYTHING, $.value)),
60+
seq(
61+
// BREAKING_CHANGE conflicts with TRAILER_TOKEN, an so requires higher
62+
// lexical precedence
63+
alias(token(prec(1, BREAKING_CHANGE)), $.token),
64+
alias(ANYTHING, $.value)
65+
),
6066

6167
comment: ($) =>
6268
seq(

src/grammar.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,15 @@
287287
{
288288
"type": "ALIAS",
289289
"content": {
290-
"type": "STRING",
291-
"value": "BREAKING CHANGE"
290+
"type": "TOKEN",
291+
"content": {
292+
"type": "PREC",
293+
"value": 1,
294+
"content": {
295+
"type": "PATTERN",
296+
"value": "BREAKING[- ]CHANGE"
297+
}
298+
}
292299
},
293300
"named": true,
294301
"value": "token"

0 commit comments

Comments
 (0)