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

Comment formatting not idempotent #331

Closed
jhaber opened this issue Dec 12, 2019 · 2 comments · Fixed by #336
Closed

Comment formatting not idempotent #331

jhaber opened this issue Dec 12, 2019 · 2 comments · Fixed by #336
Labels
area: bug 🐛 Something isn't working theme: comments Issue caused by comments handling theme: Re-Writer

Comments

@jhaber
Copy link
Contributor

jhaber commented Dec 12, 2019

We're seeing code that needs to be formatted 3 times before it stabilizes and the final formatting doesn't look right.

(All of these are formatted with print-width=70)

Input:

public class Example {
  Map<String, String> map =
    // there is a random comment on this line up here
    // and then there is a separate comment on this line down here
    new HashMap<>(
      someRandomMethodThatReturnsTheInitialMapThatWeWantToMutate()
    );
}

Output after first formatting:

public class Example {
  Map<String, String> map = // there is a random comment on this line up here
  // and then there is a separate comment on this line down here
  new HashMap<>(
    someRandomMethodThatReturnsTheInitialMapThatWeWantToMutate()
  );
}

Output after second formatting:

public class Example {
  Map<String, String> map = // and then there is a separate comment on this line down here // there is a random comment on this line up here
  new HashMap<>(
    someRandomMethodThatReturnsTheInitialMapThatWeWantToMutate()
  );
}

Output after third formatting (stable after this):

public class Example {
  Map<String, String> map = new HashMap<>( // and then there is a separate comment on this line down here // there is a random comment on this line up here
    someRandomMethodThatReturnsTheInitialMapThatWeWantToMutate()
  );
}

I believe the issue is related to the placement of the comments, moving them elsewhere solves the issue

@clementdessoude
Copy link
Contributor

clementdessoude commented Dec 15, 2019

Ah yes, we are still facing some issues with comments when there are placed at some unexpected places. For instance:

class T {

  public void t() {
    for
    // one
    // two
    (;;) {
      int i = 1;
      int j = 2;
    }
  }
}

is not idempotent either.

@clementdessoude
Copy link
Contributor

In your case, I am pretty sure that putting the comments before the Map<String, String> map = should be ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: bug 🐛 Something isn't working theme: comments Issue caused by comments handling theme: Re-Writer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants