Skip to content

Google-style: New Check BlockCommentEndPositionCheck #18571

@Praveen7294

Description

@Praveen7294

From #18273

BlockCommentEndPositionCheck should validate position of */. And have property strategy with the values alone or along_or_singleline and default value should be alone_or_singleLine.

7.1.1 General Form and google/google-java-format#1279 (comment)

The preferred style is to put /** and */ on their own lines (unless the entire javadoc comment fits on a single line), and to include a leading * on each line.

Example config with default value:

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
        "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
        "https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
    <module name="TreeWalker">
        <module name="BlockCommentEndPosition"/>
    </module>
</module>

Test.java

/**
 * Testing misaligned leading asterisks.
 */
public class Test {

  /**  Javadoc for instance variable. */   // ok, default value is `alone_or_singleline`
  private String xyz;

  /**
   * If leading asterisk is not present then identation is not checked.
   */
  private int age;

  /**
   * Leading asterisk not present. */  // violation ''BLOCK_COMMENT_END' must be on the new line.'
  private void foo1() {}

  /**
   * Correct Indentation for leading asterisk. */ // violation ''BLOCK_COMMENT_END' must be on the new line.'
  private void foo2() {}

  /** 
   * Testing... 
   */
  public static void main(String[] args) {
    System.out.println("Hello, World!");
  }
}

Example output:

$ java -jar testing/checkstyle-10.25.0-all.jar -c config.xml TextBlocks.java 
Starting audit...
[WARN] Test.java:15:36: 'BLOCK_COMMENT_END' must be on the new line. [BlockCommentEndPosition]
[WARN] Test.java:19:48 'BLOCK_COMMENT_END' must be on the new line. [BlockCommentEndPosition]
Audit done.

Example with alone value:

config:

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
        "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
        "https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
    <module name="TreeWalker">
        <module name="BlockCommentEndPosition">
            <property name="strategy" value="alone">
        </module>
    </module>
</module>

Test.java

/**
 * Testing misaligned leading asterisks.
 */
public class Test {

  /**  Javadoc for instance variable. */   // violation ''BLOCK_COMMENT_END' must be on the new line.'
  private String xyz;

  /**
   * If leading asterisk is not present then identation is not checked.
   */
  private int age;

  /**
   * Javadoc for instance method foo1. */  // violation ''BLOCK_COMMENT_END' must be on the new line.'
  private void foo1() {}

  /**
   *  Javadoc for instance method foo2. */ // violation ''BLOCK_COMMENT_END' must be on the new line.'
  private void foo2() {}

  /** 
   * Testing... 
   */
  public static void main(String[] args) {
    System.out.println("Hello, World!");
  }
}

output:

$ java -jar testing/checkstyle-10.25.0-all.jar -c config.xml TextBlocks.java 
Starting audit...
[WARN] Test.java:6:39: 'BLOCK_COMMENT_END' must be on the new line. [BlockCommentEndPosition]
[WARN] Test.java:15:36: 'BLOCK_COMMENT_END' must be on the new line. [BlockCommentEndPosition]
[WARN] Test.java:19:48 'BLOCK_COMMENT_END' must be on the new line. [BlockCommentEndPosition]
Audit done.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions