Ban uses of error() method call with detekt

151 views Asked by At

I wish to ban the uses of error() method.

My goal is to Ban the use of Generic exception. I can use rule TooGenericExceptionThrown if the code throws the error explicitly. However, when folks use error method. Which is defined in standard kotlin library.

public inline fun error(message: Any): Nothing = throw IllegalStateException(message.toString())

It doesn't get caught by TooGenericExceptionThrown.

I tried enabling ForbiddenMethodCall as below

  ForbiddenMethodCall:
    active: true
    methods:
      - 'kotlin.io.print'
      - 'kotlin.io.println'
      - 'kotlin.error(kotlin.Any)'
      - 'error(kotlin.Any)'
      - 'error()'
      - 'error'
      - 'kotlin.error'

When I run ./gradlew detektMain in command line, while it catches the use of print and println it doesn't catch error method call.

Not sure what I'm missing.

1

There are 1 answers

0
pr4bh4sh On BEST ANSWER

Response from the maintainer https://github.com/detekt/detekt/discussions/6485

./gradlew clean detektMain detektTest checks all files and solves the problem I was facing.