From 0b0a5de9e5437835376db4d92e80ecf5f1d4f5bc Mon Sep 17 00:00:00 2001 From: Lukas Neubert Date: Tue, 20 Apr 2021 16:20:50 +0200 Subject: [PATCH] vet: hide skipped file messages behind verbose flag (#9823) --- cmd/tools/vvet/vvet.v | 20 +++++--------------- cmd/v/help/vet.txt | 15 +++++++++++---- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/cmd/tools/vvet/vvet.v b/cmd/tools/vvet/vvet.v index 9841ed707d..43b75ddcd9 100644 --- a/cmd/tools/vvet/vvet.v +++ b/cmd/tools/vvet/vvet.v @@ -27,16 +27,17 @@ struct Options { use_color bool } -const vet_options = cmdline.options_after(os.args, ['vet']) +const term_colors = term.can_show_color_on_stderr() fn main() { + vet_options := cmdline.options_after(os.args, ['vet']) mut vt := Vet{ opt: Options{ is_force: '-force' in vet_options is_werror: '-W' in vet_options is_verbose: '-verbose' in vet_options || '-v' in vet_options - show_warnings: '-hide-warnings' !in vet_options - use_color: should_use_color() + show_warnings: '-hide-warnings' !in vet_options && '-w' !in vet_options + use_color: '-color' in vet_options || (term_colors && '-nocolor' !in vet_options) } } mut paths := cmdline.only_non_options(vet_options) @@ -88,7 +89,7 @@ fn (mut vt Vet) vet_file(path string) { // skip all /tests/ files, since usually their content is not // important enough to be documented/vetted, and they may even // contain intentionally invalid code. - eprintln("skipping test file: '$path' ...") + vt.vprintln("skipping test file: '$path' ...") return } vt.file = path @@ -252,14 +253,3 @@ fn (mut vt Vet) warn(msg string, line int, fix vet.FixKind) { vt.warns << w } } - -fn should_use_color() bool { - mut color := term.can_show_color_on_stderr() - if '-nocolor' in vet_options { - color = false - } - if '-color' in vet_options { - color = true - } - return color -} diff --git a/cmd/v/help/vet.txt b/cmd/v/help/vet.txt index 813a0ab511..7a0d2bf33f 100644 --- a/cmd/v/help/vet.txt +++ b/cmd/v/help/vet.txt @@ -5,7 +5,14 @@ Usage: Reports suspicious code constructs. Options: - -W Exit with code 1, even if vet only reported warnings. Useful for checks in CI. - -hide-warnings Do not print warnings to stderr. - -v, -verbose Enable verbose logging. - -force (NB: vet development only!) Do not skip the vet regression tests. + -W + Exit with code 1, even if vet only reported warnings. Useful for checks in CI. + + -w, -hide-warnings + Do not print warnings to stderr. + + -v, -verbose + Enable verbose logging. + + -force + (NB: vet development only!) Do not skip the vet regression tests.