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

vet: simplify fn name identifying, add warning for incomplete documentation (#8227)

This commit is contained in:
Larpon 2021-01-21 12:46:50 +01:00 committed by GitHub
parent f399c17e3d
commit ee663364de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 22 deletions

View File

@ -2,3 +2,4 @@ cmd/tools/vvet/tests/module_file_test.vv:7: warning: Function documentation seem
cmd/tools/vvet/tests/module_file_test.vv:13: warning: A function name is missing from the documentation of "pub fn bar() string".
cmd/tools/vvet/tests/module_file_test.vv:35: warning: Function documentation seems to be missing for "pub fn (f Foo) foo() string".
cmd/tools/vvet/tests/module_file_test.vv:46: warning: A function name is missing from the documentation of "pub fn (f Foo) fooo() string".
cmd/tools/vvet/tests/module_file_test.vv:52: warning: The documentation for "pub fn (f Foo) boo() string" seems incomplete.

View File

@ -47,3 +47,9 @@ pub fn (f Foo) fooo() string {
// not using convention
return f.fo()
}
// boo
pub fn (f Foo) boo() string {
// Incomplete doc
return f.fo()
}

View File

@ -172,30 +172,22 @@ fn (mut vet Vet) vet_line(lines []string, line string, lnumber int) {
}
ident_fn_name := fn (line string) string {
mut fn_idx := line.index(' fn ') or { return '' }
mut skip := false
mut p_count := 0
mut fn_name := ''
for i := fn_idx + 4; i < line.len; i++ {
char := line[i]
if !skip && char == `(` {
p_count++
skip = true
continue
} else if skip && char == `)` {
skip = false
continue
} else if char == ` ` {
continue
} else if char.is_letter() {
// fn_name += char.str()
fn_name = line[i..].all_before('(')
break
}
if p_count > 1 {
break
if line.len < fn_idx + 5 {
return ''
}
mut tokens := line[fn_idx + 4..].split(' ')
// Skip struct identifier
if tokens.first().starts_with('(') {
fn_idx = line.index(')') or { return '' }
tokens = line[fn_idx..].split(' ')
if tokens.len > 1 {
tokens = [tokens[1]]
}
}
return fn_name
if tokens.len > 0 {
return tokens[0].all_before('(')
}
return ''
}
mut line_above := lines[lnumber - 1]
mut tags := []string{}
@ -230,6 +222,14 @@ fn (mut vet Vet) vet_line(lines []string, line string, lnumber int) {
} else if prev_line.starts_with('// $fn_name ') {
grab = false
break
} else if prev_line.starts_with('// $fn_name') {
grab = false
if is_pub_fn {
clean_line := line.all_before_last('{').trim(' ')
vet.warn('The documentation for "$clean_line" seems incomplete.',
lnumber, .doc)
}
break
} else if prev_line.starts_with('[') {
tags << collect_tags(prev_line)
continue