override fun visitImportList()

in detekt-rules/src/software/aws/toolkits/gradle/detekt/rules/BannedImportsRule.kt [17:62]


    override fun visitImportList(importList: KtImportList) {
        super.visitImportList(importList)
        importList.imports.forEach { element ->
            if (element.importedFqName?.asString() == "org.assertj.core.api.Assertions") {
                report(
                    CodeSmell(
                        issue,
                        Entity.from(element),
                        message = "Import the assertion you want to use directly instead of importing the top level Assertions"
                    )
                )
            }

            if (element.importedFqName?.asString()?.startsWith("org.hamcrest") == true) {
                report(
                    CodeSmell(
                        issue,
                        Entity.from(element),
                        message = "Use AssertJ instead of Hamcrest assertions"
                    )
                )
            }

            if (element.importedFqName?.asString()?.startsWith("kotlin.test.assert") == true &&
                element.importedFqName?.asString()?.startsWith("kotlin.test.assertNotNull") == false
            ) {
                report(
                    CodeSmell(
                        issue,
                        Entity.from(element),
                        message = "Use AssertJ instead of Kotlin test assertions"
                    )
                )
            }

            if (element.importedFqName?.asString()?.contains("kotlinx.coroutines.Dispatchers") == true) {
                report(
                    CodeSmell(
                        issue,
                        Entity.from(element),
                        message = "Use contexts from CoroutineUtils.kt instead of Dispatchers"
                    )
                )
            }
        }
    }