Kiril
Kiril

Reputation: 998

How to suppress Scalastyle warning?

I got following code:

    string match {
      case Regex(_, "1", "0", _, _)    =>
      case Regex(_, "1", "1", null, _) =>
    }

Scalastyle is complaining about usage of null which cannot be avoided here. Any way I can suppress warning just for this line?

Upvotes: 40

Views: 24224

Answers (3)

Guildenstern70
Guildenstern70

Reputation: 1859

You may also add a

scalastyle_config.xml

to your project, and enable/disable any rule. See http://www.scalastyle.org/configuration.html

Upvotes: 0

mbarton
mbarton

Reputation: 646

Scalastyle understands suppression comments:

// scalastyle:off <rule id>
...
// scalastyle:on <rule id>

Rule ids are listed here

In your case, the id is simply null:

// scalastyle:off null
...
// scalastyle:on null

This was also answered on the mailing list

Upvotes: 62

Mike Allen
Mike Allen

Reputation: 8249

For a single line, you just append // scalastyle:ignore <rule-id> to the end, like so:

string match {
  case Regex(_, "1", "0", _, _)    =>
  case Regex(_, "1", "1", null, _) => // scalastyle:ignore null
}

If it's obvious what you want Scalastyle to ignore, you can disable all checks for the current line by omitting the rule-id (as you can for the on/off comments as well):

string match {
  case Regex(_, "1", "0", _, _)    =>
  case Regex(_, "1", "1", null, _) => // scalastyle:ignore
}

Upvotes: 39

Related Questions