fmt: fix too many \n if file has only imports (#8012)
parent
a97ed55a09
commit
a8378273a5
|
@ -744,7 +744,7 @@ Cyclic module imports are not allowed, like in Go.
|
||||||
|
|
||||||
You can also import specific functions and types from modules directly:
|
You can also import specific functions and types from modules directly:
|
||||||
|
|
||||||
```v nofmt
|
```v
|
||||||
import os { input }
|
import os { input }
|
||||||
import crypto.sha256 { sum }
|
import crypto.sha256 { sum }
|
||||||
import time { Time }
|
import time { Time }
|
||||||
|
|
|
@ -72,6 +72,9 @@ pub fn fmt(file ast.File, table &table.Table, is_debug bool) string {
|
||||||
// for comment in file.comments { println('$comment.line_nr $comment.text') }
|
// for comment in file.comments { println('$comment.line_nr $comment.text') }
|
||||||
f.imports(f.file.imports) // now that we have all autoimports, handle them
|
f.imports(f.file.imports) // now that we have all autoimports, handle them
|
||||||
res := f.out.str().trim_space() + '\n'
|
res := f.out.str().trim_space() + '\n'
|
||||||
|
if res.len == 1 {
|
||||||
|
return f.out_imports.str().trim_space() + '\n'
|
||||||
|
}
|
||||||
bounded_import_pos := util.imin(res.len, f.import_pos)
|
bounded_import_pos := util.imin(res.len, f.import_pos)
|
||||||
return res[..bounded_import_pos] + f.out_imports.str() + res[bounded_import_pos..] // + '\n'
|
return res[..bounded_import_pos] + f.out_imports.str() + res[bounded_import_pos..] // + '\n'
|
||||||
}
|
}
|
||||||
|
@ -211,7 +214,6 @@ pub fn (mut f Fmt) imports(imports []ast.Import) {
|
||||||
f.out_imports.writeln('import ${imp_stmt_str}\n')
|
f.out_imports.writeln('import ${imp_stmt_str}\n')
|
||||||
} else if imports.len > 1 {
|
} else if imports.len > 1 {
|
||||||
*/
|
*/
|
||||||
// f.out_imports.writeln('import (')
|
|
||||||
for imp in imports {
|
for imp in imports {
|
||||||
if imp.mod !in f.used_imports {
|
if imp.mod !in f.used_imports {
|
||||||
// TODO bring back once only unused imports are removed
|
// TODO bring back once only unused imports are removed
|
||||||
|
@ -227,8 +229,6 @@ pub fn (mut f Fmt) imports(imports []ast.Import) {
|
||||||
if num_imports > 0 {
|
if num_imports > 0 {
|
||||||
f.out_imports.writeln('')
|
f.out_imports.writeln('')
|
||||||
}
|
}
|
||||||
// f.out_imports.writeln(')\n')
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (f Fmt) imp_stmt_str(imp ast.Import) string {
|
pub fn (f Fmt) imp_stmt_str(imp ast.Import) string {
|
||||||
|
|
Loading…
Reference in New Issue