0

Eclipse 2018-12 Eclipse Checkstyle Plug-in 8.12.0 Java jdk11.0.1

In my eclipse projects, i use Google’s auto-value. Files are autogenerated in /projectRoot/.apt_generated/tld/domain/some/package/AutoValue_AnyName.java. I want to exclude those files from checkstyle checks, so i added

<module name="BeforeExecutionExclusionFileFilter">
    <property name="fileNamePattern" value=".*/.apt_generated/.*/AutoValue_.*"/>
</module>

in my checkstyle.xml. IMO, that should match the autogenerated files and exclude them from scanning. Alas, Eclipse’s opinion differs. The files are scanned, and Google does not follow my coding style, so i get a lot of “Problems”. How can i exclude those files from checkstyle?

2
  • Double check your folder path (/ versus \) and the .apt portion (I assume you mean \.apt. If that doesn't work try making the pattern exclude everything and work backwords to your specific file/folder. Commented Jan 13, 2019 at 23:37
  • I tried /, \ and \\ (because the \ is the escape character in regexps), nothing works. Commented Jan 15, 2019 at 14:00

1 Answer 1

2

You can exclude from checking by adding this to your project's .checkstyle file:

<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
  ...
  <filter name="DerivedFiles" enabled="true" />
</fileset-config>

This assumes that AutoValue/APT is marking the generated files as derived.

Or if your generated types are restricted to a particular folder/package:

<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
  ...
  <filter name="FilesFromPackage" enabled="true">
    <filter-data value="derived" />
  </filter>
</fileset-config>

Or you can try:

<module name="SuppressionFilter">
    <property name="file" value="${config_loc}/.checkstyleSuppress.xml" />
</module>

with an appropriate supress xml file. It is very versatile but takes some work to set up for the first time.

Sign up to request clarification or add additional context in comments.

1 Comment

Since i just lack the time to test all those propositions, i decided to select files externally. I exclude generated files from checkstyle in eclipse, and i just select src/java/main in gradle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.