scalacheckstylescalastyle

Scala checkstyle - Ignoring specific files for check


I've got a scalastyle_config.xml file with the following check, among others:

<check class="org.scalastyle.scalariform.ClassNamesChecker" level="warning" enabled="false">
   <parameters>
         <parameter name="regex"><![CDATA[^[A-Z][A-Za-z]*$]]></parameter>
   </parameters>
</check>

I want this to be applied to all files, except for two:

-FooK3.java
-FooK3Something.java

Is there any way to add an exception for those files? Can't see anything in the documentation


Solution

  • I don't know any way to exclude specific files from that checker, and I've been using scalastyle for a while, so I assume there isn't such a way at the moment.

    What can be done, is turning off scalastyle exactly where you don't want it. And then it will work on the rest of the file. For example where you define Class FooK3, you can do either:

    class FooK3 { // scalastyle:ignore
    

    Or:

    // scalastyle:off
    public class FooK3 {
    // scalastyle:on
      int x = 5;
    }
    

    Then the check will pass. A good practice is the add to the comment the name of the rule you want to bypass, such that if one day someone fixes it, scalastyle will be returned.

    Official docs can be found here.