Skip to content

Move violation comments above of annotated methods #19803

@romani

Description

@romani

Follow-up of #19757

Background

Find a way to fail build on cases of //violation .... usage in between of method javadoc java annotations and method signatures
We should keep target code as natural as possible to not let violation comment to do side effect to violation and let users recognize problems as in real code and comment around just hint on what is wrong.

bad

/** 
 * This Javadoc contains unclosed tag.
 * <code>unclosed 'code' tag<code>
 */
 // violation 2 lines above 'Unclosed HTML tag found: <code>'
void foo() {}

good:

// violation 3 lines below 'Unclosed HTML tag found: <code>'
/** 
 * This Javadoc contains unclosed tag.
 * <code>unclosed 'code' tag<code>
 */
void foo() {}

bad

@Override
 // violation above 'xxx'
void foo() {}

good:

 // violation below 'xxx'
@Override
void foo() {}

Task

Ensure no violation comments in between of methods signature and annoation or javadoc all existing input files.

Here is a list of existing input files to be fixed:

<!-- until https://github.com/checkstyle/checkstyle/issues/19803 -->
<suppress id="violationBetweenAnnotationAndMethod"
files="[\\/]checks[\\/]annotation[\\/]annotationlocation[\\/]InputAnnotationLocationAnnotation\.java"/>
<suppress id="violationBetweenAnnotationAndMethod"
files="[\\/]checks[\\/]annotation[\\/]annotationlocation[\\/]InputAnnotationLocationClass\.java"/>

How to contribute

  1. Choose a Check (group of Inputs for same Check) from the list;
  2. Move all violation out of target code snippets;
  3. Remove related suppressions;
  4. Update violation line numbers inside unit test methods, if any changed.
  5. Send PR.

Notes

  1. Moving violating comments around requires adding (X lines) above/below to make sure they still reference the same line. You can refer to guide to specify violations for syntax.
  2. Make sure no input files exceed the limit of 120 lines.

Example of expected update https://github.com/checkstyle/checkstyle/pull/19804/changes , #19811

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions