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

Remove redundant string concatenations when unwrapping lines #122

Open
dpursehouse opened this issue Feb 10, 2017 · 0 comments
Open

Remove redundant string concatenations when unwrapping lines #122

dpursehouse opened this issue Feb 10, 2017 · 0 comments

Comments

@dpursehouse
Copy link

In code that has string concatenation wrapped on multiple lines, the formatter should remove any redundant concatenations when unwrapping the line.

See this reformatting change on the gerrit project for example:

The original code:

      throw new IllegalStateException(String.format(
          "SubmitRuleEvaluator.evaluate for change %s " +
          "returned empty list for %s in %s",
          cd.getId(),
          patchSet.getId(),
          cd.change().getProject().get()));

And after reformatting:

    throw new IllegalStateException(
          String.format(
              "SubmitRuleEvaluator.evaluate for change %s " + "returned empty list for %s in %s",
              cd.getId(), patchSet.getId(), cd.change().getProject().get()));

The first parameter to String.format now has a redundant concatenation, and would be better as:

          String.format(
              "SubmitRuleEvaluator.evaluate for change %s returned empty list for %s in %s",
              cd.getId(), patchSet.getId(), cd.change().getProject().get()));
lucamilanesio pushed a commit to GerritCodeReview/gerrit that referenced this issue Feb 17, 2017
Reformatting the code with google-java-format tool in change Id5f3c6de9
resulted in wrapped lines being unwrapped to the new 100 columns limit.

In cases where the wrapped line was wrapped on a string concatenation,
the resulting long line now includes redundant concatenations. See the
upstream issue [1] for an example of this.

Squash the redundant concatenations with:

  git ls-files | grep java$ | xargs sed -i '' 's/" + "//g'

(note: this also resulted in a couple of unwanted changes; those are
manually undone.)

[1] google/google-java-format#122

Change-Id: I7348413ae460c8c7a0b0c72dab0a1ae7275a2ec3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants