1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

tools: support --exclude/-e and --relative-paths/-r options in missdoc.v

This commit is contained in:
Delyan Angelov 2022-02-08 11:10:19 +02:00
parent f0806822dd
commit ff02f94fd6
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -8,6 +8,7 @@ const (
tool_name = os.file_name(os.executable())
tool_version = '0.0.3'
tool_description = 'Prints all V functions in .v files under PATH/, that do not yet have documentation comments.'
work_dir_prefix = normalise_path(os.real_path(os.wd_at_startup) + '/')
)
struct UndocumentedFN {
@ -23,44 +24,34 @@ struct Options {
private bool
js bool
no_line_numbers bool
exclude []string
relative_paths bool
}
fn collect(path string, mut l []string, f fn (string, mut []string)) {
if !os.is_dir(path) {
return
}
mut files := os.ls(path) or { return }
for file in files {
p := path + os.path_separator + file
if os.is_dir(p) && !os.is_link(p) {
collect(p, mut l, f)
} else if os.exists(p) {
f(p, mut l)
}
}
return
}
fn report_undocumented_functions_in_path(opt Options, path string) {
fn (opt Options) report_undocumented_functions_in_path(path string) {
mut files := []string{}
collect_fn := fn (path string, mut l []string) {
if os.file_ext(path) == '.v' {
l << os.real_path(path)
collect(path, mut files, fn (npath string, mut accumulated_paths []string) {
if !npath.ends_with('.v') {
return
}
}
collect(path, mut files, collect_fn)
if npath.ends_with('_test.v') {
return
}
accumulated_paths << npath
})
for file in files {
if file.ends_with('_test.v') {
continue
}
if !opt.js && file.ends_with('.js.v') {
continue
}
report_undocumented_functions_in_file(opt, file)
if opt.exclude.len > 0 && opt.exclude.any(file.contains(it)) {
continue
}
opt.report_undocumented_functions_in_file(file)
}
}
fn report_undocumented_functions_in_file(opt Options, file string) {
fn (opt &Options) report_undocumented_functions_in_file(nfile string) {
file := os.real_path(nfile)
contents := os.read_file(file) or { panic(err) }
lines := contents.split('\n')
mut info := []UndocumentedFN{}
@ -104,17 +95,42 @@ fn report_undocumented_functions_in_file(opt Options, file string) {
} else {
''
}
ofile := if opt.relative_paths {
nfile.replace(work_dir_prefix, '')
} else {
os.real_path(nfile)
}
if opt.deprecated {
println('$file:$line_numbers$undocumented_fn.signature $tags_str')
println('$ofile:$line_numbers$undocumented_fn.signature $tags_str')
} else {
if 'deprecated' !in undocumented_fn.tags {
println('$file:$line_numbers$undocumented_fn.signature $tags_str')
println('$ofile:$line_numbers$undocumented_fn.signature $tags_str')
}
}
}
}
}
fn normalise_path(path string) string {
return path.replace('\\', '/')
}
fn collect(path string, mut l []string, f fn (string, mut []string)) {
if !os.is_dir(path) {
return
}
mut files := os.ls(path) or { return }
for file in files {
p := normalise_path(os.join_path_single(path, file))
if os.is_dir(p) && !os.is_link(p) {
collect(p, mut l, f)
} else if os.exists(p) {
f(p, mut l)
}
}
return
}
fn collect_tags(line string) []string {
mut cleaned := line.all_before('/')
cleaned = cleaned.replace_each(['[', '', ']', '', ' ', ''])
@ -137,18 +153,21 @@ fn main() {
deprecated: fp.bool('deprecated', `d`, false, 'Include deprecated functions in output.')
private: fp.bool('private', `p`, false, 'Include private functions in output.')
js: fp.bool('js', 0, false, 'Include JavaScript functions in output.')
no_line_numbers: fp.bool('no-line-numbers', 0, false, 'Exclude line numbers in output.')
no_line_numbers: fp.bool('no-line-numbers', `n`, false, 'Exclude line numbers in output.')
collect_tags: fp.bool('tags', `t`, false, 'Also print function tags if any is found.')
exclude: fp.string_multi('exclude', `e`, '')
relative_paths: fp.bool('relative-paths', `r`, false, 'Use relative paths in output.')
}
dump(opt)
if opt.show_help {
println(fp.usage())
exit(0)
}
for path in os.args[1..] {
if os.is_file(path) {
report_undocumented_functions_in_file(opt, path)
opt.report_undocumented_functions_in_file(path)
} else {
report_undocumented_functions_in_path(opt, path)
opt.report_undocumented_functions_in_path(path)
}
}
}