Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanups #4542

Merged
merged 1 commit into from Jan 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -4,13 +4,12 @@ import java.io.Closeable
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.function.Supplier

typealias Task<T> = CompletableFuture<T>
typealias TaskList<T> = List<CompletableFuture<T>>

fun <T> TaskPool.task(block: () -> T): Task<T> =
CompletableFuture.supplyAsync(Supplier { block() }, this)
CompletableFuture.supplyAsync({ block() }, this)

fun <T> Task<T>.recover(block: (Throwable) -> T?): Task<T?> = this.exceptionally(block)

Expand Down
Expand Up @@ -8,6 +8,7 @@ class Errors {
}

fun javaExit() {
@Suppress("ReplaceJavaStaticMethodWithKotlinAnalog")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Why this? Was it triggering a warning of any form? If so where?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I see a suggestion by IDEA to replace System.exit(1) with exitProcess(1), it's not proper right here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not proper right here?

I think it's ok. This is a test resource, so we're not actually executing it and should be treated as plain-text. However, as the IDE is recognizing that is Kotlin code, it's probably ok to have it.

System.exit(1)
}
}
Expand Up @@ -15,7 +15,7 @@ open class CustomDetektReport @Inject constructor(objects: ObjectFactory) {
@Deprecated("Use outputLocation.set(value)")
@get:Internal
var destination: File?
get() = outputLocation.asFile.getOrNull()
get() = outputLocation.asFile.orNull
set(value) {
outputLocation.set(value)
}
Expand Down
Expand Up @@ -17,7 +17,7 @@ open class DetektReport @Inject constructor(val type: DetektReportType, objects:

@Deprecated("Use outputLocation.set(value)")
var destination: File?
get() = outputLocation.asFile.getOrNull()
get() = outputLocation.asFile.orNull
set(value) {
outputLocation.set(value)
}
Expand Down
Expand Up @@ -122,7 +122,7 @@ class DslGradleRunner @Suppress("LongParameterList") constructor(

@OptIn(ExperimentalStdlibApi::class)
private fun buildGradleRunner(tasks: List<String>): GradleRunner {
val args = buildList<String> {
val args = buildList {
add("--stacktrace")
add("--info")
add("--build-cache")
Expand Down
Expand Up @@ -62,8 +62,7 @@ class HtmlOutputReport : OutputReport() {

private fun renderDate(): String {
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
val now = OffsetDateTime.now(ZoneOffset.UTC).format(formatter) + " UTC"
return now
return "${OffsetDateTime.now(ZoneOffset.UTC).format(formatter)} UTC"
}

private fun renderMetrics(metrics: Collection<ProjectMetric>) = createHTML().div {
Expand Down
Expand Up @@ -23,7 +23,6 @@ package io.github.detekt.report.xml

import java.util.ArrayList
import java.util.Arrays
import java.util.Collections

/**
* Adapted from Unbescape - https://github.com/unbescape/unbescape/
Expand All @@ -33,7 +32,7 @@ import java.util.Collections
object XmlEscape {

private val REFERENCE_HEXA_PREFIX = "&#x".toCharArray()
private val REFERENCE_SUFFIX = ';'
private const val REFERENCE_SUFFIX = ';'

/**
* Perform an XML 1.0 level 2 (markup-significant and all non-ASCII chars) **escape** operation
Expand Down Expand Up @@ -169,7 +168,7 @@ object XmlEscape {
@Suppress("ALL")
private object Xml10EscapeSymbolsInitializer {

internal class XmlCodepointValidator {
class XmlCodepointValidator {

/*
* XML 1.0 does not allow many control characters, nor unpaired surrogate chars
Expand Down Expand Up @@ -221,7 +220,7 @@ private object Xml10EscapeSymbolsInitializer {
/*
* Everything non-ASCII is level 2 unless contrary indication.
*/
for (c in 0x80..XmlEscapeSymbols.LEVELS_LEN - 1) {
for (c in 0x80 until XmlEscapeSymbols.LEVELS_LEN) {
escapeLevels[c] = 2
}

Expand Down Expand Up @@ -376,16 +375,16 @@ private object Xml10EscapeSymbolsInitializer {
SORTED_CODEPOINTS_BY_CER = IntArray(structureLen)

val cersOrdered = ArrayList(cers)
Collections.sort(cersOrdered) { o1, o2 -> String(o1).compareTo(String(o2)) }
cersOrdered.sortWith { o1, o2 -> String(o1).compareTo(String(o2)) }

val codepointsOrdered = ArrayList(codepoints)
Collections.sort(codepointsOrdered)
codepointsOrdered.sort()

// Order the CODEPOINT -> CERs (escape)structures
for (i in 0..structureLen - 1) {
for (i in 0 until structureLen) {
val codepoint = codepointsOrdered[i]
SORTED_CODEPOINTS[i] = codepoint
for (j in 0..structureLen - 1) {
for (j in 0 until structureLen) {
if (codepoint == codepoints[j]) {
SORTED_CERS_BY_CODEPOINT[i] = cers[j]
break
Expand All @@ -394,10 +393,10 @@ private object Xml10EscapeSymbolsInitializer {
}

// Order the CERs -> CODEPOINT (unescape)structures
for (i in 0..structureLen - 1) {
for (i in 0 until structureLen) {
val cer = cersOrdered[i]
SORTED_CERS[i] = cer
for (j in 0..structureLen - 1) {
for (j in 0 until structureLen) {
if (Arrays.equals(cer, cers[j])) {
SORTED_CODEPOINTS_BY_CER[i] = codepoints[j]
break
Expand Down Expand Up @@ -428,7 +427,7 @@ private object Xml10EscapeSymbolsInitializer {
/*
* Size of the array specifying the escape levels.
*/
val LEVELS_LEN = (0x9f + 2)
const val LEVELS_LEN = (0x9f + 2)
}
}
}