This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const val WHEN_STATEMENT = """ | |
sealed class S { | |
object A: S() | |
object B: S() | |
} | |
class WhenTester { | |
fun checkS(state: S) { | |
when (state) { | |
S.A -> println("a") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
testImplementation "io.gitlab.arturbosch.detekt:detekt-api:$detektVersion" | |
testImplementation "io.gitlab.arturbosch.detekt:detekt-test:$detektVersion" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NonExhaustiveWhen(config: Config = Config.empty): Rule(config) { | |
override val issue = Issue( | |
javaClass.simpleName, | |
Severity.Defect, | |
DESCR, | |
Debt.FIVE_MINS | |
) | |
override fun visitNamedFunction(function: KtNamedFunction) { | |
super.visitNamedFunction(function) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun visitNamedFunction(function: KtNamedFunction) { | |
super.visitNamedFunction(function) | |
val whenExpressions = | |
function.children.filterIsInstance<KtBlockExpression>() | |
.flatMap { blockExpression -> blockExpression.children.asIterable() } | |
.filterIsInstance<KtWhenExpression>() | |
if (whenExpressions.isNotEmpty()) { | |
report( | |
CodeSmell( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NonExhaustiveWhen(config: Config = Config.empty): Rule(config) { | |
override val issue = Issue( | |
javaClass.simpleName, | |
Severity.Defect, | |
DESCR, | |
Debt.FIVE_MINS | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compileOnly "io.gitlab.arturbosch.detekt:detekt-api:$detektVersion" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun render(viewState: EmailLoginViewState) { | |
when(viewState) { | |
INITIAL -> renderInitial() | |
}.exhaustive | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example | |
/** | |
* We declare a package-level function main which returns Unit and takes | |
* an Array of strings as a parameter. Note that semicolons are optional. | |
*/ | |
fun main(args: Array<String>) { | |
println("Hello, world!") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun render(viewState: EmailLoginViewState) { | |
when(viewState) { | |
INITIAL -> renderInitial() | |
}.exhaustive | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val <T> T.exhaustive: T | |
get() = this |