Skip to content

Commit

Permalink
fmt: fix formatting for imports of submodule from module src dir (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Mar 19, 2024
1 parent a36c693 commit d3d1bc0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions vlib/v/fmt/fmt.v
Expand Up @@ -382,9 +382,15 @@ pub fn (mut f Fmt) imports(imports []ast.Import) {
pub fn (f Fmt) imp_stmt_str(imp ast.Import) string {
normalized_mod := if f.inside_vmodules {
imp.source_name
} else if imp.mod.len == 0 {
imp.alias
} else {
mod := if imp.mod.len == 0 { imp.alias } else { imp.mod }
mod.all_after('src.') // Ignore the 'src.' folder prefix since src/ folder is root of code
mod_last := imp.mod.all_after_last('.')
if imp.source_name == mod_last {
mod_last
} else {
imp.mod
}
}
is_diff := imp.alias != normalized_mod && !normalized_mod.ends_with('.' + imp.alias)
mut imp_alias_suffix := if is_diff { ' as ${imp.alias}' } else { '' }
Expand Down
@@ -0,0 +1 @@
import foo.bar.src.baz

0 comments on commit d3d1bc0

Please sign in to comment.