Scalastyle - Configuration

Quick start

You can just use the default Scalastyle configuration scalastyle_config.xml. Right-click this link and select Save link as. This is the one we use for Scalastyle development, so it’s obviously the best :-)

Format of the file

The configuration file is XML containing a list of rules to apply to your Scala source. A (short) example configuration would be:

<scalastyle commentFilter="enabled">
 <name>Scalastyle standard configuration</name>
 <check level="warning" class="org.scalastyle.file.FileTabChecker" enabled="true" />
 <check level="warning" class="org.scalastyle.file.FileLengthChecker" enabled="true">
  <parameters>
   <parameter name="maxFileLength">800</parameter>
  </parameters>
 </check>
</scalastyle>

Each check element is the name of the class which implements the checker along with any parameters. For a list of rules plus parameters, see Implemented Rules.

Comment filters

If you wish to turn off checking for a section of code, you can put a comment in the source before and after the section, with the following syntax:

// scalastyle:off
...
// naughty stuff
...
// scalastyle:on

You can switch off checking for a single line using a comment at the end of the line:

naughty()  // scalastyle:ignore

You can also switch off checking for a specific rule by specifying the id of the rule to ignore:

// scalastyle:off magic.number
var foobar = 134
// scalastyle:on magic.number

Custom messages

If you wish to have a custom error message for a particular checker, then you can do so by defining a customMessage element in the configuration, such as:

<check level="warning" class="org.scalastyle.scalariform.MagicNumberChecker" enabled="true">
 <customMessage>Please don't use magic numbers</customMessage>
</check>

If you wish to have a customId associated with a rule (for instance you may have the same rule with multiple configurations), then you can specify the customId attribute:

<check customId="this.is.custom" level="warning" class="org.scalastyle.scalariform.MagicNumberChecker" enabled="true" />
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值