eclipse-cs icon indicating copy to clipboard operation
eclipse-cs copied to clipboard

Is there an easy way to exclude Maven test directories from checking?

Open noelo-cohelo opened this issue 6 years ago • 12 comments

noelo-cohelo avatar Feb 11 '19 12:02 noelo-cohelo

OK, I found it myself ;)

It's under project configuration (right-click on the project -> Properties -> Checkstyle -> Exclude from checking... -> files from packages: ).

Still think this should be included in FAQ.

And one more thing: normally in the Maven project you have the same package names in main and test source directories - and those directories names are not shown in "Filter packages" view - so one kind of need to guess which ones to check.

noelo-cohelo avatar Feb 11 '19 12:02 noelo-cohelo

ignoring some Checks in maven test folder by checkstyle config - https://github.com/checkstyle/checkstyle/blob/checkstyle-8.17/config/suppressions.xml#L32

romani avatar Feb 12 '19 15:02 romani

Thank you. What do you think, is it worth putting on FAQ?

I don't use suppresstions.xml, does it mean I need to create one?

noelo-cohelo avatar Feb 12 '19 15:02 noelo-cohelo

I think you need to create suppression config.

not sure if it worse to be in FAQ. Suppression is a very big topic.

romani avatar Feb 12 '19 15:02 romani

Before, I don't need to do this setting explicitly.

Today I updated the plugin from version 8.23 to 8.32 and the plugin started scanning src/test/.

Eclipse version: 2020-03 (4.15.0)

mhagnumdw avatar May 25 '20 13:05 mhagnumdw

@Calixte , do you know anything on this change in behavior ?

romani avatar May 25 '20 22:05 romani

No. I don't think we introduced any change that would have this consequence.

Calixte avatar May 26 '20 04:05 Calixte

If test folders shall be ignored completely, wouldn't it be more useful to configure a BeforeExecutionExclusionFileFilter? My understanding was that this one completely avoids matching files from being processed, while all the suppression filters only throw away found issues after processing. Performance wise that might make a big difference on large code bases, wouldn't it?

Bananeweizen avatar May 26 '20 09:05 Bananeweizen

Before, I don't need to do this setting explicitly.

Today I updated the plugin from version 8.23 to 8.32 and the plugin started scanning src/test/.

Eclipse version: 2020-03 (4.15.0)

After

  • Eclipse Checkstyle version 8.23
  • src/test not scanned, everything is ok here

image

checkstyle-for-8.23.xml.txt

Before

  • Eclipse Checkstyle version 8.32
  • src/test scanned, here seems to be a problem

image

checkstyle-for-8.32.xml.txt

mhagnumdw avatar May 26 '20 16:05 mhagnumdw

The Eclipse Checkstyle plugin doesn't differentiate between main sources and test sources (and never did, as far as I know). So it should have been scanning the test sources also in the old version (and that's what it does in all my installations). However, the plugin will definitively only scan source folders which are configured as part of the classpath. Does your old version really contain a source folder (that's the upper rectangle in your second screenshot), and not just a folder (that's the lower rectangle in your second screenshot). If those are two different installations, then you want to compare the .classpath files of the selected project.

One more thing to look at would be "project context menu -> properties -> checkstyle", there you can specify additional criteria for things to include/exclude in the scan.

Bananeweizen avatar May 26 '20 17:05 Bananeweizen

If those are two different installations, then you want to compare the .classpath files of the selected project.

The .project file is the same in both. No differences.

The only difference between both projects are:

  • the version of the checkstyle plugin for Eclipse
  • the checkstyle.xml file (because the checkstyle version changes and I needed to make adjustments)

mhagnumdw avatar May 26 '20 20:05 mhagnumdw

I configured the filter as advised,

<!-- Ignore test sources -->
<module name="BeforeExecutionExclusionFileFilter">
    <property name="fileNamePattern" value=".*[\\/]src[\\/]test[\\/].*$"/>
</module>

and indeed using the Checkstyle Gradle plugin the test sources are excluded (when I remove the filter, Gradle flags the test files). However eclipse still flags the files. I tried disabling, then enabling Checkstyle for the project, I tried cleaning the project, the warnings still come back.

Should I file a new ticket as this was originally about something different? Are we misusing it somehow?

JanecekPetr avatar Jul 19 '23 14:07 JanecekPetr