mirror of
https://github.com/vlang/v.git
synced 2025-09-08 23:07:19 -04:00
tools.vet: move error methods to vvet/errors.v
(#21449)
This commit is contained in:
parent
0a9d65946b
commit
9604cd5f70
@ -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}'
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user