+
Skip to content

google_checks.xml: remove xpath suppression and false-positive indentation violations for block codes #15769

@Zopsss

Description

@Zopsss

I have read check documentation: https://checkstyle.org/checks/misc/indentation.html
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words

Detected at #14294

In google_checks.xml, Indentation module gives false-positive error for following type of blocks:

{
  int x = 99;
}

Example:

/** Test... */
public class Test {
  private static void indentationIssue(int condition) {
    { // line 4, false-positive
      System.out.println("True");
    } // line 6, false-positive
  }

  { // good, no violation
    System.out.println("False");
  } // good, no violation

    { // line 13, expected
      System.out.println("False");
    } // line 15, expected

  class Inner {
    void test() {
      { // line 19, false-positive
        System.out.println("True");
      } // line 21, false-positive
    }
  }
}
$ java -jar .\checkstyle-10.18.2-all.jar -c .\google_checks.xml .\Test.java
Starting audit...
[WARN] C:\checkstyle testing\.\Test.java:4:5: 'block lcurly' has incorrect indentation level 4, expected level should be 6. [Indentation]
[WARN] C:\checkstyle testing\.\Test.java:6:5: 'block rcurly' has incorrect indentation level 4, expected level should be 6. [Indentation]
[WARN] C:\checkstyle testing\.\Test.java:13:5: 'block lcurly' has incorrect indentation level 4, expected level should be 2. [Indentation]
[WARN] C:\checkstyle testing\.\Test.java:14:7: 'block' child has incorrect indentation level 6, expected level should be 4. [Indentation]
[WARN] C:\checkstyle testing\.\Test.java:15:5: 'block rcurly' has incorrect indentation level 4, expected level should be 2. [Indentation]
[WARN] C:\checkstyle testing\.\Test.java:19:7: 'block lcurly' has incorrect indentation level 6, expected level should be 8. [Indentation]
[WARN] C:\checkstyle testing\.\Test.java:21:7: 'block rcurly' has incorrect indentation level 6, expected level should be 8. [Indentation]
Audit done.

@romani suggested to use suppression to suppress these false-positives until we find a way to fix it at: #14294 (comment)

The suppression is:

    <module name="SuppressionXpathSingleFilter">
      <property name="checks" value="Indentation"/>
      <property name="query" value="//SLIST/SLIST"/>
    </module>
    <module name="SuppressionXpathSingleFilter">
      <property name="checks" value="Indentation"/>
      <property name="query" value="//SLIST/SLIST/RCURLY"/>
    </module>
    <module name="Indentation">
      <property name="basicOffset" value="2"/>
      <property name="braceAdjustment" value="2"/>
      <property name="caseIndent" value="2"/>
      <property name="throwsIndent" value="4"/>
      <property name="lineWrappingIndentation" value="4"/>
      <property name="arrayInitIndent" value="2"/>
    </module>

Adding this suppression will suppress all indentation violations for above mentioned type of blocks whether they're correct or not but we need to use it till we find a fix.


As part of this issue, we need to find a way to fix this false-positive and remove the suppression.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载