2020-06-27 14:50:04 +02:00
|
|
|
// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
|
|
|
|
// Use of this source code is governed by an MIT license that can be found in the LICENSE file.
|
|
|
|
module main
|
|
|
|
|
|
|
|
import v.vet
|
|
|
|
import v.pref
|
|
|
|
import v.parser
|
|
|
|
import v.util
|
|
|
|
import v.table
|
|
|
|
import os
|
2020-07-04 14:29:00 +02:00
|
|
|
import os.cmdline
|
|
|
|
|
|
|
|
struct VetOptions {
|
|
|
|
is_verbose bool
|
2020-07-19 19:58:34 +02:00
|
|
|
errors []string
|
2020-07-04 14:29:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn (vet_options &VetOptions) vprintln(s string) {
|
|
|
|
if !vet_options.is_verbose {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
println(s)
|
|
|
|
}
|
2020-06-27 14:50:04 +02:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
args := util.join_env_vflags_and_os_args()
|
2020-07-04 14:29:00 +02:00
|
|
|
paths := cmdline.only_non_options(cmdline.options_after(args, ['vet']))
|
|
|
|
vet_options := VetOptions{
|
|
|
|
is_verbose: '-verbose' in args || '-v' in args
|
2020-06-27 14:50:04 +02:00
|
|
|
}
|
2020-07-04 14:29:00 +02:00
|
|
|
for path in paths {
|
2020-08-12 19:33:51 +02:00
|
|
|
if !os.exists(path) {
|
|
|
|
eprintln('File/folder $path does not exist')
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if path.ends_with('_test.v') || (path.contains('/tests/') && !path.contains('vlib/v/vet/')) {
|
|
|
|
eprintln('skipping $path')
|
2020-08-12 18:56:06 +02:00
|
|
|
continue
|
|
|
|
}
|
2020-07-04 14:29:00 +02:00
|
|
|
if path.ends_with('.v') {
|
|
|
|
vet_options.vet_file(path)
|
|
|
|
} else if os.is_dir(path) {
|
|
|
|
vet_options.vprintln("vetting folder '$path'...")
|
|
|
|
files := os.walk_ext(path, '.v')
|
|
|
|
for file in files {
|
2020-08-12 18:56:06 +02:00
|
|
|
if file.ends_with('_test.v') || file.contains('/tests/') { // TODO copy pasta
|
|
|
|
continue
|
|
|
|
}
|
2020-07-04 14:29:00 +02:00
|
|
|
vet_options.vet_file(file)
|
|
|
|
}
|
2020-06-27 14:50:04 +02:00
|
|
|
}
|
|
|
|
}
|
2020-07-19 19:58:34 +02:00
|
|
|
if vet_options.errors.len > 0 {
|
|
|
|
for err in vet_options.errors {
|
|
|
|
eprintln(err)
|
|
|
|
}
|
|
|
|
eprintln('NB: You can run `v fmt -w file.v` to fix these automatically')
|
|
|
|
exit(1)
|
|
|
|
}
|
2020-06-27 14:50:04 +02:00
|
|
|
}
|
|
|
|
|
2020-07-04 14:29:00 +02:00
|
|
|
fn (vet_options &VetOptions) vet_file(path string) {
|
|
|
|
mut prefs := pref.new_preferences()
|
|
|
|
prefs.is_vet = true
|
|
|
|
table := table.new_table()
|
|
|
|
vet_options.vprintln("vetting file '$path'...")
|
2020-07-19 19:58:34 +02:00
|
|
|
file_ast := parser.parse_vet_file(path, table, prefs, vet_options.errors)
|
2020-06-27 14:50:04 +02:00
|
|
|
vet.vet(file_ast, table, true)
|
|
|
|
}
|