Ignoring few classes from import control check

105 views
Skip to first unread message

Anku

unread,
Mar 22, 2017, 11:14:01 AM3/22/17
to checkstyle
Hello,

I am using ImportControl check in project which checks for few unwanted imports in my source code. I want to exclude few .java files from this check.

For eg: I have a package - com.myapp.ui which contains 3 classes i.e FirstClass.java, SecondClass.java & ThirdClass.java. Here, I want to apply import control check on the complete package but excluding SecondClass.java, so that SecondClass.java will not be checked for import control.

Could someone help me in getting solution for this?

Thanks!

Roman Ivanov

unread,
Mar 22, 2017, 2:28:31 PM3/22/17
to Anku, checkstyle
Hi Anku,

there is not such ability in Check right now, there is no issue on this too in our issue tracker.

as want to completely turn off certain Check on certain classes, please use suppressions/filters

​thanks,
Roman Ivanov

Anku

unread,
Mar 23, 2017, 12:58:37 AM3/23/17
to checkstyle, anku.t...@gmail.com
Thanks Roman for a quick reply on this. Your suggestion has worked for me :)
Here is my code snippet:

<module name="SuppressionFilter">
<property name="file" value="config/checkstyle/suppression.xml"/>
</module>

suppression.xml

<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">

<suppressions>
<suppress checks="." files="[\\/]DatabaseHelper\.java$"/>
</suppressions> 

Thanks!

Roman Ivanov

unread,
Mar 23, 2017, 9:01:27 AM3/23/17
to Anku, checkstyle
Hi Anku,

​> suppress checks="."

it is recommended to use name of Check(ImportControl) instead of "." (all Checks)

but it is up to you.

Anku

unread,
Mar 23, 2017, 9:29:32 AM3/23/17
to checkstyle, anku.t...@gmail.com
Yes, I have got to this know later. Thanks for looking into this & providing your suggestion.
Reply all
Reply to author
Forward
0 new messages