From 094441c8635cfe83f1c2cc45cd52ec77899c64c7 Mon Sep 17 00:00:00 2001 From: Lukas Neubert Date: Sat, 3 Apr 2021 12:16:49 +0200 Subject: [PATCH] vet: remove false positive space indent errors inside strings (#9568) --- cmd/tools/vvet/tests/indent_with_space.out | 2 ++ cmd/tools/vvet/tests/indent_with_space.vv | 19 +++++++++++++------ vlib/v/parser/parser.v | 7 ++++++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/cmd/tools/vvet/tests/indent_with_space.out b/cmd/tools/vvet/tests/indent_with_space.out index c05ca82ccd..7db901faca 100644 --- a/cmd/tools/vvet/tests/indent_with_space.out +++ b/cmd/tools/vvet/tests/indent_with_space.out @@ -1,3 +1,5 @@ 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. +cmd/tools/vvet/tests/indent_with_space.vv:16: error: Looks like you are using spaces for indentation. +cmd/tools/vvet/tests/indent_with_space.vv:19: 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 c4419f7156..c392568e49 100644 --- a/cmd/tools/vvet/tests/indent_with_space.vv +++ b/cmd/tools/vvet/tests/indent_with_space.vv @@ -4,10 +4,17 @@ fn main() { fn block_comments() { /* tab to indent the comment - spaces before - also spaces before - same here */ - /* spaces for comment indentation (ouch) - and inside too - */ + spaces before + also spaces before + same here */ + /* spaces for comment indentation (ouch) + and inside too + */ +} + +fn space_inside_strings() { + str := "Bad space usage for variable indentation. + Here it's fine. + Here too." + str2 := 'linebreak and space\n inside' } diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 9d266dcd43..e365d80ae1 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -2330,9 +2330,14 @@ fn (mut p Parser) string_expr() ast.Expr { } mut node := ast.empty_expr() val := p.tok.lit - pos := p.tok.position() + mut pos := p.tok.position() + pos.last_line = pos.line_nr + val.count('\n') if p.peek_tok.kind != .str_dollar { p.next() + if p.vet_errors.len > 0 && val.contains('\n ') { + p.vet_errors = p.vet_errors.filter(!(it.pos.line_nr > pos.line_nr - 1 + && it.pos.line_nr <= pos.last_line - 1)) + } node = ast.StringLiteral{ val: val is_raw: is_raw