Skip to content

Commit

Permalink
feat: add warning on subject overflow (#52)
Browse files Browse the repository at this point in the history
Ref: #46
  • Loading branch information
gbprod authored Feb 29, 2024
1 parent 7c01af8 commit 7fe4245
Show file tree
Hide file tree
Showing 8 changed files with 34,584 additions and 34,364 deletions.
20 changes: 16 additions & 4 deletions corpus/subject.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,26 @@ Empty file w/ empty comment
================================================================================
Subject overflow
================================================================================
this is a simple subject with an awesome overflow because it's longer than 50 characters
this is a subject with an overflow, it's longer than 50 characters

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

(source
(subject
(overflow)))

================================================================================
Subject overflow and warning
================================================================================
this is a simple subject with an awesome overflow because it's longer than 72 characters

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

(source
(subject
(overflow
(warning))))

================================================================================
Not a comment
================================================================================
Expand All @@ -92,8 +104,8 @@ This should not exists
--------------------------------------------------------------------------------

(source
(subject)
(ERROR))
(subject)
(ERROR))

================================================================================
Subject with type and scope
Expand Down Expand Up @@ -157,7 +169,7 @@ feat(issue42): allow numbers in scope

(source
(subject))

================================================================================
Parse fixup!
================================================================================
Expand Down
5 changes: 4 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const NEWLINE = /\r?\n/;
const ANYTHING = /[^\n\r]+/;
const SUBJECT = /[^\n\r]{1,49}/;
const OVERFLOW = /[^\n\r]{1,22}/;
const NOT_A_COMMENT = /[^#]/;
const SCISSORS = /# -+ >8 -+\r?\n/;
const BRANCH_NAME = /[^\s'”»"“]+/;
Expand Down Expand Up @@ -41,9 +42,11 @@ module.exports = grammar({
seq(NOT_A_COMMENT, SUBJECT),
seq($.prefix, $._conventional_subject)
),
optional(alias(ANYTHING, $.overflow))
optional($.overflow)
),

overflow: ($) => seq(OVERFLOW, optional(alias(ANYTHING, $.warning))),

prefix: ($) =>
seq(
alias($._conventional_type, $.type),
Expand Down
2 changes: 1 addition & 1 deletion queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

(subject) @text.title
(subject (overflow) @text)
(subject (overflow (warning) @text.warning))
(prefix (type) @keyword)
(prefix (scope) @parameter)
(prefix [
Expand All @@ -31,4 +32,3 @@
(scissor) @comment
(subject_prefix) @keyword

(ERROR) @error
23 changes: 22 additions & 1 deletion src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,27 @@
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "overflow"
},
{
"type": "BLANK"
}
]
}
]
},
"overflow": {
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "[^\\n\\r]{1,22}"
},
{
"type": "CHOICE",
"members": [
Expand All @@ -178,7 +199,7 @@
"value": "[^\\n\\r]+"
},
"named": true,
"value": "overflow"
"value": "warning"
},
{
"type": "BLANK"
Expand Down
23 changes: 19 additions & 4 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@
"named": true,
"fields": {}
},
{
"type": "overflow",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": false,
"types": [
{
"type": "warning",
"named": true
}
]
}
},
{
"type": "prefix",
"named": true,
Expand Down Expand Up @@ -988,10 +1003,6 @@
"type": "ny fil:",
"named": false
},
{
"type": "overflow",
"named": true
},
{
"type": "pick",
"named": false
Expand Down Expand Up @@ -1124,6 +1135,10 @@
"type": "value",
"named": true
},
{
"type": "warning",
"named": true
},
{
"type": "yeni dosya:",
"named": false
Expand Down
Loading

0 comments on commit 7fe4245

Please sign in to comment.