@@ -26,13 +26,15 @@ const vexe = @VEXE
26
26
27
27
struct CheckResult {
28
28
pub mut :
29
+ files int
29
30
warnings int
30
31
errors int
31
32
oks int
32
33
}
33
34
34
35
fn (v1 CheckResult) + (v2 CheckResult) CheckResult {
35
36
return CheckResult{
37
+ files: v1 .files + v2 .files
36
38
warnings: v1 .warnings + v2 .warnings
37
39
errors: v1 .errors + v2 .errors
38
40
oks: v1 .oks + v2 .oks
@@ -83,9 +85,7 @@ fn main() {
83
85
if res.errors == 0 && show_progress {
84
86
clear_previous_line ()
85
87
}
86
- if res.warnings > 0 || res.errors > 0 || res.oks > 0 {
87
- println ('\n Warnings: ${res.warnings} | Errors: ${res.errors} | OKs: ${res.oks} ' )
88
- }
88
+ println ('Checked .md files: ${res.files} | OKs: ${res.oks} | Warnings: ${res.warnings} | Errors: ${res.errors} ' )
89
89
if res.errors > 0 {
90
90
exit (1 )
91
91
}
@@ -171,40 +171,53 @@ fn (mut f MDFile) progress(message string) {
171
171
}
172
172
}
173
173
174
+ struct CheckResultContext {
175
+ path string
176
+ line_number int
177
+ line string
178
+ }
179
+
180
+ fn (mut res CheckResult) wcheck (actual int , limit int , ctx CheckResultContext, msg_template string ) {
181
+ if actual > limit {
182
+ wprintln (wline (ctx.path, ctx.line_number, ctx.line.len, msg_template.replace ('@' ,
183
+ limit.str ())))
184
+ wprintln (ctx.line)
185
+ wprintln (ftext ('-' .repeat (limit) + '^' , term.gray))
186
+ res.warnings++
187
+ }
188
+ }
189
+
190
+ fn (mut res CheckResult) echeck (actual int , limit int , ctx CheckResultContext, msg_template string ) {
191
+ if actual > limit {
192
+ eprintln (eline (ctx.path, ctx.line_number, ctx.line.len, msg_template.replace ('@' ,
193
+ limit.str ())))
194
+ eprintln (ctx.line)
195
+ eprintln (ftext ('-' .repeat (limit) + '^' , term.gray))
196
+ res.errors++
197
+ }
198
+ }
199
+
174
200
fn (mut f MDFile) check () CheckResult {
175
- mut res := CheckResult{}
201
+ mut res := CheckResult{
202
+ files: 1
203
+ }
176
204
mut anchor_data := AnchorData{}
177
205
for j, line in f.lines {
178
206
// f.progress('line: $j')
179
207
if ! f.skip_line_length_check {
208
+ ctx := CheckResultContext{f.path, j, line}
180
209
if f.state == .vexample {
181
- if line.len > too_long_line_length_example {
182
- wprintln (wline (f.path, j, line.len, 'example lines must be less than ${too_long_line_length_example} characters' ))
183
- wprintln (line)
184
- res.warnings++
185
- }
210
+ res.wcheck (line.len, too_long_line_length_example, ctx, 'example lines must be less than @ characters' )
186
211
} else if f.state == .codeblock {
187
- if line.len > too_long_line_length_codeblock {
188
- wprintln (wline (f.path, j, line.len, 'code lines must be less than ${too_long_line_length_codeblock} characters' ))
189
- wprintln (line)
190
- res.warnings++
191
- }
212
+ res.wcheck (line.len, too_long_line_length_codeblock, ctx, 'code lines must be less than @ characters' )
192
213
} else if line.starts_with ('|' ) {
193
- if line.len > too_long_line_length_table {
194
- wprintln (wline (f.path, j, line.len, 'table lines must be less than ${too_long_line_length_table} characters' ))
195
- wprintln (line)
196
- res.warnings++
197
- }
214
+ res.wcheck (line.len, too_long_line_length_table, ctx, 'table lines must be less than @ characters' )
198
215
} else if line.contains ('http' ) {
199
- if line.all_after ('https' ).len > too_long_line_length_link {
200
- wprintln (wline (f.path, j, line.len, 'link lines must be less than ${too_long_line_length_link} characters' ))
201
- wprintln (line)
202
- res.warnings++
203
- }
204
- } else if line.len > too_long_line_length_other {
205
- eprintln (eline (f.path, j, line.len, 'must be less than ${too_long_line_length_other} characters' ))
206
- eprintln (line)
207
- res.errors++
216
+ // vfmt off
217
+ res.wcheck (line.all_after ('https' ).len, too_long_line_length_link, ctx, 'link lines must be less than @ characters' )
218
+ // vfmt on
219
+ } else {
220
+ res.echeck (line.len, too_long_line_length_other, ctx, 'must be less than @ characters' )
208
221
}
209
222
}
210
223
if f.state == .markdown {
0 commit comments