checkstyle / checkstyle

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. By default it supports the Google Java Style Guide and Sun Code Conventions, but is highly configurable. It can be invoked with an ANT task and a command line program.

Home Page:https://checkstyle.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to exclude java-Files that contain @Generated-Annotation?

AlBundy33 opened this issue · comments

Currently a lot of genreated jaxb-files (different packages/projects) are checked with checkstyle.
The classes have always a @Generated-Annotation.

Can I exclude such classes with a simple rule?

Usually generated sources are grouped in special folders. You can exclude folder from checkstyle to validate, it depends on what plugin you use.
If all is mixed, you should just extensively use https://checkstyle.org/filters/suppressionxpathsinglefilter.html#SuppressionXpathSingleFilter to suppress all

We have one global config for all projects and libraries, jaxb, wsdl, ...
So an exclusion based on path doesn't work.

I've already seen the filter and tried to define it but the class was not ignored.
First error is on the first line because the generated class comment does not match out rules.
Also left and rigth curly braces are on the wrong line.
And so on.

Therefore I want to exclude all classes with @generated.

Does it matter if I add the filter inside the checker or the treewalker and does the ordering of the modules matter?

I suggest you look over https://checkstyle.org/report_issue.html#How_to_report_a_bug.3F and provide us the necessary details to assist.

The examples connected to the filters show where they should be in terms of in TreeWalker or not. XPath needs to be in TreeWalker and won't work anywhere else.

Also, XPath filter only works on TreeWalker checks. If you are looking to suppress Checker checks, then your options are probably https://checkstyle.org/filters/suppresswithnearbycommentfilter.html or https://checkstyle.org/filters/suppresswarningsfilter.html or, as suggested by, by file name or path. However, we can only guess unless you provide us a case.

Also this is probably better suited in discussions as you are asking for assistance instead of reporting a bug or asking for a feature.

ok - I've created a new discussion #14773