Support Kotlin 1.4 (#2981)

* Update to Gradle 6.6

* Update to Kotlin 1.4

* Upgrade to prerelease of KtLint 0.38

* Fix testcase by unwrapping the original descriptor

* Increase max heap for dokka on Java 11

* Update minimal supported Gradle version to 5.3

* Do not run warningsAsErrors on CI due to Gradle not supporting Kotlin 1.4

* Remove new line testing as it fails on windows

* Require Gradle 5.4 to reflect Kotlin's required version from their website
This commit is contained in:
Artur Bosch
2020-08-20 20:00:38 +02:00
committed by GitHub
parent f3877b4430
commit ee49144114
29 changed files with 65 additions and 84 deletions

View File

@@ -31,7 +31,7 @@ jobs:
java-version: 8
- name: Build detekt
run: ./gradlew build --build-cache --parallel -PwarningsAsErrors=true
run: ./gradlew build --build-cache --parallel
- name: Deploy Snapshot
env:

View File

@@ -53,7 +53,7 @@ jobs:
- name: Build detekt
run: ./gradlew build :detekt-cli:shadowJarExecutable -PwarningsAsErrors=true --parallel
run: ./gradlew build :detekt-cli:shadowJarExecutable --parallel
- name: Run detekt-cli --help
run: java -jar ./detekt-cli/build/run/detekt --help
- name: Run detekt-cli with argsfile

View File

@@ -63,7 +63,7 @@ You can find [other ways to install detekt here](https://detekt.github.io/detekt
#### with Gradle
Gradle 5.0+ is required:
Gradle 5.4+ is required:
```kotlin
buildscript {

View File

@@ -13,7 +13,7 @@ repositories {
}
object Plugins {
const val KOTLIN = "1.3.72"
const val KOTLIN = "1.4.0"
const val DETEKT = "1.11.2"
const val GITHUB_RELEASE = "2.2.12"
const val ARTIFACTORY = "4.15.1"

View File

@@ -8,7 +8,6 @@ plugins {
val analysisDir = file(projectDir)
val baselineFile = file("$rootDir/config/detekt/baseline.xml")
val configFile = file("$rootDir/config/detekt/detekt.yml")
val formatConfigFile = file("$rootDir/config/detekt/format.yml")
val statisticsConfigFile = file("$rootDir/config/detekt/statistics.yml")
val kotlinFiles = "**/*.kt"
@@ -53,7 +52,7 @@ val detektFormat by tasks.registering(Detekt::class) {
buildUponDefaultConfig = true
autoCorrect = true
setSource(analysisDir)
config.setFrom(listOf(statisticsConfigFile, formatConfigFile))
config.setFrom(listOf(statisticsConfigFile, configFile))
include(kotlinFiles)
include(kotlinScriptFiles)
exclude(resourceFiles)

View File

@@ -53,6 +53,8 @@ formatting:
autoCorrect: true
MaximumLineLength:
active: false
ParameterListWrapping:
active: false
naming:
MemberNameEqualsClassName:

View File

@@ -1,6 +0,0 @@
formatting:
active: true
android: false
autoCorrect: true
MaximumLineLength:
active: false

View File

@@ -5,7 +5,7 @@ plugins {
dependencies {
val version = object {
val spek = "2.0.13-alpha.0.3+3b5f071"
val ktlint = "0.37.2"
val ktlint = "0.38.0-alpha01"
}
constraints {

View File

@@ -22,6 +22,6 @@ class DetektProgressListener : FileProcessListener {
override fun onFinish(files: List<KtFile>, result: Detektion) {
val middlePart = if (files.size == 1) "file was" else "files were"
outPrinter.appendln("\n\n${files.size} kotlin $middlePart analyzed.")
outPrinter.appendLine("\n\n${files.size} kotlin $middlePart analyzed.")
}
}

View File

@@ -34,14 +34,14 @@ private fun CliArgs.validate(jCommander: JCommander) {
val violations = StringBuilder()
if (createBaseline && baseline == null) {
violations.appendln("Creating a baseline.xml requires the --baseline parameter to specify a path.")
violations.appendLine("Creating a baseline.xml requires the --baseline parameter to specify a path.")
}
if (!createBaseline && baseline != null) {
if (Files.notExists(checkNotNull(baseline))) {
violations.appendln("The file specified by --baseline should exist '$baseline'.")
violations.appendLine("The file specified by --baseline should exist '$baseline'.")
} else if (!Files.isRegularFile(checkNotNull(baseline))) {
violations.appendln("The path specified by --baseline should be a file '$baseline'.")
violations.appendLine("The path specified by --baseline should be a file '$baseline'.")
}
}

View File

@@ -20,6 +20,6 @@ class AstPrinter(
}
val ktFile = KtCompiler().compile(input, input)
outPrinter.appendln(ElementPrinter.dump(ktFile))
outPrinter.appendLine(ElementPrinter.dump(ktFile))
}
}

View File

@@ -12,6 +12,6 @@ class ConfigExporter(
override fun execute() {
val configPath = Paths.get(arguments.config ?: "detekt.yml")
DefaultConfigurationProvider.load().copy(configPath)
outputPrinter.appendln("Successfully copied default config to ${configPath.toAbsolutePath()}")
outputPrinter.appendLine("Successfully copied default config to ${configPath.toAbsolutePath()}")
}
}

View File

@@ -12,7 +12,7 @@ class ElementPrinter : DetektVisitor() {
companion object {
fun dump(file: KtFile): String = ElementPrinter().run {
sb.appendln("0: " + file.javaClass.simpleName)
sb.appendLine("0: " + file.javaClass.simpleName)
visitKtFile(file)
sb.toString()
}
@@ -39,14 +39,14 @@ class ElementPrinter : DetektVisitor() {
val currentLine = element.line
if (element.isContainer()) {
indent++
sb.appendln(element.dump)
sb.appendLine(element.dump)
} else {
if (lastLine == currentLine) {
indent++
sb.appendln(element.dump)
sb.appendLine(element.dump)
indent--
} else {
sb.appendln(element.dump)
sb.appendLine(element.dump)
}
}
lastLine = currentLine

View File

@@ -5,6 +5,6 @@ import io.github.detekt.tooling.api.VersionProvider
class VersionPrinter(private val outputPrinter: Appendable) : Executable {
override fun execute() {
outputPrinter.appendln(VersionProvider.load().current())
outputPrinter.appendLine(VersionProvider.load().current())
}
}

View File

@@ -3,18 +3,14 @@ package io.gitlab.arturbosch.detekt.cli.runners
import io.github.detekt.test.utils.StringPrintStream
import org.assertj.core.api.Assertions.assertThat
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
class VersionPrinterSpec : Spek({
describe("version printer") {
test("prints the version") {
val printStream = StringPrintStream()
it("prints the version") {
val printStream = StringPrintStream()
VersionPrinter(printStream).execute()
VersionPrinter(printStream).execute()
assertThat(printStream.toString()).isEqualTo("1.6.0" + System.lineSeparator())
}
assertThat(printStream.toString()).contains("1.6.0")
}
})

View File

@@ -1,8 +1,8 @@
package io.gitlab.arturbosch.detekt.core
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
import org.jetbrains.kotlin.cli.common.messages.PlainTextMessageRenderer
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
@@ -16,7 +16,7 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProvid
internal fun generateBindingContext(
environment: KotlinCoreEnvironment,
classpath: List<String>,
files: List<KtFile>
files: List<KtFile>,
): BindingContext {
if (classpath.isEmpty()) {
return BindingContext.EMPTY
@@ -38,11 +38,11 @@ internal fun generateBindingContext(
private object DetektMessageRenderer : PlainTextMessageRenderer() {
override fun getName() = "detekt message renderer"
override fun getPath(location: CompilerMessageLocation) = location.path
override fun getPath(location: CompilerMessageSourceLocation) = location.path
override fun render(
severity: CompilerMessageSeverity,
message: String,
location: CompilerMessageLocation?
location: CompilerMessageSourceLocation?,
): String {
if (!severity.isError) return ""
return super.render(severity, message, location)

View File

@@ -29,7 +29,7 @@ class OutputFacade(
for (extension in extensions) {
val output = extension.render(result)
if (!output.isNullOrBlank()) {
settings.outputChannel.appendln(output)
settings.outputChannel.appendLine(output)
}
}
}

View File

@@ -19,7 +19,7 @@ internal fun Throwable.printStacktraceRecursively(logger: Appendable) {
is PrintStream -> this.printStackTrace(logger)
is PrintWriter -> this.printStackTrace(logger)
else -> {
stackTrace.forEach { logger.appendln(it.toString()) }
stackTrace.forEach { logger.appendLine(it.toString()) }
cause?.printStacktraceRecursively(logger)
}
}
@@ -33,17 +33,17 @@ internal class LoggingFacade(
override val errorChannel: Appendable = spec.errorChannel
override fun info(msg: String) {
outputChannel.appendln(msg)
outputChannel.appendLine(msg)
}
override fun error(msg: String, error: Throwable) {
errorChannel.appendln(msg)
errorChannel.appendLine(msg)
error.printStacktraceRecursively(errorChannel)
}
override fun debug(msg: () -> String) {
if (spec.debug) {
outputChannel.appendln(msg())
outputChannel.appendLine(msg())
}
}
}

View File

@@ -7,7 +7,6 @@ import io.github.detekt.test.utils.StringPrintStream
import io.github.detekt.test.utils.createTempFileForTest
import io.github.detekt.test.utils.resourceAsPath
import io.gitlab.arturbosch.detekt.core.DetektResult
import io.gitlab.arturbosch.detekt.core.NL
import io.gitlab.arturbosch.detekt.core.createNullLoggingSpec
import io.gitlab.arturbosch.detekt.core.tooling.withSettings
import io.gitlab.arturbosch.detekt.test.createFinding
@@ -42,9 +41,9 @@ internal class OutputFacadeSpec : Spek({
spec.withSettings { OutputFacade(this).run(defaultResult) }
assertThat(printStream.toString()).contains(
"Successfully generated ${TxtOutputReport().name} at $plainOutputPath$NL",
"Successfully generated ${XmlOutputReport().name} at $xmlOutputPath$NL",
"Successfully generated ${HtmlOutputReport().name} at $htmlOutputPath$NL"
"Successfully generated ${TxtOutputReport().name} at $plainOutputPath",
"Successfully generated ${XmlOutputReport().name} at $xmlOutputPath",
"Successfully generated ${HtmlOutputReport().name} at $htmlOutputPath"
)
}
})

View File

@@ -29,9 +29,9 @@ object MultiVersionTest : Spek({
private fun getGradleVersionsUnderTest() =
if (getJdkVersion() < 13) {
listOf("5.0", "6.4.1")
listOf("5.4", "6.6")
} else {
listOf("6.4.1")
listOf("6.6")
}
private fun getJdkVersion(): Int {

View File

@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
dependencies {
api(kotlin("compiler-embeddable"))
implementation(project(":detekt-psi-utils"))
@@ -5,7 +7,7 @@ dependencies {
}
tasks.withType<Test> {
systemProperty("kotlinVersion", embeddedKotlinVersion)
systemProperty("kotlinVersion", getKotlinPluginVersion() ?: embeddedKotlinVersion)
doFirst {
systemProperty("testClasspath", classpath.joinToString(";"))

View File

@@ -54,9 +54,9 @@ class UnusedPrivateMember(config: Config = Config.empty) : Rule(config) {
override val defaultRuleIdAliases: Set<String> = setOf("UNUSED_VARIABLE", "UNUSED_PARAMETER", "unused")
override val issue: Issue = Issue("UnusedPrivateMember",
Severity.Maintainability,
"Private member is unused.",
Debt.FIVE_MINS)
Severity.Maintainability,
"Private member is unused.",
Debt.FIVE_MINS)
private val allowedNames by LazyRegex(ALLOWED_NAMES_PATTERN, "(_|ignored|expected|serialVersionUID)")
@@ -99,11 +99,11 @@ private class UnusedFunctionVisitor(
} else {
emptyList()
}
val referenceDescriptors = (references + referencesViaOperator).mapNotNull {
it.getResolvedCall(bindingContext)?.resultingDescriptor
}
functions.filter {
bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, it] !in referenceDescriptors
val referenceDescriptors = (references + referencesViaOperator)
.mapNotNull { it.getResolvedCall(bindingContext)?.resultingDescriptor }
.map { it.original }
functions.filterNot {
bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, it] in referenceDescriptors
}
}
references.isEmpty() -> functions
@@ -204,7 +204,7 @@ private class UnusedParameterVisitor(allowedNames: Regex) : UnusedMemberVisitor(
private fun KtNamedFunction.isRelevant() = !isAllowedToHaveUnusedParameters()
private fun KtNamedFunction.isAllowedToHaveUnusedParameters() =
isAbstract() || isOpen() || isOverride() || isOperator() || isMainFunction() || isExternal() || isExpect()
isAbstract() || isOpen() || isOverride() || isOperator() || isMainFunction() || isExternal() || isExpect()
}
private class UnusedPropertyVisitor(allowedNames: Regex) : UnusedMemberVisitor(allowedNames) {
@@ -214,9 +214,11 @@ private class UnusedPropertyVisitor(allowedNames: Regex) : UnusedMemberVisitor(a
override fun getUnusedReports(issue: Issue): List<CodeSmell> {
return properties
.filter { it.nameAsSafeName.identifier !in nameAccesses }
.map { CodeSmell(issue, Entity.from(it),
"Private property ${it.nameAsSafeName.identifier} is unused.") }
.filter { it.nameAsSafeName.identifier !in nameAccesses }
.map {
CodeSmell(issue, Entity.from(it),
"Private property ${it.nameAsSafeName.identifier} is unused.")
}
}
override fun visitParameter(parameter: KtParameter) {
@@ -236,8 +238,8 @@ private class UnusedPropertyVisitor(allowedNames: Regex) : UnusedMemberVisitor(a
override fun visitPrimaryConstructor(constructor: KtPrimaryConstructor) {
super.visitPrimaryConstructor(constructor)
constructor.valueParameters
.filter { (it.isPrivate() || !it.hasValOrVar()) && it.containingClassOrObject?.isExpect() == false }
.forEach { maybeAddUnusedProperty(it) }
.filter { (it.isPrivate() || !it.hasValOrVar()) && it.containingClassOrObject?.isExpect() == false }
.forEach { maybeAddUnusedProperty(it) }
}
override fun visitSecondaryConstructor(constructor: KtSecondaryConstructor) {

View File

@@ -1157,7 +1157,7 @@ class UnusedPrivateMemberSpec : Spek({
"""
val findings = subject.compileAndLintWithContext(env, code)
assertThat(findings).hasSize(1).hasSourceLocations(
SourceLocation(3,5)
SourceLocation(3, 5)
)
}
}

View File

@@ -10,7 +10,7 @@ redirect_from:
summary:
---
detekt requires Gradle 5.0 or higher.
detekt requires Gradle 5.4 or higher.
#### <a name="tasks">Available plugin tasks</a>

View File

@@ -4,5 +4,7 @@ systemProp.file.encoding=UTF-8
org.gradle.parallel=true
org.gradle.workers.max=4
org.gradle.caching=true
# increase max heap for dokka on Java 11
org.gradle.jvmargs=-Xmx1024m
# Needed for https://github.com/gradle/gradle/issues/11412
systemProp.org.gradle.internal.publish.checksums.insecure=true

Binary file not shown.

View File

@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

2
gradlew vendored
View File

@@ -130,7 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath

21
gradlew.bat vendored
View File

@@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -54,7 +54,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
@@ -64,21 +64,6 @@ echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
@@ -86,7 +71,7 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell