rewrite-static-analysis icon indicating copy to clipboard operation
rewrite-static-analysis copied to clipboard

TernaryOperatorsShouldNotBeNested does not handle assignments

Open pstreef opened this issue 1 year ago • 0 comments

TernaryOperatorsShouldNotBeNested is only implemented for return statements and lambdas, not assignments (or other possible places for ternaries).

sample

class Test {
  public void doThing(String a, String b) {
    String result = "a".equals(a) ? "a" : "b".equals(b) ? "b" : "nope";
    System.out.println(result);
  }
}

expected:

class Test {
  public void doThing(String a, String b) {
      String result;
      if ("a".equals(a)) {
        result = "a";
      }
      else {
        result = "b".equals(b) ? "b" : "nope";
      }
      System.out.println(result);
  }
}

actual: no change

pstreef avatar May 18 '23 12:05 pstreef