Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organize imports #46

Merged
merged 2 commits into from
Jan 28, 2017
Merged

Organize imports #46

merged 2 commits into from
Jan 28, 2017

Conversation

olafurpg
Copy link
Contributor

No description provided.

Main changes:

- Patch(from, to, replace) replaced with TokenPatch(token, newToken)
  with helpful combinators such as Add{Left,Right}
- New high-level TreePatch datatype with can be converted to TokenPatch.
- Implemented two tree patches, AddGlobalImport and RemoveGlobalImport.
- Implemented OrganizeImport, which is a prerequisite to use import tree
  patches.
- OrganizeImports
  - orders imports by configurable groups
  - removes unused imports using scalac -Ywarn-unused-import
    infrastructure. The implementation is requires hijacking a few
    private fields in g.analyzer using evil reflection hackery.
  - option to expand relative imports
  - handles renames
  - configurable "always used" to force keeping an import such as
    acyclic.file

Known bugs:

- introduces false import on non-existing cats.data.UUID in circe
- makes an import unused by expanding relative imports to
  fully-qualified imports, requiring you to run scalafix
  twice to fully remove unused imports (e.g. in cats with
  -Ywarn-unused-import)
- crashes on scala.meta parser bug (in akka), not scalafix problem
  really.

Expand relative

Test that patch is unchanged
@olafurpg
Copy link
Contributor Author

Organize imports is still a work-in-progress, main issues are

  • running it on cats/circe/akka fails/crashes
  • little documentation on how to use new tree patches

I'm still gonna go ahead and merge this now so those who want to experiment with this new API don't have to work off a fork branch.

@olafurpg olafurpg merged commit d8a926f into scalacenter:master Jan 28, 2017
@olafurpg olafurpg deleted the organize-imports branch January 28, 2017 08:19
@mwz mwz mentioned this pull request Jun 29, 2019
bjaglin pushed a commit to liancheng/scalafix that referenced this pull request May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant