From 46ede3fb9873ca0c5c3e5ec33f2dc065d5160662 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 16 Aug 2021 10:11:44 +0300 Subject: [PATCH] v check-md: reduce false positives for too long lines in various cases (real problems are easier to spot now) --- cmd/tools/vcheck-md.v | 38 ++++++++++++++++++++++++-------------- doc/docs.md | 9 +++++++-- vlib/term/README.md | 3 ++- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/cmd/tools/vcheck-md.v b/cmd/tools/vcheck-md.v index f5cd5eae21..3978b48b78 100644 --- a/cmd/tools/vcheck-md.v +++ b/cmd/tools/vcheck-md.v @@ -12,11 +12,15 @@ import v.pref import regex const ( - too_long_line_length = 100 - term_colors = term.can_show_color_on_stderr() - hide_warnings = '-hide-warnings' in os.args || '-w' in os.args - show_progress = os.getenv('GITHUB_JOB') == '' && '-silent' !in os.args - non_option_args = cmdline.only_non_options(os.args[2..]) + too_long_line_length_example = 120 + too_long_line_length_codeblock = 120 + too_long_line_length_table = 120 + too_long_line_length_link = 150 + too_long_line_length_other = 100 + term_colors = term.can_show_color_on_stderr() + hide_warnings = '-hide-warnings' in os.args || '-w' in os.args + show_progress = os.getenv('GITHUB_JOB') == '' && '-silent' !in os.args + non_option_args = cmdline.only_non_options(os.args[2..]) ) struct CheckResult { @@ -166,28 +170,34 @@ fn (mut f MDFile) check() CheckResult { mut anchor_data := AnchorData{} for j, line in f.lines { // f.progress('line: $j') - if line.len > too_long_line_length { - if f.state == .vexample { + if f.state == .vexample { + if line.len > too_long_line_length_example { wprintln(wline(f.path, j, line.len, 'long V example line')) wprintln(line) res.warnings++ - } else if f.state == .codeblock { + } + } else if f.state == .codeblock { + if line.len > too_long_line_length_codeblock { wprintln(wline(f.path, j, line.len, 'long code block line')) wprintln(line) res.warnings++ - } else if line.starts_with('|') { + } + } else if line.starts_with('|') { + if line.len > too_long_line_length_table { wprintln(wline(f.path, j, line.len, 'long table')) wprintln(line) res.warnings++ - } else if line.contains('https') { + } + } else if line.contains('http') { + if line.all_after('https').len > too_long_line_length_link { wprintln(wline(f.path, j, line.len, 'long link')) wprintln(line) res.warnings++ - } else { - eprintln(eline(f.path, j, line.len, 'line too long')) - eprintln(line) - res.errors++ } + } else if line.len > too_long_line_length_other { + eprintln(eline(f.path, j, line.len, 'line too long')) + eprintln(line) + res.errors++ } if f.state == .markdown { anchor_data.add_links(j, line) diff --git a/doc/docs.md b/doc/docs.md index 063ae8f222..033fa7a0b4 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -4037,8 +4037,13 @@ struct Customer { db := sqlite.connect('customers.db') ? -// you can create tables -// CREATE TABLE IF NOT EXISTS `Customer` (`id` INTEGER PRIMARY KEY, `name` TEXT NOT NULL, `nr_orders` INTEGER, `country` TEXT NOT NULL) +// you can create tables: +// CREATE TABLE IF NOT EXISTS `Customer` ( +// `id` INTEGER PRIMARY KEY, +// `name` TEXT NOT NULL, +// `nr_orders` INTEGER, +// `country` TEXT NOT NULL +// ) sql db { create table Customer } diff --git a/vlib/term/README.md b/vlib/term/README.md index 870822662e..f9fcb9ec67 100644 --- a/vlib/term/README.md +++ b/vlib/term/README.md @@ -56,7 +56,8 @@ term.fail_message('oh, no') term.warning_message('be warned') // clears the entire terminal and leaves a blank one term.clear() -// colors the output of the output, the available colors are: black,blue,yellow,green,cyan,gray,bright_blue,bright_green,bright_red,bright_black,bright_cyan +// colors the output of the output, the available colors are: +// black,blue,yellow,green,cyan,gray,bright_blue,bright_green,bright_red,bright_black,bright_cyan term.yellow('submarine') // transforms the given string into bold text term.bold('and beautiful')