From f1b35aff220015d4565021669c4016b7add029c2 Mon Sep 17 00:00:00 2001 From: Larpon Date: Mon, 16 May 2022 11:24:21 +0200 Subject: [PATCH] vvet: fix false positive, add test (#14403) --- cmd/tools/vtest-self.v | 3 +++ cmd/tools/vvet/tests/array_init_one_val.out | 2 +- cmd/tools/vvet/tests/indent_with_space.out | 2 +- cmd/tools/vvet/tests/no_warn_about_missing.out | 0 cmd/tools/vvet/tests/no_warn_about_missing.vv | 6 ++++++ cmd/tools/vvet/tests/parens_space_a.out | 2 +- cmd/tools/vvet/tests/parens_space_b.out | 2 +- cmd/tools/vvet/vvet.v | 6 +++++- 8 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 cmd/tools/vvet/tests/no_warn_about_missing.out create mode 100644 cmd/tools/vvet/tests/no_warn_about_missing.vv diff --git a/cmd/tools/vtest-self.v b/cmd/tools/vtest-self.v index 9a6dd83229..183dec0759 100644 --- a/cmd/tools/vtest-self.v +++ b/cmd/tools/vtest-self.v @@ -8,6 +8,8 @@ const github_job = os.getenv('GITHUB_JOB') const ( skip_test_files = [ + 'cmd/tools/vdoc/html_tag_escape_test.v', /* can't locate local module: markdown */ + 'cmd/tools/vdoc/tests/vdoc_file_test.v', /* fails on Windows; order of output is not as expected */ 'vlib/context/onecontext/onecontext_test.v', 'vlib/context/deadline_test.v' /* sometimes blocks */, 'vlib/mysql/mysql_orm_test.v' /* mysql not installed */, @@ -164,6 +166,7 @@ fn main() { cmd_prefix := args_string.all_before('test-self') title := 'testing vlib' mut all_test_files := os.walk_ext(os.join_path(vroot, 'vlib'), '_test.v') + all_test_files << os.walk_ext(os.join_path(vroot, 'cmd'), '_test.v') test_js_files := os.walk_ext(os.join_path(vroot, 'vlib'), '_test.js.v') all_test_files << test_js_files testing.eheader(title) diff --git a/cmd/tools/vvet/tests/array_init_one_val.out b/cmd/tools/vvet/tests/array_init_one_val.out index e10d5119b8..42bcd163b4 100644 --- a/cmd/tools/vvet/tests/array_init_one_val.out +++ b/cmd/tools/vvet/tests/array_init_one_val.out @@ -1,2 +1,2 @@ cmd/tools/vvet/tests/array_init_one_val.vv:2: error: Use `var == value` instead of `var in [value]` -NB: You can run `v fmt -w file.v` to fix these errors automatically +Note: You can run `v fmt -w file.v` to fix these errors automatically diff --git a/cmd/tools/vvet/tests/indent_with_space.out b/cmd/tools/vvet/tests/indent_with_space.out index b307e208f2..15a1a15263 100644 --- a/cmd/tools/vvet/tests/indent_with_space.out +++ b/cmd/tools/vvet/tests/indent_with_space.out @@ -3,4 +3,4 @@ cmd/tools/vvet/tests/indent_with_space.vv:10: error: Looks like you are using sp cmd/tools/vvet/tests/indent_with_space.vv:17: error: Looks like you are using spaces for indentation. cmd/tools/vvet/tests/indent_with_space.vv:20: error: Looks like you are using spaces for indentation. cmd/tools/vvet/tests/indent_with_space.vv:22: error: Looks like you are using spaces for indentation. -NB: You can run `v fmt -w file.v` to fix these errors automatically +Note: You can run `v fmt -w file.v` to fix these errors automatically diff --git a/cmd/tools/vvet/tests/no_warn_about_missing.out b/cmd/tools/vvet/tests/no_warn_about_missing.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/cmd/tools/vvet/tests/no_warn_about_missing.vv b/cmd/tools/vvet/tests/no_warn_about_missing.vv new file mode 100644 index 0000000000..805c025a4c --- /dev/null +++ b/cmd/tools/vvet/tests/no_warn_about_missing.vv @@ -0,0 +1,6 @@ +// Some header comment + +// read_response is a carefully constructed comment. +// read_response_body. <-- this would earlier trigger a false +// postive. +pub fn read_response() ?(string, string) {} diff --git a/cmd/tools/vvet/tests/parens_space_a.out b/cmd/tools/vvet/tests/parens_space_a.out index dbda99add0..80188115be 100644 --- a/cmd/tools/vvet/tests/parens_space_a.out +++ b/cmd/tools/vvet/tests/parens_space_a.out @@ -1,2 +1,2 @@ cmd/tools/vvet/tests/parens_space_a.vv:1: error: Looks like you are adding a space after `(` -NB: You can run `v fmt -w file.v` to fix these errors automatically +Note: You can run `v fmt -w file.v` to fix these errors automatically diff --git a/cmd/tools/vvet/tests/parens_space_b.out b/cmd/tools/vvet/tests/parens_space_b.out index d1d879158c..2a277e115c 100644 --- a/cmd/tools/vvet/tests/parens_space_b.out +++ b/cmd/tools/vvet/tests/parens_space_b.out @@ -1,2 +1,2 @@ cmd/tools/vvet/tests/parens_space_b.vv:1: error: Looks like you are adding a space before `)` -NB: You can run `v fmt -w file.v` to fix these errors automatically +Note: You can run `v fmt -w file.v` to fix these errors automatically diff --git a/cmd/tools/vvet/vvet.v b/cmd/tools/vvet/vvet.v index 1b9cc3f9b9..7004e4282e 100644 --- a/cmd/tools/vvet/vvet.v +++ b/cmd/tools/vvet/vvet.v @@ -182,13 +182,17 @@ fn (mut vt Vet) vet_fn_documentation(lines []string, line string, lnumber int) { fn_name := ident_fn_name(line) mut grab := true for j := lnumber - 1; j >= 0; j-- { + mut prev_prev_line := '' + if j - 1 >= 0 { + prev_prev_line = lines[j - 1] + } prev_line := lines[j] if prev_line.contains('}') { // We've looked back to the above scope, stop here break } else if prev_line.starts_with('// $fn_name ') { grab = false break - } else if prev_line.starts_with('// $fn_name') { + } else if prev_line.starts_with('// $fn_name') && !prev_prev_line.starts_with('//') { grab = false clean_line := line.all_before_last('{').trim(' ') vt.warn('The documentation for "$clean_line" seems incomplete.', lnumber,