Detekt: UseCheckOrError in conjunction with when statement

Created on 22 Aug 2019  路  3Comments  路  Source: detekt/detekt

I don't know why detekt 1.0.0 flags the following with the UseCheckOrError rule:

fun zoneactionModelDir() = when (this) {
  IN -> ZoneactionModel.Dir.IN
  OUT -> ZoneactionModel.Dir.OUT
  else -> throw IllegalStateException("Are you lost?")
}

How should I rewrite this one?

support

Most helpful comment

Today I learned about TIL, thanks!

All 3 comments

I think I can assist.

fun zoneactionModelDir() = when (this) {
  IN -> ZoneactionModel.Dir.IN
  OUT -> ZoneactionModel.Dir.OUT
  else -> error("Are you lost?")
}

TIL!

Today I learned about TIL, thanks!

Was this page helpful?
0 / 5 - 0 ratings