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
enum class Destination { | |
HOME, | |
NOTIFICATIONS, | |
ACCOUNTS | |
} |
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 visit(root: KtFile) { | |
super.visit(root) | |
val classVisitor = UnusedClassVisitor() | |
root.accept(classVisitor) | |
classVisitor.privateClasses | |
.filterNot<KtNamedDeclaration> { it.isUsed() } | |
.forEach { | |
report(CodeSmell(issue, Entity.from(it), "Private class ${it.nameAsSafeName.identifier} is unused.")) |
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
private fun KtNamedDeclaration.isUsed(): Boolean { | |
if (nameAsSafeName.identifier in namedClasses) return true | |
val pathSegments = fqName?.pathSegments().orEmpty() | |
return pathSegments.isNotEmpty() && importedFqNames.any { importedFqName -> | |
importedFqName.pathSegments().zip(pathSegments).all { it.first == it.second } | |
} | |
} |
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 Solution { | |
private var count = 0 | |
private var candidate: Int? = null | |
fun majorityElement(nums: IntArray): Int { | |
for (num in nums) { | |
candidate = updateCandidateForZeroCount(num) | |
count = updateCountForCandidate(num) | |
} |
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
if (count == 0) { | |
candidate = num | |
} | |
if (num == candidate) { | |
count++ | |
} else { | |
count-- | |
} |
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 Solution { | |
fun majorityElement(nums: IntArray): Int { | |
var count = 0 | |
var candidate: Int? = null | |
for (num in nums) { | |
if (count == 0) { | |
candidate = num | |
count++ | |
} else { |
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
private void includeSetupAndTeardownPages() throws Exception { | |
includeSetupPages(); | |
includePageContent(); | |
includeTeardownPages(); | |
updatePageContent(); | |
} | |
private void includeSetupPages() throws Exception { | |
if (isSuite) | |
includeSuiteSetupPage(); |
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
public static String testableHtml(PageData pageData, boolean includeSuiteSetup) throws Exception { | |
WikiPage wikiPage = pageData.getWikiPage(); | |
StringBuffer buffer = new StringBuffer(); | |
if (pageData.hasAttribute("Test")) { | |
if (includeSuiteSetup) { | |
WikiPage suiteSetup = PageCrawlerImpl.getInheritedPage(SuiteResponder.SUITE_SETUP_NAME, wikiPage); | |
if (suiteSetup != null) { | |
WikiPagePath pagePath = suiteSetup.getPageCrawler().getFullPath(suiteSetup); | |
String pagePathName = PathParser.render(pagePath); | |
buffer.append("!include -setup .").append(pagePathName).append("\n"); |
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
import io.gitlab.arturbosch.detekt.api.Config | |
import io.gitlab.arturbosch.detekt.test.assertThat | |
import io.gitlab.arturbosch.detekt.test.compileAndLintWithContext | |
import io.gitlab.arturbosch.detekt.test.setupKotlinEnvironment | |
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment | |
import org.junit.jupiter.api.BeforeAll | |
import org.junit.jupiter.api.Test | |
class DoubleNegativeTakeUnlessTest { |
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
import io.gitlab.arturbosch.detekt.api.* | |
import org.jetbrains.kotlin.psi.* | |
import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType | |
class DoubleNegativeTakeUnless(config: Config = Config.empty) : Rule(config) { | |
override val issue = Issue( | |
"DoubleNegativeTakeUnless", | |
Severity.Style, | |
"Using double negatives with `takeUnless` can make the code harder to read.", |
NewerOlder