From b04b8d438b11f113203ba240d3c5c737fbdd616d Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 24 Jan 2021 00:13:21 +0200 Subject: [PATCH] tools: print the offending markdown source line, for errors and warnings --- cmd/tools/check-md.v | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/tools/check-md.v b/cmd/tools/check-md.v index 59feed7c74..18f9b79c94 100644 --- a/cmd/tools/check-md.v +++ b/cmd/tools/check-md.v @@ -22,7 +22,7 @@ fn wprintln(s string) { fn main() { if os.args.len == 1 { - println('Usage: checks the passed markdown files for correct ```v ``` code blocks, + println('Usage: checks the passed markdown files for correct ```v ``` code blocks, and for other style violations. like too long lines/links etc... a) `v run cmd/tools/check-md.v -all` - will check *all* .md files in the folders. b) `v run cmd/tools/check-md.v doc/docs.md` - will only check a single file. @@ -61,18 +61,23 @@ These are: if line.len > too_long_line_length { if mdfile.state == .vexample { wprintln(wline(file_path, i, line.len, 'long V example line')) + wprintln(line) warnings++ } else if mdfile.state == .codeblock { wprintln(wline(file_path, i, line.len, 'long code block line')) + wprintln(line) warnings++ } else if line.starts_with('|') { wprintln(wline(file_path, i, line.len, 'long table')) + wprintln(line) warnings++ } else if line.contains('https') { wprintln(wline(file_path, i, line.len, 'long link')) + wprintln(line) warnings++ } else { eprintln(eline(file_path, i, line.len, 'line too long')) + eprintln(line) errors++ } } @@ -129,7 +134,8 @@ fn rtext(s string) string { } fn wline(file_path string, lnumber int, column int, message string) string { - return btext('$file_path:${lnumber + 1}:${column + 1}:') + btext(mtext(' warn:')) + rtext(' $message') + return btext('$file_path:${lnumber + 1}:${column + 1}:') + btext(mtext(' warn:')) + + rtext(' $message') } fn eline(file_path string, lnumber int, column int, message string) string { @@ -155,7 +161,7 @@ enum MDFileParserState { } struct MDFile { - path string + path string mut: examples []VCodeExample current VCodeExample