Skip to content

Commit 7fe4245

Browse files
authored
feat: add warning on subject overflow (#52)
Ref: #46
1 parent 7c01af8 commit 7fe4245

File tree

8 files changed

+34584
-34364
lines changed

8 files changed

+34584
-34364
lines changed

corpus/subject.txt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,26 @@ Empty file w/ empty comment
6565
================================================================================
6666
Subject overflow
6767
================================================================================
68-
this is a simple subject with an awesome overflow because it's longer than 50 characters
68+
this is a subject with an overflow, it's longer than 50 characters
6969

7070
--------------------------------------------------------------------------------
7171

7272
(source
7373
(subject
7474
(overflow)))
7575

76+
================================================================================
77+
Subject overflow and warning
78+
================================================================================
79+
this is a simple subject with an awesome overflow because it's longer than 72 characters
80+
81+
--------------------------------------------------------------------------------
82+
83+
(source
84+
(subject
85+
(overflow
86+
(warning))))
87+
7688
================================================================================
7789
Not a comment
7890
================================================================================
@@ -92,8 +104,8 @@ This should not exists
92104
--------------------------------------------------------------------------------
93105

94106
(source
95-
(subject)
96-
(ERROR))
107+
(subject)
108+
(ERROR))
97109

98110
================================================================================
99111
Subject with type and scope
@@ -157,7 +169,7 @@ feat(issue42): allow numbers in scope
157169

158170
(source
159171
(subject))
160-
172+
161173
================================================================================
162174
Parse fixup!
163175
================================================================================

grammar.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const NEWLINE = /\r?\n/;
22
const ANYTHING = /[^\n\r]+/;
33
const SUBJECT = /[^\n\r]{1,49}/;
4+
const OVERFLOW = /[^\n\r]{1,22}/;
45
const NOT_A_COMMENT = /[^#]/;
56
const SCISSORS = /# -+ >8 -+\r?\n/;
67
const BRANCH_NAME = /[^\s'»"]+/;
@@ -41,9 +42,11 @@ module.exports = grammar({
4142
seq(NOT_A_COMMENT, SUBJECT),
4243
seq($.prefix, $._conventional_subject)
4344
),
44-
optional(alias(ANYTHING, $.overflow))
45+
optional($.overflow)
4546
),
4647

48+
overflow: ($) => seq(OVERFLOW, optional(alias(ANYTHING, $.warning))),
49+
4750
prefix: ($) =>
4851
seq(
4952
alias($._conventional_type, $.type),

queries/highlights.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
(subject) @text.title
1111
(subject (overflow) @text)
12+
(subject (overflow (warning) @text.warning))
1213
(prefix (type) @keyword)
1314
(prefix (scope) @parameter)
1415
(prefix [
@@ -31,4 +32,3 @@
3132
(scissor) @comment
3233
(subject_prefix) @keyword
3334

34-
(ERROR) @error

src/grammar.json

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,27 @@
168168
}
169169
]
170170
},
171+
{
172+
"type": "CHOICE",
173+
"members": [
174+
{
175+
"type": "SYMBOL",
176+
"name": "overflow"
177+
},
178+
{
179+
"type": "BLANK"
180+
}
181+
]
182+
}
183+
]
184+
},
185+
"overflow": {
186+
"type": "SEQ",
187+
"members": [
188+
{
189+
"type": "PATTERN",
190+
"value": "[^\\n\\r]{1,22}"
191+
},
171192
{
172193
"type": "CHOICE",
173194
"members": [
@@ -178,7 +199,7 @@
178199
"value": "[^\\n\\r]+"
179200
},
180201
"named": true,
181-
"value": "overflow"
202+
"value": "warning"
182203
},
183204
{
184205
"type": "BLANK"

src/node-types.json

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,21 @@
170170
"named": true,
171171
"fields": {}
172172
},
173+
{
174+
"type": "overflow",
175+
"named": true,
176+
"fields": {},
177+
"children": {
178+
"multiple": false,
179+
"required": false,
180+
"types": [
181+
{
182+
"type": "warning",
183+
"named": true
184+
}
185+
]
186+
}
187+
},
173188
{
174189
"type": "prefix",
175190
"named": true,
@@ -988,10 +1003,6 @@
9881003
"type": "ny fil:",
9891004
"named": false
9901005
},
991-
{
992-
"type": "overflow",
993-
"named": true
994-
},
9951006
{
9961007
"type": "pick",
9971008
"named": false
@@ -1124,6 +1135,10 @@
11241135
"type": "value",
11251136
"named": true
11261137
},
1138+
{
1139+
"type": "warning",
1140+
"named": true
1141+
},
11271142
{
11281143
"type": "yeni dosya:",
11291144
"named": false

0 commit comments

Comments
 (0)