saveourtool/diktat
Vedi su GitHubOptional rule: require should have a message unless it's inside code from tests
Open
#838 aperta il 22 apr 2021
enhancementgood first issue
Metriche repository
- Star
- (571 star)
- Metriche merge PR
- (Metriche PR in attesa)
Descrizione
Preconditions from Kotlin stdlib (require, requireNotNull) accept an optional message parameter. If it's not set, failed precondition results in exceptions like Requirement failed at class:line:col. This is not useful and confusing. Unless require or requireNotNull is used in tests, it should be provided with exception message.
require(a.condition())
requireNotNull(b)
should be something like
require(a.condition()) { "Condition is not met for $a" }
requireNotNull(b) { "b is not set" }
Sure, we can't suggest exact text of these messages, so the possible inspection should only warn.