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

Import jumps on to comment line when there is a comment #26

Open
ckipp01 opened this issue Jan 2, 2020 · 10 comments
Open

Import jumps on to comment line when there is a comment #26

ckipp01 opened this issue Jan 2, 2020 · 10 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@ckipp01
Copy link

ckipp01 commented Jan 2, 2020

Given the following code block, if you run scalafix it will cause the second import to jump up a line resulting in it being commented out.

import java.time.Period
// import this here
import java.time.Instant

object hello extends App {

  val x: Instant = Instant.now()
  val y: Period = Period.ZERO

}

It will become this:

import java.time.Period
// import this hereimport java.time.Instant

object hello extends App {

  val x: Instant = Instant.now()
  val y: Period = Period.ZERO

}
@NeQuissimus
Copy link
Owner

This is funny, I was literally trying to reproduce something like this from memory the other day but had no luck.
I have indeed encountered this before.
It is likely due to SortImport not working on comments at all.

PRs welcome, otherwise I will get around to it whenever I have some free time.

@NeQuissimus NeQuissimus added bug Something isn't working good first issue Good for newcomers labels Jan 2, 2020
@ckipp01
Copy link
Author

ckipp01 commented Jan 2, 2020

Sounds good! If I get a moment I'll take a look to see if it's something clear to me and easy to fix.

@He-Pin
Copy link

He-Pin commented Mar 22, 2020

image
was fixed into

    // need implicit system for dilated    import context.system

@He-Pin
Copy link

He-Pin commented Mar 22, 2020

@NeQuissimus
Try akka.actor.FSMTimingSpec

@He-Pin
Copy link

He-Pin commented Mar 22, 2020

image

@He-Pin
Copy link

He-Pin commented Mar 22, 2020

Change src/main/scala/fix/commented.scala to

/*
rule = SortImports
 SortImports.blocks = [
 "java",
 "scala",
 "*",
 "com.sun"
 ]
 */
import scala.util._ // foobar
import scala.collection._
import java.util.Map
import com.oracle.net._
import com.sun.awt._
import java.math.BigInteger

/**
 *  Bla
 */
object Bla {
  val foo = "Hello" // World

  //comment between 1
  import java.util.fucntion._
  //comment between 2
  import java.concurrent._
}

can produce this
@NeQuissimus

@He-Pin
Copy link

He-Pin commented Mar 22, 2020

@NeQuissimus you can check out https://github.com/akka/akka/pull/28780 and run sortImports to reproduce.

@ckipp01
Copy link
Author

ckipp01 commented Mar 27, 2020

Just have to clean this up locally and figure out a couple edge cases, but I've got a fix that I should be able to push up soon.

2020-03-27 21 27 44

@He-Pin
Copy link

He-Pin commented Mar 29, 2020

Very cool @ckipp01 , looking forward to your fix, thanks for sharing.

@ckipp01
Copy link
Author

ckipp01 commented Apr 11, 2020

I more than likely won't get this fixed for a while. If anyone wants to work off what I had started, it's closed to being finished and the tests are there as well. My branch is here https://github.com/ckipp01/sort-imports/tree/comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants