fmt: sort names in selective imports (#8827)
parent
5e1159e4c3
commit
f381836f9e
|
@ -262,6 +262,7 @@ pub fn (mut f Fmt) imports(imports []ast.Import) {
|
||||||
f.did_imports = true
|
f.did_imports = true
|
||||||
mut num_imports := 0
|
mut num_imports := 0
|
||||||
mut already_imported := map[string]bool{}
|
mut already_imported := map[string]bool{}
|
||||||
|
|
||||||
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
|
||||||
|
@ -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)
|
is_diff := imp.alias != imp.mod && !imp.mod.ends_with('.' + imp.alias)
|
||||||
mut imp_alias_suffix := if is_diff { ' as $imp.alias' } else { '' }
|
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 {
|
if syms.len > 0 {
|
||||||
imp_alias_suffix += if imp.syms[0].pos.line_nr == imp.pos.line_nr {
|
imp_alias_suffix += if imp.syms[0].pos.line_nr == imp.pos.line_nr {
|
||||||
' { ' + syms.join(', ') + ' }'
|
' { ' + syms.join(', ') + ' }'
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import math { max, min }
|
import math { max, min }
|
||||||
import cli { Command }
|
import cli { Command }
|
||||||
import math.complex { complex, Complex }
|
import math.complex { Complex, complex }
|
||||||
import os {
|
import os {
|
||||||
user_os,
|
|
||||||
file_ext,
|
file_ext,
|
||||||
|
user_os,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct App {
|
struct App {
|
||||||
|
|
Loading…
Reference in New Issue