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

Create a Checkstyle module to enforce comment formatting in input files #13797

Closed
relentless-pursuit opened this issue Sep 28, 2023 · 9 comments · Fixed by #13803
Closed

Create a Checkstyle module to enforce comment formatting in input files #13797

relentless-pursuit opened this issue Sep 28, 2023 · 9 comments · Fixed by #13803

Comments

@relentless-pursuit
Copy link

We haveve noticed inconsistencies in the formatting of single-line comments in the codebase. For instance, some comments lack a space after the //, making them harder to read.

Current Behavior:
Comments like //violation exist in the codebase without a space after //.

Desired Behavior:
All single-line comments should have a space after //, like // violation.

@nrmancuso
Copy link
Member

@relentless-pursuit do you have a suggestion on which checkstyle module we can use for this? It would be good to add an example that loosely follows our bug report format to help the person that works on this issue to fully understand what we need to do.

@romani
Copy link
Member

romani commented Sep 28, 2023

I also like space after // , and main code base are restricted by some check, we can reuse it if we find it.

To find it , we can just remove space after // and see what Check is doing violation

@romani romani assigned romani and unassigned romani Sep 28, 2023
@relentless-pursuit
Copy link
Author

relentless-pursuit commented Sep 29, 2023

I also like space after // , and main code base are restricted by some check, we can reuse it if we find it.

To find it , we can just remove space after // and see what Check is doing violation

I used a RegexpSinglelineCheck in checkstyle-examples-checks.xml

Below it the example i tested the check:

/*xml
<module name="Checker">
  <module name="TreeWalker">
    <module name="AnnotationLocation">
      <property name="allowSamelineSingleParameterlessAnnotation"
                value="false"/>
      <property name="allowSamelineParameterizedAnnotation" value="false"/>
      <property name="allowSamelineMultipleAnnotations" value="true"/>
    </module>
  </module>
</module>


*/

package com.puppycrawl.tools.checkstyle.checks.annotation.annotationlocation;

import org.antlr.v4.runtime.misc.NotNull;
import org.mockito.Mock;

// xdoc section -- start
class Example2 {
  @NotNull
  private boolean field1;
  @Override public int hashCode() { return 1; }
  @NotNull
  private boolean field2;
  @Override
  public boolean equals(Object obj) { return true; }
  @Mock
  DataLoader loader1;
  @SuppressWarnings("deprecation") DataLoader loader;
  @SuppressWarnings("deprecation") public int foo() { return 1; } // ok
  @NotNull @Mock DataLoader loader2;
  //ok above as 'allowSamelineMultipleAnnotations' set to true
}
// xdoc section -- end

Result of the build:

[ERROR] [checkstyle] [ERROR] /Users/piyushkumarsadangi/Development/new/checkstyle/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/annotation/annotationlocation/Example2.java:35: Single-line comment should have a space after //. [ensureSpaceAfterSingleLineComment]

@romani
Copy link
Member

romani commented Sep 29, 2023

please send PR.

relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Sep 30, 2023
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Sep 30, 2023
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Sep 30, 2023
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Sep 30, 2023
relentless-pursuit pushed a commit to relentless-pursuit/checkstyle that referenced this issue Oct 1, 2023
@relentless-pursuit
Copy link
Author

Hi @romani , can this be assigned a hacktober fest label?

@romani
Copy link
Member

romani commented Oct 1, 2023

@relentless-pursuit , please let us know what label matters this year.

@relentless-pursuit
Copy link
Author

relentless-pursuit commented Oct 1, 2023

@relentless-pursuit , please let us know what label matters this year.

hacktoberfest i guess. i can only confirm if one of my such labeled PR gets merged. (among the two labels seen)

@nrmancuso
Copy link
Member

Closed via #13803

@nrmancuso
Copy link
Member

@relentless-pursuit thanks for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants