From e438b158a636679f816256603b302575198dee6f Mon Sep 17 00:00:00 2001 From: Lukas Neubert Date: Fri, 2 Apr 2021 16:26:53 +0200 Subject: [PATCH] vet: remove false positive space indentation error inside block comments (#9565) --- cmd/tools/vvet/tests/indent_with_space.out | 1 + cmd/tools/vvet/tests/indent_with_space.vv | 10 ++++++++++ vlib/v/parser/parser.v | 11 ++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/cmd/tools/vvet/tests/indent_with_space.out b/cmd/tools/vvet/tests/indent_with_space.out index 9ce1ef4426..c05ca82ccd 100644 --- a/cmd/tools/vvet/tests/indent_with_space.out +++ b/cmd/tools/vvet/tests/indent_with_space.out @@ -1,2 +1,3 @@ cmd/tools/vvet/tests/indent_with_space.vv:2: error: Looks like you are using spaces for indentation. +cmd/tools/vvet/tests/indent_with_space.vv:10: error: Looks like you are using spaces for indentation. NB: You can run `v fmt -w file.v` to fix these errors automatically diff --git a/cmd/tools/vvet/tests/indent_with_space.vv b/cmd/tools/vvet/tests/indent_with_space.vv index c965d2131c..c4419f7156 100644 --- a/cmd/tools/vvet/tests/indent_with_space.vv +++ b/cmd/tools/vvet/tests/indent_with_space.vv @@ -1,3 +1,13 @@ fn main() { _ = 1 == 2 } + +fn block_comments() { + /* tab to indent the comment + spaces before + also spaces before + same here */ + /* spaces for comment indentation (ouch) + and inside too + */ +} diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index f0ad826c50..8cb73ceb42 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -216,8 +216,8 @@ pub fn parse_vet_file(path string, table_ &ast.Table, pref &pref.Preferences) (a } } } - file := p.parse() p.vet_errors << p.scanner.vet_errors + file := p.parse() return file, p.vet_errors } @@ -614,9 +614,14 @@ pub fn (mut p Parser) comment() ast.Comment { text := p.tok.lit pos.last_line = pos.line_nr + text.count('\n') p.next() - // p.next_with_comment() + is_multi := text.contains('\n') + // Filter out space indentation vet errors inside block comments + if p.vet_errors.len > 0 && is_multi { + p.vet_errors = p.vet_errors.filter(!(it.pos.line_nr - 1 > pos.line_nr + && it.pos.line_nr - 1 <= pos.last_line)) + } return ast.Comment{ - is_multi: text.contains('\n') + is_multi: is_multi text: text pos: pos }