Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools.vet: move error methods to vvet/errors.v #21449

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions cmd/tools/vvet/errors.v
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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}'
}
64 changes: 0 additions & 64 deletions cmd/tools/vvet/vvet.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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