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.

[Feature Idea] Default to wildcard if too many merged imports

See original GitHub issue

If I have a number of qualified imports sharing a package name, such as below:

import cats.data.AndThen
import cats.data.Binested
import cats.data.BinestedBitraverse 
import cats.data.Kleisli
import cats.data.Reader
import cats.data.OptionT
import cats.data.State
import cats.data.StateT

The optimizer under the Merge configuration (rightly) groups them all together:

import cats.data.{AndThen, Binested, BinestedBitraverse, Kleisli, OptionT, Reader, State, StateT}

However at some point the number of things imported from the same package can be so large that the merge grouping will go over the column limit. Of course, Scalafmt can catch this and turn it into this:

import cats.data.{
  AndThen,
  Binested,
  BinestedBitraverse,
  Kleisli,
  Reader,
  OptionT,
  State,
  StateT
}

But why not have an option to simplify to a wildcard like below? It’s much cleaner, albeit less precise w.r.t scope.

import cats.data._

So the feature idea I’m proposing is to add a configuration to the groupedImports rule such as SmartMerge which will default to a wildcard if the merged group goes over the standard column limit (100 chars?).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lianchengcommented, Apr 24, 2020

BTW, the reason why the groupedImports option defaults to Explode is that having each import selector on their own line as a fully-qualified import is friendlier to version control and text searching. I personally prefer not grouping them together. It also avoids exceeding the column limit.

0reactions
nasadoriancommented, May 4, 2020

Awesome, thanks for the update @liancheng! Gonna take it for a spin in one of my repos.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IntelliJ: Never use wildcard imports - Stack Overflow
Update: in IDEA 13 "Use single class import" does not prevent wildcard imports. The solution is to go to Preferences ( ⌘ +...
Read more >
Auto import | IntelliJ IDEA Documentation - JetBrains
Disable wildcard imports. When the number of classes that IntelliJ IDEA has imported from the same package reaches the limit ( ...
Read more >
Wildcard imports · Issue #48 · pinterest/ktlint - GitHub
My primary argument is that intellij does add wildcard imports in the default configuration, and I think I should not have to configure ......
Read more >
How to disable wildcard imports in IntelliJ IDEA - Marc Nuri
IntelliJ IDEA uses wildcard imports ( import java. util. *; ) whenever the number of classes imported from the same package reaches the...
Read more >
Why you should disable wildcard imports in IntelliJ IDEA
The default behavior of IntelliJ IDEA is to replace multiple class imports from a package with an asterisk. At my team, we decided...
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