1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fmt: fix too many \n if file has only imports (#8012)

This commit is contained in:
Lukas Neubert 2021-01-10 20:19:31 +01:00 committed by GitHub
parent a97ed55a09
commit a8378273a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -744,7 +744,7 @@ Cyclic module imports are not allowed, like in Go.
You can also import specific functions and types from modules directly:
```v nofmt
```v
import os { input }
import crypto.sha256 { sum }
import time { Time }

View File

@ -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') }
f.imports(f.file.imports) // now that we have all autoimports, handle them
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)
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')
} else if imports.len > 1 {
*/
// f.out_imports.writeln('import (')
for imp in imports {
if imp.mod !in f.used_imports {
// 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 {
f.out_imports.writeln('')
}
// f.out_imports.writeln(')\n')
// }
}
pub fn (f Fmt) imp_stmt_str(imp ast.Import) string {