From 646d46b4dc73c7516f9bb1bad197d3ffe0a8c2ba Mon Sep 17 00:00:00 2001 From: Lukas Neubert Date: Sat, 3 Apr 2021 18:30:15 +0200 Subject: [PATCH] vet: turn warnings into errors with -W flag (#9575) --- cmd/tools/vvet/vvet.v | 10 ++++++++-- vlib/v/vet/vet.v | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/tools/vvet/vvet.v b/cmd/tools/vvet/vvet.v index 7470f0bc97..b01fa5c7d4 100644 --- a/cmd/tools/vvet/vvet.v +++ b/cmd/tools/vvet/vvet.v @@ -77,7 +77,7 @@ fn main() { if vfmt_err_count > 0 { eprintln('NB: You can run `v fmt -w file.v` to fix these errors automatically') } - if vt.errors.len > 0 || (vt.opt.is_werror && vt.warns.len > 0) { + if vt.errors.len > 0 { exit(1) } } @@ -236,13 +236,19 @@ fn (mut vt Vet) warn(msg string, line int, fix vet.FixKind) { pos := token.Position{ line_nr: line + 1 } - vt.warns << vet.Error{ + mut w := vet.Error{ message: msg file_path: vt.file pos: pos kind: .warning fix: fix } + if vt.opt.is_werror { + w.kind = .error + vt.errors << w + } else { + vt.warns << w + } } fn should_use_color() bool { diff --git a/vlib/v/vet/vet.v b/vlib/v/vet/vet.v index 2a56b8431e..0c11132d13 100644 --- a/vlib/v/vet/vet.v +++ b/vlib/v/vet/vet.v @@ -16,12 +16,13 @@ pub enum FixKind { } pub struct Error { +pub mut: + kind ErrorKind [required] pub: // General message message string [required] details string // Details about how to resolve or fix the situation file_path string // file where the error have origin pos token.Position // position in the file - kind ErrorKind [required] fix FixKind [required] }