diff --git a/cmd/tools/vvet/errors.v b/cmd/tools/vvet/errors.v index 4d5ef3bccd..01e2895df3 100644 --- a/cmd/tools/vvet/errors.v +++ b/cmd/tools/vvet/errors.v @@ -1,6 +1,7 @@ // Copyright (c) 2019-2024 Alexander Medvednikov. All rights reserved. // Use of this source code is governed by an MIT license that can be found in the LICENSE file. import v.token +import term pub enum ErrorKind { error @@ -34,3 +35,65 @@ pub: fix FixKind @[required] typ ErrorType @[required] } + +fn (mut vt Vet) error(msg string, line int, fix FixKind) { + pos := token.Pos{ + line_nr: line + 1 + } + vt.errors << VetError{ + message: msg + file_path: vt.file + pos: pos + kind: .error + fix: fix + typ: .default + } +} + +fn (mut vt Vet) warn(msg string, line int, fix FixKind) { + pos := token.Pos{ + line_nr: line + 1 + } + mut w := VetError{ + message: msg + file_path: vt.file + pos: pos + kind: .warning + fix: fix + typ: .default + } + if vt.opt.is_werror { + w.kind = .error + vt.errors << w + } else { + vt.warns << w + } +} + +fn (mut vt Vet) notice(msg string, line int, fix FixKind) { + pos := token.Pos{ + line_nr: line + 1 + } + vt.notices << VetError{ + message: msg + file_path: vt.file + pos: pos + kind: .notice + fix: fix + typ: .default + } +} + +fn (vt &Vet) e2string(err VetError) string { + mut kind := '${err.kind}:' + mut location := '${err.file_path}:${err.pos.line_nr}:' + if vt.opt.use_color { + kind = term.bold(match err.kind { + .warning { term.magenta(kind) } + .error { term.red(kind) } + .notice { term.yellow(kind) } + }) + location = term.bold(location) + } + return '${location} ${kind} ${err.message}' +} diff --git a/cmd/tools/vvet/vvet.v b/cmd/tools/vvet/vvet.v index bbd1b406e3..c335755f5c 100644 --- a/cmd/tools/vvet/vvet.v +++ b/cmd/tools/vvet/vvet.v @@ -6,7 +6,6 @@ import os import os.cmdline import v.pref import v.parser -import v.token import v.ast import v.help import term @@ -325,21 +324,6 @@ fn (vt &Vet) vprintln(s string) { println(s) } -fn (vt &Vet) e2string(err VetError) string { - mut kind := '${err.kind}:' - mut location := '${err.file_path}:${err.pos.line_nr}:' - if vt.opt.use_color { - kind = match err.kind { - .warning { term.magenta(kind) } - .error { term.red(kind) } - .notice { term.yellow(kind) } - } - kind = term.bold(kind) - location = term.bold(location) - } - return '${location} ${kind} ${err.message}' -} - fn (mut vt Vet) vet_in_condition(expr ast.InfixExpr) { if expr.right is ast.ArrayInit && expr.right.exprs.len == 1 && expr.op in [.key_in, .not_in] { left := expr.left.str() @@ -349,51 +333,3 @@ fn (mut vt Vet) vet_in_condition(expr ast.InfixExpr) { expr.pos.line_nr, .vfmt) } } - -fn (mut vt Vet) error(msg string, line int, fix FixKind) { - pos := token.Pos{ - line_nr: line + 1 - } - vt.errors << VetError{ - message: msg - file_path: vt.file - pos: pos - kind: .error - fix: fix - typ: .default - } -} - -fn (mut vt Vet) warn(msg string, line int, fix FixKind) { - pos := token.Pos{ - line_nr: line + 1 - } - mut w := VetError{ - message: msg - file_path: vt.file - pos: pos - kind: .warning - fix: fix - typ: .default - } - if vt.opt.is_werror { - w.kind = .error - vt.errors << w - } else { - vt.warns << w - } -} - -fn (mut vt Vet) notice(msg string, line int, fix FixKind) { - pos := token.Pos{ - line_nr: line + 1 - } - vt.notices << VetError{ - message: msg - file_path: vt.file - pos: pos - kind: .notice - fix: fix - typ: .default - } -}