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

AnnotationUseStyle: compact_no_array does not violate extended and multi param annotations #3210

Closed
eric-milles opened this issue May 22, 2016 · 5 comments

Comments

Projects
None yet
5 participants
@eric-milles
Copy link

commented May 22, 2016

/var/tmp $ cat TestClass.java 
@SuppressWarnings(value = "rawtypes") // 'value=' is superflous (non-compact) - VIOLATION
public class Example {
    @SuppressWarnings({"unchecked"}) // array is superflous - VIOLATION 
    public void somePublicMethod() {
    }

    @SomeAnnotation(attr1="value1", arrt2={"value2"}) // array is superfluous  - VIOLATION
    public Object[] stuff;
}

/var/tmp $ cat my_check.xml 
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name = "Checker">
    <module name="TreeWalker">
        <module name="AnnotationUseStyle">
            <property name="elementStyle" value="compact_no_array" />
            <property name="trailingArrayComma" value="ignore" />
        </module>
    </module>
</module>

/var/tmp $ java -jar checkstyle-7.0-all.jar -c my_check.xml TestClass.java 
Starting audit...
[ERROR] /var/tmp/TestClass.java:3: Annotation style must be 'COMPACT_NO_ARRAY'. [AnnotationUseStyle]
Audit done.
Checkstyle ends with 1 errors.

Expected violations are marked at source code - there should be 3 of them as all of them are not compact.

Attention: "compact" mode should give 1 violation 1st line.

http://checkstyle.sourceforge.net/config_annotation.html#AnnotationUseStyle
http://checkstyle.sourceforge.net/property_types.html#elementStyle

@romani romani changed the title AnnotationUseStyle: add support for redundant value attribute and redundant array for single-value attribute AnnotationUseStyle: compact_no_array does not violate extended and multi param annotations Jun 28, 2016

@rnveach rnveach added the easy label Mar 2, 2017

@checkstyle checkstyle deleted a comment from izishared Aug 31, 2017

@Sekair

This comment has been minimized.

Copy link

commented Aug 31, 2017

I am on it

@Sekair

This comment has been minimized.

Copy link

commented Sep 4, 2017

@eric-milles @romani There is some problem with this issue.
@SomeAnnotation(attr1="value1", arrt2={"value2"}) // array is superfluous - VIOLATION
This must be a valid example with no violation, cuz the documentaiton says

compact_no_array | It is similar to the compact style but single value arrays are flagged. With annotations a single value array does not need to be placed in an array initializer. This style can only be used when there is an element called 'value' which is either the sole element or all other elements have default values.

What should i do? I dont know why we need to have "value" element to validate a single value array, so we can allow to mark a single value array in any element as violate and just use "value" to validate "compact" rule. Or we can just ignore it?

@Vladlis

This comment has been minimized.

Copy link
Member

commented Sep 4, 2017

+1 from me for

mark a single value array in any element

@romani

This comment has been minimized.

Copy link
Member

commented Sep 4, 2017

@Sekair , we need to validate all elements of annotation not only default("value").
Documentation at http://checkstyle.sourceforge.net/property_types.html#elementStyle is very uncertain, please help us to fix it. Each value should have description that explain behavior , with examples where violation will be and where not.
Please update section - https://github.com/checkstyle/checkstyle/blob/master/src/xdocs/property_types.xml#L512 to avoid any future misinterpretations of how works.
Doc polishing could be done in separate commit of the same PR or in the same commit.

I appreciate your help, thanks in advance.

strkkk added a commit to strkkk/checkstyle that referenced this issue Jun 4, 2019

strkkk added a commit to strkkk/checkstyle that referenced this issue Jun 5, 2019

strkkk added a commit to strkkk/checkstyle that referenced this issue Jun 12, 2019

strkkk added a commit to strkkk/checkstyle that referenced this issue Jun 13, 2019

strkkk added a commit to strkkk/checkstyle that referenced this issue Jun 14, 2019

strkkk added a commit to strkkk/checkstyle that referenced this issue Jun 14, 2019

romani added a commit that referenced this issue Jun 14, 2019

@romani romani added this to the 8.22 milestone Jun 14, 2019

@romani

This comment has been minimized.

Copy link
Member

commented Jun 14, 2019

fix is merged.

@romani romani closed this Jun 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.