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 import regex
const ( const (
too_long_line_length = 100 too_long_line_length_example = 120
term_colors = term.can_show_color_on_stderr() too_long_line_length_codeblock = 120
hide_warnings = '-hide-warnings' in os.args || '-w' in os.args too_long_line_length_table = 120
show_progress = os.getenv('GITHUB_JOB') == '' && '-silent' !in os.args too_long_line_length_link = 150
non_option_args = cmdline.only_non_options(os.args[2..]) 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 { struct CheckResult {
@ -166,28 +170,34 @@ fn (mut f MDFile) check() CheckResult {
mut anchor_data := AnchorData{} mut anchor_data := AnchorData{}
for j, line in f.lines { for j, line in f.lines {
// f.progress('line: $j') // 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(wline(f.path, j, line.len, 'long V example line'))
wprintln(line) wprintln(line)
res.warnings++ 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(wline(f.path, j, line.len, 'long code block line'))
wprintln(line) wprintln(line)
res.warnings++ 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(wline(f.path, j, line.len, 'long table'))
wprintln(line) wprintln(line)
res.warnings++ 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(wline(f.path, j, line.len, 'long link'))
wprintln(line) wprintln(line)
res.warnings++ 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 { if f.state == .markdown {
anchor_data.add_links(j, line) anchor_data.add_links(j, line)

View File

@ -4037,8 +4037,13 @@ struct Customer {
db := sqlite.connect('customers.db') ? db := sqlite.connect('customers.db') ?
// you can create tables // 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) // CREATE TABLE IF NOT EXISTS `Customer` (
// `id` INTEGER PRIMARY KEY,
// `name` TEXT NOT NULL,
// `nr_orders` INTEGER,
// `country` TEXT NOT NULL
// )
sql db { sql db {
create table Customer create table Customer
} }

View File

@ -56,7 +56,8 @@ term.fail_message('oh, no')
term.warning_message('be warned') term.warning_message('be warned')
// clears the entire terminal and leaves a blank one // clears the entire terminal and leaves a blank one
term.clear() 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') term.yellow('submarine')
// transforms the given string into bold text // transforms the given string into bold text
term.bold('and beautiful') term.bold('and beautiful')