Restrict Checkstyle validation using project filters

The Eclipse Checkstyle Pluin contains a filter facility to exclude certain files from Checkstyle.
Knowing that the plug-in allows you to configure file sets you might ask why there are also filters.
This feature seems to be quite redundant to file sets.

Lets think about this some more.
File set let you configure patterns that determine if a file gets included or excluded from the checks based on the file name.
In some situations this is quite sufficient but there are also cases where you want to exclude files based on other properties, for instance if you want to exclude files that are write protected.

The filters are accessible in the bottom section of the Checkstyle Project Properties Page.

project filters
To enable a filter for your project just select the corresponding check box.
Some filters are configurable, if you select such a filter the Change... button will become enabled.
Pressing the Change... button will open a specific filter editor.

The following filters come with the plugin:

Filter Description
Files outside source directories This filter is enabled by default. Some projects have java sources outside of source folders (for instance build folders where all sources are copied to for source distribution builds).
With this filter you can exclude this files from the checks. Again, this can be also achieved by configuring file sets - but for most cases the filter is easier to use.
Write protected files Use this filter if you want to check only writeable files. This filter is particular useful if you use a versioning system with a Check-In/Check-Out semantic which uses file write protection to allow/disallow modification.
So you can restrict the Checkstyle Plug-in to only check files you are actually working on (because you checked them out from the repository).
Derived (generated) files Excludes project resources which have the Derived flag set, which is typically the case for generated sources.
Files not opened in editor You can use this filter to check only files you opened in an Eclipse editor. This is particularly useful for big projects, as checking all files might lead to unacceptable build times or resource consumption.
If this filter is enabled a project file which is opened in the editor is automatically checked upon opening, pointing out the problems in this file. Likewise when the file is closed the assiciated problem markers are cleared from the Problems view.
Files from packages This is a configurable filter, allowing you to specify the packages you want to exclude from checking. You can, of course, get the same result by configuring file sets, but this variant is much more practical.
Files in sync with the source repository If your project is based on a source repository (Git, SVN, CVS) you might want to use this filter.
With this you can limit the checks to the files you actually changed. All other files that are in sync with the repository (therefore unchanged) are excluded from the checks.
This filter is a great way to support the application of the Boy Scout Rule (aka Leave the campground cleaner than you found it.) within your development team.

The Eclipse Checkstyle Plugin provides an extension point for customer filters which can be used to implement your own filter. Read here for more info about extending the plugin with filters .