vvet: allow passing many files, improve specifity for emacs goto error

pull/5656/head
Delyan Angelov 2020-07-04 15:29:00 +03:00
parent dc3101384f
commit 68af46402e
3 changed files with 40 additions and 21 deletions

View File

@ -632,9 +632,9 @@ fn (mut cfg DocConfig) generate_docs_from_file() {
}
if cfg.include_readme {
readme_contents := cfg.get_readme(dir_path)
if cfg.output_type == .stdout {
if cfg.output_type == .stdout {
println(markdown.to_plain(readme_contents))
} else if cfg.output_type == .html && cfg.is_multi {
} else if cfg.output_type == .html && cfg.is_multi {
cfg.docs << doc.Doc{
head: doc.DocNode{
name: 'README',
@ -642,7 +642,7 @@ fn (mut cfg DocConfig) generate_docs_from_file() {
}
time_generated: time.now()
}
}
}
}
dirs := if cfg.is_multi { get_modules_list(cfg.input_path, []string{}) } else { [cfg.input_path] }
for dirpath in dirs {

View File

@ -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]
if path.ends_with('.v') {
vet_file(path, table, prefs)
} else if os.is_dir(path) {
println("vet'ing directory '$path'...")
files := os.walk_ext(path, '.v')
for file in files {
vet_file(file, table, prefs)
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_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 {
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)
}

View File

@ -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()