fmt: sort names in selective imports (#8827)

pull/8857/head
zakuro 2021-02-20 20:22:09 +09:00 committed by GitHub
parent 5e1159e4c3
commit f381836f9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -262,6 +262,7 @@ pub fn (mut f Fmt) imports(imports []ast.Import) {
f.did_imports = true
mut num_imports := 0
mut already_imported := map[string]bool{}
for imp in imports {
if imp.mod !in f.used_imports {
// TODO bring back once only unused imports are removed
@ -289,7 +290,8 @@ pub fn (f Fmt) imp_stmt_str(imp ast.Import) string {
is_diff := imp.alias != imp.mod && !imp.mod.ends_with('.' + imp.alias)
mut imp_alias_suffix := if is_diff { ' as $imp.alias' } else { '' }
syms := imp.syms.map(it.name).filter(f.import_syms_used[it])
mut syms := imp.syms.map(it.name).filter(f.import_syms_used[it])
syms.sort()
if syms.len > 0 {
imp_alias_suffix += if imp.syms[0].pos.line_nr == imp.pos.line_nr {
' { ' + syms.join(', ') + ' }'

View File

@ -1,9 +1,9 @@
import math { max, min }
import cli { Command }
import math.complex { complex, Complex }
import math.complex { Complex, complex }
import os {
user_os,
file_ext,
user_os,
}
struct App {