Skip to content

feat: add overflow on trailers #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 10 additions & 106 deletions corpus/body.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,133 +64,37 @@ And a paragraph.
(message))

================================================================================
Not a trailer
================================================================================
This is a simple subject

:This is a simple body.
: Fake
With a: second line.

An:d a paragraph.
test(trailer): test
--------------------------------------------------------------------------------

(source
(subject)
(message))

================================================================================
Simple trailer
================================================================================
This is a simple subject

Signed-by: gbprod <contact@gb-prod.fr>
--------------------------------------------------------------------------------

(source
(subject)
(message
(trailer
(token)
(value))))

================================================================================
Multiple trailers
================================================================================
This is a simple subject

Signed-by : gbprod <contact@gb-prod.fr>
Signed-off-by: Bob <bob@example.com>
Acked-by: Alice <alice@example.com>
Ref: #1234
Suggested-by: Toto

--------------------------------------------------------------------------------

(source
(subject)
(message
(trailer
(token)
(value))
(trailer
(token)
(value))
(trailer
(token)
(value))
(trailer
(token)
(value))
(trailer
(token)
(value))))

================================================================================
Multiline trailers
================================================================================
This is a simple subject

key: This is a very long value, with spaces and
newlines in it.

--------------------------------------------------------------------------------

(source
(subject)
(message
(trailer
(token)
(value))))

================================================================================
Mixed
BREAKING CHANGE
================================================================================
This is a simple subject

With a message
Signed-by : gbprod <contact@gb-prod.fr>

Not conventional but why not
Ref: #1234
Suggested-by: Toto

And go on
test

BREAKING CHANGE: My message
BREAKING-CHANGE: also valid
--------------------------------------------------------------------------------

(source
(subject)
(message
(trailer
(token)
(value))
(trailer
(breaking_change
(token)
(value))
(trailer
(breaking_change
(token)
(value))))

================================================================================
BREAKING CHANGE
BREAKING CHANGE with overflow
================================================================================

test

BREAKING CHANGE: My message
BREAKING-CHANGE: also valid
BREAKING CHANGE: My message with a long long text that will overflow with ease.
--------------------------------------------------------------------------------

(source
(message
(breaking_change
(token)
(value))
(breaking_change
(token)
(value))))
(value)
(overflow))))

================================================================================
Overflowed summary
Expand Down
126 changes: 126 additions & 0 deletions corpus/trailers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
================================================================================
Not a trailer
================================================================================
This is a simple subject

:This is a simple body.
: Fake
With a: second line.

An:d a paragraph.
test(trailer): test
--------------------------------------------------------------------------------

(source
(subject)
(message))

================================================================================
Simple trailer
================================================================================
This is a simple subject

Signed-by: gbprod <contact@gb-prod.fr>
--------------------------------------------------------------------------------

(source
(subject)
(message
(trailer
(token)
(value))))

================================================================================
Multiple trailers
================================================================================
This is a simple subject

Signed-by : gbprod <contact@gb-prod.fr>
Signed-off-by: Bob <bob@example.com>
Acked-by: Alice <alice@example.com>
Ref: #1234
Suggested-by: Toto

--------------------------------------------------------------------------------

(source
(subject)
(message
(trailer
(token)
(value))
(trailer
(token)
(value))
(trailer
(token)
(value))
(trailer
(token)
(value))
(trailer
(token)
(value))))

================================================================================
Multiline trailers
================================================================================
This is a simple subject

key: This is a very long value, with spaces and
newlines in it.

--------------------------------------------------------------------------------

(source
(subject)
(message
(trailer
(token)
(value))))

================================================================================
Mixed
================================================================================
This is a simple subject

With a message
Signed-by : gbprod <contact@gb-prod.fr>

Not conventional but why not
Ref: #1234
Suggested-by: Toto

And go on

--------------------------------------------------------------------------------

(source
(subject)
(message
(trailer
(token)
(value))
(trailer
(token)
(value))
(trailer
(token)
(value))))

================================================================================
Overflowed trailers
================================================================================
This is a simple subject

key: This is a very long value, with spaces and that will overflow the line size.

--------------------------------------------------------------------------------

(source
(subject)
(message
(trailer
(token)
(value)
(overflow))))
18 changes: 13 additions & 5 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ const SCOPE = /[^\n\r\(\)]+/;
const COMMENT = /[^\n\r]*\r?\n/;
const COMMENT_TITLE = /[^\n\r:\uff1a]+[:\uff1a]\s*\r?\n/;
const TRAILER_TOKEN = /[a-zA-Z-]+[ ]*[:\uff1a] /;
const TRAILER_VALUE = /[^\n\r]+(\r?\n [^\n\r]+)*/;
const GENERATED_COMMENT_TITLE = /[^\n\r:\uff1a]+[:\uff1a][ ]*/;
const NUMBER = /\d+/;
const BREAKING_CHANGE = /BREAKING[- ]CHANGE/;
const BREAKING_CHANGE = /BREAKING[- ]CHANGE[ ]*[:\uff1a] /;

module.exports = grammar({
name: 'gitcommit',
extras: () => [],

externals: ($) => [$._conventional_type, $._conventional_subject],
externals: ($) => [
$._conventional_type,
$._conventional_subject,
$._trailer_value,
],

rules: {
source: ($) =>
Expand Down Expand Up @@ -60,14 +63,19 @@ module.exports = grammar({
seq(seq(NOT_A_COMMENT, SUMMARY), optional(alias(ANYTHING, $.overflow))),

trailer: ($) =>
seq(alias(TRAILER_TOKEN, $.token), alias(TRAILER_VALUE, $.value)),
seq(
alias(TRAILER_TOKEN, $.token),
alias($._trailer_value, $.value),
optional(alias(ANYTHING, $.overflow))
),

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

comment: ($) =>
Expand Down
48 changes: 43 additions & 5 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,28 @@
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[^\\n\\r]+(\\r?\\n [^\\n\\r]+)*"
"type": "SYMBOL",
"name": "_trailer_value"
},
"named": true,
"value": "value"
},
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[^\\n\\r]+"
},
"named": true,
"value": "overflow"
},
{
"type": "BLANK"
}
]
}
]
},
Expand All @@ -347,7 +364,7 @@
"value": 1,
"content": {
"type": "PATTERN",
"value": "BREAKING[- ]CHANGE"
"value": "BREAKING[- ]CHANGE[ ]*[:\\uff1a] "
}
}
},
Expand All @@ -357,11 +374,28 @@
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[^\\n\\r]+"
"type": "SYMBOL",
"name": "_trailer_value"
},
"named": true,
"value": "value"
},
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[^\\n\\r]+"
},
"named": true,
"value": "overflow"
},
{
"type": "BLANK"
}
]
}
]
},
Expand Down Expand Up @@ -4250,6 +4284,10 @@
{
"type": "SYMBOL",
"name": "_conventional_subject"
},
{
"type": "SYMBOL",
"name": "_trailer_value"
}
],
"inline": [],
Expand Down
Loading
Loading