parser: filter out vet space indent errors inside StringInterLiterals (#9695)
parent
ada763e0f4
commit
b2c16ced57
|
@ -1,5 +1,6 @@
|
||||||
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: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: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:17: 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.
|
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
|
NB: You can run `v fmt -w file.v` to fix these errors automatically
|
||||||
|
|
|
@ -13,8 +13,12 @@ fn block_comments() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn space_inside_strings() {
|
fn space_inside_strings() {
|
||||||
|
// Plain strings
|
||||||
str := "Bad space usage for variable indentation.
|
str := "Bad space usage for variable indentation.
|
||||||
Here it's fine.
|
Here it's fine.
|
||||||
Here too."
|
Here too."
|
||||||
str2 := 'linebreak and space\n inside'
|
str2 := 'linebreak and space\n inside'
|
||||||
|
// String interpolation
|
||||||
|
si1 := 'Error here $foo
|
||||||
|
and not here'
|
||||||
}
|
}
|
||||||
|
|
|
@ -2322,6 +2322,17 @@ fn (mut p Parser) enum_val() ast.EnumVal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn (mut p Parser) filter_string_vet_errors(pos token.Position) {
|
||||||
|
if p.vet_errors.len == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
p.vet_errors = p.vet_errors.filter(
|
||||||
|
(it.typ == .trailing_space && it.pos.line_nr - 1 >= pos.last_line)
|
||||||
|
|| (it.typ != .trailing_space && it.pos.line_nr - 1 > pos.last_line)
|
||||||
|
|| (it.typ == .space_indent && it.pos.line_nr - 1 <= pos.line_nr)
|
||||||
|
|| (it.typ != .space_indent && it.pos.line_nr - 1 < pos.line_nr))
|
||||||
|
}
|
||||||
|
|
||||||
fn (mut p Parser) string_expr() ast.Expr {
|
fn (mut p Parser) string_expr() ast.Expr {
|
||||||
is_raw := p.tok.kind == .name && p.tok.lit == 'r'
|
is_raw := p.tok.kind == .name && p.tok.lit == 'r'
|
||||||
is_cstr := p.tok.kind == .name && p.tok.lit == 'c'
|
is_cstr := p.tok.kind == .name && p.tok.lit == 'c'
|
||||||
|
@ -2334,14 +2345,7 @@ fn (mut p Parser) string_expr() ast.Expr {
|
||||||
pos.last_line = pos.line_nr + val.count('\n')
|
pos.last_line = pos.line_nr + val.count('\n')
|
||||||
if p.peek_tok.kind != .str_dollar {
|
if p.peek_tok.kind != .str_dollar {
|
||||||
p.next()
|
p.next()
|
||||||
// Filter out false positive vet errors inside strings
|
p.filter_string_vet_errors(pos)
|
||||||
if p.vet_errors.len > 0 {
|
|
||||||
p.vet_errors = p.vet_errors.filter(
|
|
||||||
(it.typ == .trailing_space && it.pos.line_nr - 1 >= pos.last_line)
|
|
||||||
|| (it.typ != .trailing_space && it.pos.line_nr - 1 > pos.last_line)
|
|
||||||
|| (it.typ == .space_indent && it.pos.line_nr - 1 <= pos.line_nr)
|
|
||||||
|| (it.typ != .space_indent && it.pos.line_nr - 1 < pos.line_nr))
|
|
||||||
}
|
|
||||||
node = ast.StringLiteral{
|
node = ast.StringLiteral{
|
||||||
val: val
|
val: val
|
||||||
is_raw: is_raw
|
is_raw: is_raw
|
||||||
|
@ -2420,6 +2424,8 @@ fn (mut p Parser) string_expr() ast.Expr {
|
||||||
fills << fill
|
fills << fill
|
||||||
fposs << p.prev_tok.position()
|
fposs << p.prev_tok.position()
|
||||||
}
|
}
|
||||||
|
pos = pos.extend(p.prev_tok.position())
|
||||||
|
p.filter_string_vet_errors(pos)
|
||||||
node = ast.StringInterLiteral{
|
node = ast.StringInterLiteral{
|
||||||
vals: vals
|
vals: vals
|
||||||
exprs: exprs
|
exprs: exprs
|
||||||
|
@ -2430,7 +2436,7 @@ fn (mut p Parser) string_expr() ast.Expr {
|
||||||
fills: fills
|
fills: fills
|
||||||
fmts: fmts
|
fmts: fmts
|
||||||
fmt_poss: fposs
|
fmt_poss: fposs
|
||||||
pos: pos.extend(p.prev_tok.position())
|
pos: pos
|
||||||
}
|
}
|
||||||
// need_fmts: prelimery - until checker finds out if really needed
|
// need_fmts: prelimery - until checker finds out if really needed
|
||||||
p.inside_str_interp = false
|
p.inside_str_interp = false
|
||||||
|
|
|
@ -1094,9 +1094,12 @@ fn (mut s Scanner) ident_string() string {
|
||||||
// }
|
// }
|
||||||
mut n_cr_chars := 0
|
mut n_cr_chars := 0
|
||||||
mut start := s.pos
|
mut start := s.pos
|
||||||
if s.text[start] == s.quote
|
start_char := s.text[start]
|
||||||
|| (s.text[start] == s.inter_quote && (s.is_inter_start || s.is_enclosed_inter)) {
|
if start_char == s.quote
|
||||||
|
|| (start_char == s.inter_quote && (s.is_inter_start || s.is_enclosed_inter)) {
|
||||||
start++
|
start++
|
||||||
|
} else if start_char == `\n` {
|
||||||
|
s.inc_line_number()
|
||||||
}
|
}
|
||||||
s.is_inside_string = false
|
s.is_inside_string = false
|
||||||
mut u_escapes_pos := []int{} // pos list of \uXXXX
|
mut u_escapes_pos := []int{} // pos list of \uXXXX
|
||||||
|
|
Loading…
Reference in New Issue