From ee663364de79eeb5a0421949d242075c2ba8d31b Mon Sep 17 00:00:00 2001 From: Larpon Date: Thu, 21 Jan 2021 12:46:50 +0100 Subject: [PATCH] vet: simplify fn name identifying, add warning for incomplete documentation (#8227) --- cmd/tools/vvet/tests/module_file_test.out | 1 + cmd/tools/vvet/tests/module_file_test.vv | 6 ++++ cmd/tools/vvet/vvet.v | 44 +++++++++++------------ 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/cmd/tools/vvet/tests/module_file_test.out b/cmd/tools/vvet/tests/module_file_test.out index 2c863adce1..b033e715f0 100644 --- a/cmd/tools/vvet/tests/module_file_test.out +++ b/cmd/tools/vvet/tests/module_file_test.out @@ -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. \ No newline at end of file diff --git a/cmd/tools/vvet/tests/module_file_test.vv b/cmd/tools/vvet/tests/module_file_test.vv index fe613263b7..f0f5b24057 100644 --- a/cmd/tools/vvet/tests/module_file_test.vv +++ b/cmd/tools/vvet/tests/module_file_test.vv @@ -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() +} diff --git a/cmd/tools/vvet/vvet.v b/cmd/tools/vvet/vvet.v index 45ed5a3256..557a4420a9 100644 --- a/cmd/tools/vvet/vvet.v +++ b/cmd/tools/vvet/vvet.v @@ -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