Skip to content

Commit a36c693

Browse files
authored
fmt: fix autoimport with shebang and comments above other imports (#21050)
1 parent 833da30 commit a36c693

3 files changed

+14
-1
lines changed

vlib/v/fmt/fmt.v

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ pub fn fmt(file ast.File, mut table ast.Table, pref_ &pref.Preferences, is_debug
9898
return res
9999
}
100100
mut import_start_pos := f.import_pos
101-
if stmt := file.stmts[1] {
101+
if f.import_pos == 0 && file.stmts.len > 1 {
102+
stmt := file.stmts[1]
102103
if stmt is ast.ExprStmt && stmt.expr is ast.Comment
103104
&& (stmt.expr as ast.Comment).text.starts_with('#!') {
104105
import_start_pos = stmt.pos.len
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env -S v
2+
3+
// Comment
4+
import json
5+
import os
6+
7+
os.join_path('', '')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env -S v
2+
3+
// Comment
4+
import json
5+
os.join_path('', '')

0 commit comments

Comments
 (0)