v check-md: reduce false positives for too long lines in various cases (real problems are easier to spot now)

pull/11204/head
Delyan Angelov 2021-08-16 10:11:44 +03:00
parent e28dc0489d
commit 46ede3fb98
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 33 additions and 17 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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')