Skip to content

Small scalafix rule to avoid pattern matching cases that matches everything.

License

Notifications You must be signed in to change notification settings

daddykotex/scalafix-matchall

Repository files navigation

Scalafix rules for Match All

A linter to help you avoid wildcard pattern matching.

Continuous Integration

Details

This rule prevents you from unintentionally adding a case to a pattern match that would match everything. The Scala compiler can do exhaustive checking of pattern match in certain condition. Having a catch all case in the pattern match will make the compiler happy when in reality some cases would be better handled by a specific case.

The rule looks for:

  • case where the _ wild card is used with no guards
  • case where the pattern is just a variable that does not start with _ with no guards

You can disable the rule in a given scope using the @SuppressWarnings("MatchAll") annotation.

Usage

Currently, this rule is not published on maven central, as such, the only way to run it is from source. See the scalafix website for more info.

scalafix --rules=https://raw.githubusercontent.com/daddykotex/scalafix-matchall/main/rules/src/main/scala/fix/MatchAll.scala

Development

To develop rule:

sbt ~tests/test
# edit rules/src/main/scala/fix/MatchAll.scala

About

Small scalafix rule to avoid pattern matching cases that matches everything.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages