question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Formatting is not preserved in imports renamed with =>

See original GitHub issue

If I have the following imports (formatted with spaces.inImportCurlyBraces = true in scalafmt, which adds spaces within the curly braces), and if they are already correctly organized:

import bar.{ Bar => Baz }
import foo.{ Foo1, Foo2 }

then organize-imports preserves the formatting of the second line, but not the first line (the spaces within the curly braces are removed):

import bar.{Bar => Baz}
import foo.{ Foo1, Foo2 }

I have only noticed this in lines where an import is renamed using the => syntax.

This is not a problem in my opinion for formatting code (we just run organize-imports first, and then scalafmt, which makes sense anyway) ; but it’s an issue when checking already formatted code with the -check option, since it detects a difference.

I tested with the following configuration:

OrganizeImports {
  coalesceToWildcardImportThreshold = 50
  expandRelative = false
  groupExplicitlyImportedImplicitsSeparately = false
  groupedImports = Merge
  groups = ["re:javax?\\.", "scala.", "*", "my.app.package"]
  importSelectorsOrder = SymbolsFirst
  importsOrder = SymbolsFirst
  removeUnused = true
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
guilgalycommented, Nov 17, 2020

I can confirm that it also works on my real project. 👍

BTW, I had already tested this tool with a colleague, over the past few weeks, on another project (with different formatting rules, so it didn’t show the same issue) and we’ve been super happy with it. 🙂

0reactions
lianchengcommented, Nov 18, 2020

Thanks for the feedback, I’m closing this one and will prepare for the 0.4.4 release to include this fix.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Excel data doesn't retain formatting in mail merge - Office
In the Microsoft Excel dialog box, under Named or cell range, select the cell range or worksheet that contains the data that you...
Read more >
Add text to frames in InDesign - Adobe Support
Imports Word footnotes. Footnotes and references are preserved, but renumbered based on the document's footnote settings. If the Word footnotes ...
Read more >
liancheng/scalafix-organize-imports: A CI-friendly ... - GitHub
A CI-friendly Scalafix semantic rule for organizing imports - GitHub ... according to the configuration, its original source level format is preserved.
Read more >
Preserve Address Format on Import - Slate Knowledge Base
The Preserve formatting check box is a way to set an address to a quality of 1, so it does not run through...
Read more >
Editing Python in Visual Studio Code
User defined symbols (those not coming from installed packages or libraries) are only automatically imported if they have already been used in files...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found