vvet: allow passing many files, improve specifity for emacs goto error
parent
dc3101384f
commit
68af46402e
|
@ -9,33 +9,48 @@ import v.parser
|
|||
import v.util
|
||||
import v.table
|
||||
import os
|
||||
import os.cmdline
|
||||
|
||||
fn main() {
|
||||
mut prefs := pref.new_preferences()
|
||||
prefs.is_vet = true
|
||||
table := table.new_table()
|
||||
args := util.join_env_vflags_and_os_args()
|
||||
if args.len < 3 {
|
||||
struct VetOptions {
|
||||
is_verbose bool
|
||||
}
|
||||
|
||||
fn (vet_options &VetOptions) vprintln(s string) {
|
||||
if !vet_options.is_verbose {
|
||||
return
|
||||
}
|
||||
path := args[2]
|
||||
println(s)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
args := util.join_env_vflags_and_os_args()
|
||||
paths := cmdline.only_non_options(cmdline.options_after(args, ['vet']))
|
||||
vet_options := VetOptions{
|
||||
is_verbose: '-verbose' in args || '-v' in args
|
||||
}
|
||||
for path in paths {
|
||||
if path.ends_with('.v') {
|
||||
vet_file(path, table, prefs)
|
||||
vet_options.vet_file(path)
|
||||
} else if os.is_dir(path) {
|
||||
println("vet'ing directory '$path'...")
|
||||
vet_options.vprintln("vetting folder '$path'...")
|
||||
files := os.walk_ext(path, '.v')
|
||||
for file in files {
|
||||
vet_file(file, table, prefs)
|
||||
vet_options.vet_file(file)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn vet_file(path string, table &table.Table, prefs &pref.Preferences) {
|
||||
fn (vet_options &VetOptions) vet_file(path string) {
|
||||
mut prefs := pref.new_preferences()
|
||||
prefs.is_vet = true
|
||||
table := table.new_table()
|
||||
if path.contains('/tests') {
|
||||
return
|
||||
}
|
||||
file_ast := parser.parse_file(path, table, .parse_comments, prefs, &ast.Scope{
|
||||
parent: 0
|
||||
})
|
||||
vet_options.vprintln("vetting file '$path'...")
|
||||
vet.vet(file_ast, table, true)
|
||||
}
|
||||
|
|
|
@ -115,9 +115,13 @@ pub fn parse_file(path string, b_table &table.Table, comments_mode scanner.Comme
|
|||
global_scope: global_scope
|
||||
}
|
||||
if pref.is_vet && p.scanner.text.contains('\n ') {
|
||||
// TODO make this smarter
|
||||
println(p.scanner.file_path)
|
||||
println('Looks like you are using spaces for indentation.\n' + 'You can run `v fmt -w file.v` to fix that automatically')
|
||||
source_lines := os.read_lines(path) or { []string{} }
|
||||
for lnumber, line in source_lines {
|
||||
if line.starts_with(' ') {
|
||||
eprintln('${p.scanner.file_path}:${lnumber+1}: Looks like you are using spaces for indentation.')
|
||||
}
|
||||
}
|
||||
eprintln('NB: You can run `v fmt -w file.v` to fix these automatically')
|
||||
exit(1)
|
||||
}
|
||||
return p.parse()
|
||||
|
|
Loading…
Reference in New Issue