Open cvogt opened 7 years ago
This would be a really nice rewrite to have. However, it's a tricky one since
Importee.Wildcard.symbol
is currently a ???
, see https://github.com/scalameta/scalameta/issues/925Assuming we fix those issues, it should be possible to implement a def usedSymbol(Importee.Wildcard): Seq[Symbol]
method that can be used to produce a patch. I'm happy to give more pointers if someone is interested.
Example diff produced by this rule
- import com.foo._
+ import com.foo.{A, B}
assuming that only com.foo.{A,B}
are the only symbols used from the wildcard import. This is blocked by https://github.com/scalameta/scalameta/issues/1075
What would be the rewrite strategy for this?
We don't have the available data in semanticdb to resolve which symbols are imported from the wildcard.
And that would be #1075? Isn't that issue closed?
I just reopened the issue with a more detailed motivation
A quick update: synthetics now have attached symbols, which means scalafix knows symbols that are used by implicits. We also visit both macro expandees and expanders, however we could miss some used symbols in pathological cases, causing some symbols to be missing from the expanded wildcard import. I'm happy to give more pointers if someone is motivated to give this a try :)
This is a good idea. This should be significantly simpler now thanks to the new synthetics introduced in https://github.com/scalacenter/scalafix/pull/828. After the PR https://github.com/scalacenter/scalafix/pull/827, we are moving most built-in rules outside of the scalacenter/scalafix repository so that they can evolve at a different pace than Scalafix APIs. As long as a custom rule meets a certain level of quality, it can still
Ping us on Gitter if you believe your rule is good enough for inclusion. Don't hesitate to ask for help around code review or general guidance on writing/sharing custom rules.
Any progress so far?
Would be nice to expand wildcard imports into fully qualified imports.
Hey @olafurpg... is it available as a ready rule in Scalafix already? or at least more easily doable? 🤔
I don't think this was ever worked on, it would require some time put into it. Most blockers should be resolved aside from macro issue perhaps?
This clearly falls under the scope of OrganizeImports
, which is now a built-in rule, so I am re-opening that. Not because there is active work planned on it, but because it should probably be done as a PR here if someone is willing to try.
The behavior could honor coalesceToWildcardImportThreshold
to avoid expanding too many qualified imports.
not sure how easy that is