Enable rules according to code scope

43 views
Skip to first unread message

Alon Furman

unread,
Aug 21, 2017, 10:31:48 AM8/21/17
to scalasty...@googlegroups.com
Hi,

We want to enable/disable rules for production or test code.
For example we want to enable Magic number checker on production code but disable it for test code.

How would you suggest we do it?

Thanks,
Alon Furman

Matthew Farwell

unread,
Aug 21, 2017, 4:27:59 PM8/21/17
to scalasty...@googlegroups.com
If you're using sbt you can specify a different configuration for test code, using 

(scalastyleConfig in Test) := baseDirectory.value / "scalastyle-test-config.xml"


If you're using maven, this is a bit more complicated, but still doable.

Thanks.

Matthew Farwell.

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "Scalastyle users".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse scalastyle-users+unsubscribe@googlegroups.com.
Pour envoyer un message à ce groupe, envoyez un e-mail à l'adresse scalastyle-users@googlegroups.com.
Visitez ce groupe à l'adresse https://groups.google.com/group/scalastyle-users.
Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.

Alon Furman

unread,
Aug 22, 2017, 4:18:40 AM8/22/17
to Scalastyle users
Thanks for the response!
I would like to avoid using 2 different configuration files for production and tests, I would like to enable/disable rules using only one configuration file.

For example:
<check level=“warning” class=“org.scalastyle.scalariform.MagicNumberChecker” enabled=“true”>
     <parameters>
         <parameter name=“ignore”><![CDATA[-1,0,1,2,3]]></parameter>
         <parameter name="scope"><![CDATA[production]]></parameter>
     </parameters>
</check>

Thanks,
Alon Furman

On Monday, August 21, 2017 at 11:27:59 PM UTC+3, Matthew Farwell wrote:
If you're using sbt you can specify a different configuration for test code, using 

(scalastyleConfig in Test) := baseDirectory.value / "scalastyle-test-config.xml"


If you're using maven, this is a bit more complicated, but still doable.

Thanks.

Matthew Farwell.
Le 21 août 2017 à 16:31, Alon Furman <furma...@gmail.com> a écrit :
Hi,

We want to enable/disable rules for production or test code.
For example we want to enable Magic number checker on production code but disable it for test code.

How would you suggest we do it?

Thanks,
Alon Furman

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "Scalastyle users".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse scalastyle-use...@googlegroups.com.
Pour envoyer un message à ce groupe, envoyez un e-mail à l'adresse scalasty...@googlegroups.com.

Matthew Farwell

unread,
Aug 23, 2017, 4:59:07 AM8/23/17
to scalasty...@googlegroups.com
That isn't possible at the minute. I understand that it is a bit awkward to have two files, but that is the only way for the minute. There are other potential solutions as well, such as being able to specify a list of config files, which would be merged to have the correct one according to scope. The problem is that scope is specific to the build.

Personally, I have a global off switch for certain checks in my test files, such as

// scalastyle:off magic.number null

at the top of the test files.

It isn't pretty, but it works.

Matthew Farwell.

Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse scalastyle-users+unsubscribe@googlegroups.com.
Pour envoyer un message à ce groupe, envoyez un e-mail à l'adresse scalastyle-users@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages