Skip to content

Commit 000b416

Browse files
authored
fmt: fix comment line number in file with crlf line separator (fix #23524) (#25163)
1 parent be31491 commit 000b416

4 files changed

Lines changed: 29 additions & 3 deletions

File tree

‎vlib/v/fmt/tests/.gitattributes‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*_crlf_* binary
2+
*_lf_* binary
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module main
2+
3+
fn main() {
4+
// vfmt off
5+
a := [
6+
1, 2, 3,
7+
4, 5, 6,
8+
]
9+
// vfmt on
10+
11+
println('Hello World!')
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module main
2+
3+
fn main() {
4+
// vfmt off
5+
a := [
6+
1, 2, 3,
7+
4, 5, 6,
8+
]
9+
// vfmt on
10+
11+
println('Hello World!')
12+
}

‎vlib/v/scanner/scanner.v‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,11 +1068,11 @@ pub fn (mut s Scanner) text_scan() token.Token {
10681068
mut comment_line_end := s.pos
10691069
if s.text[s.pos - 1] == b_cr {
10701070
comment_line_end--
1071-
} else {
1072-
// fix line_nr, \n was read; the comment is marked on the next line
10731071
s.pos--
1074-
s.line_nr--
10751072
}
1073+
// fix line_nr, \n was read; the comment is marked on the next line
1074+
s.pos--
1075+
s.line_nr--
10761076
if s.should_parse_comment() {
10771077
s.line_comment = s.text[start + 1..comment_line_end]
10781078
mut comment := s.line_comment

0 commit comments

Comments
 (0)