vet: simplify fn name identifying, add warning for incomplete documentation (#8227)
parent
f399c17e3d
commit
ee663364de
|
@ -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: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: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: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.
|
|
@ -47,3 +47,9 @@ pub fn (f Foo) fooo() string {
|
||||||
// not using convention
|
// not using convention
|
||||||
return f.fo()
|
return f.fo()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// boo
|
||||||
|
pub fn (f Foo) boo() string {
|
||||||
|
// Incomplete doc
|
||||||
|
return f.fo()
|
||||||
|
}
|
||||||
|
|
|
@ -172,30 +172,22 @@ fn (mut vet Vet) vet_line(lines []string, line string, lnumber int) {
|
||||||
}
|
}
|
||||||
ident_fn_name := fn (line string) string {
|
ident_fn_name := fn (line string) string {
|
||||||
mut fn_idx := line.index(' fn ') or { return '' }
|
mut fn_idx := line.index(' fn ') or { return '' }
|
||||||
mut skip := false
|
if line.len < fn_idx + 5 {
|
||||||
mut p_count := 0
|
return ''
|
||||||
mut fn_name := ''
|
}
|
||||||
for i := fn_idx + 4; i < line.len; i++ {
|
mut tokens := line[fn_idx + 4..].split(' ')
|
||||||
char := line[i]
|
// Skip struct identifier
|
||||||
if !skip && char == `(` {
|
if tokens.first().starts_with('(') {
|
||||||
p_count++
|
fn_idx = line.index(')') or { return '' }
|
||||||
skip = true
|
tokens = line[fn_idx..].split(' ')
|
||||||
continue
|
if tokens.len > 1 {
|
||||||
} else if skip && char == `)` {
|
tokens = [tokens[1]]
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fn_name
|
if tokens.len > 0 {
|
||||||
|
return tokens[0].all_before('(')
|
||||||
|
}
|
||||||
|
return ''
|
||||||
}
|
}
|
||||||
mut line_above := lines[lnumber - 1]
|
mut line_above := lines[lnumber - 1]
|
||||||
mut tags := []string{}
|
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 ') {
|
} else if prev_line.starts_with('// $fn_name ') {
|
||||||
grab = false
|
grab = false
|
||||||
break
|
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('[') {
|
} else if prev_line.starts_with('[') {
|
||||||
tags << collect_tags(prev_line)
|
tags << collect_tags(prev_line)
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in New Issue