openrewrite / openrewrite/rewrite-static-analysis

Prevent unintentional changes in logging best practices that conflict with Google Java Format

Open
#354 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
62
Forks
112
Avg merge
1d 19h
Merged PRs (30d)
40

Description

What problem are you trying to solve?

I want to use Google Java Format (AOSP) together with OpenRewrite

Describe the solution you'd like

OpenRewrite should not write files if only whitespace change.

Have you considered any alternatives or workarounds?

Disabling rules.

Additional context

org.openrewrite.staticanalysis.ChainStringBuilderAppendCalls:

--- a/src/main/java/org/jabref/logic/exporter/GroupSerializer.java
+++ b/src/main/java/org/jabref/logic/exporter/GroupSerializer.java
@@ -29,8 +29,7 @@ public class GroupSerializer {
     private String serializeExplicitGroup(ExplicitGroup group) {
         StringBuilder sb = new StringBuilder();
         sb.append(MetadataSerializationConfiguration.EXPLICIT_GROUP_ID);
-        sb.append(
-                StringUtil.quote(
+        sb.append(StringUtil.quote(
                         group.getName(),
                         MetadataSerializationConfiguration.GROUP_UNIT_SEPARATOR,
                         MetadataSerializationConfiguration.GROUP_QUOTE_CHAR));

org.openrewrite.java.logging.slf4j.ParameterizedLogging

-                                    "dataModel JabRef52"
-                                            + " only supports pageInfo for the last citation of a group");
+                            LOGGER.warn("dataModel JabRef52" + " only supports pageInfo for the last citation of a group");

(For this, I can do a work-around by using single-line strings only)

Are you interested in contributing this feature to OpenRewrite?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ChainStringBuilderAppendCalls and ParameterizedLogging recipes, using the GroupSerializer.java diff and the two shown transformations as concrete cases. Trace how OpenRewrite decides to write a file and define completion as preserving meaningful recipe changes while avoiding writes when the result differs only in whitespace.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.