Skip to content

Commit

Permalink
Merge branch 'master' into kotlin-1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbosch committed Aug 19, 2020
2 parents a3f8692 + f3877b4 commit 2464940
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 23 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -250,6 +250,11 @@ Integrations:
- [detekt-hint is a plugin to detekt that provides detection of design principle violations through integration with Danger](https://github.com/mkohm/detekt-hint)
- [GitHub Action: Detekt All](https://github.com/marketplace/actions/detekt-all)

Custom rules from 3rd parties:

- [cph-cachet/detekt-verify-implementation](https://github.com/cph-cachet/detekt-verify-implementation)
- [detekt-hint is a plugin to detekt that provides detection of design principle violations through integration with Danger](https://github.com/mkohm/detekt-hint)

#### Credits

- [JetBrains](https://github.com/jetbrains/) - Creating IntelliJ + Kotlin
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Expand Up @@ -14,7 +14,7 @@ repositories {

object Plugins {
const val KOTLIN = "1.4.0"
const val DETEKT = "1.11.1"
const val DETEKT = "1.11.2"
const val GITHUB_RELEASE = "2.2.12"
const val ARTIFACTORY = "4.15.1"
const val SHADOW = "5.2.0"
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
@@ -1,6 +1,6 @@
object Versions {

const val DETEKT: String = "1.11.1"
const val DETEKT: String = "1.11.2"
const val JVM_TARGET: String = "1.8"
const val JACOCO: String = "0.8.5"

Expand Down
Expand Up @@ -2,6 +2,7 @@ package io.gitlab.arturbosch.detekt.formatting

import com.pinterest.ktlint.core.EditorConfig
import com.pinterest.ktlint.core.KtLint
import io.github.detekt.psi.fileName
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.CorrectableCodeSmell
import io.gitlab.arturbosch.detekt.api.Debt
Expand All @@ -15,8 +16,6 @@ import io.gitlab.arturbosch.detekt.api.SourceLocation
import io.gitlab.arturbosch.detekt.api.TextLocation
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.com.intellij.lang.FileASTNode
import org.jetbrains.kotlin.com.intellij.psi.PsiElement
import org.jetbrains.kotlin.com.intellij.testFramework.LightVirtualFile
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.psiUtil.endOffset

Expand Down Expand Up @@ -63,7 +62,7 @@ abstract class FormattingRule(config: Config) : Rule(config) {
SourceLocation(line, column),
TextLocation(node.startOffset, node.psi.endOffset),
"($line, $column)",
root.originalFilePath() ?: root.containingFile.name
root.fileName
)

// Nodes reported by 'NoConsecutiveBlankLines' are dangling whitespace nodes which means they have
Expand All @@ -74,14 +73,11 @@ abstract class FormattingRule(config: Config) : Rule(config) {
.takeIf { it.isNotEmpty() }
?.plus(".")
?: ""
val entity = Entity("", "", "$packageName${root.name}:$line", location, root)
val entity = Entity("", "", "$packageName${root.fileName}:$line", location, root)
report(CorrectableCodeSmell(issue, entity, message, autoCorrectEnabled = autoCorrect))
}
}

private fun ruleShouldOnlyRunOnFileNode(node: ASTNode) =
wrapping is com.pinterest.ktlint.core.Rule.Modifier.RestrictToRoot && node !is FileASTNode

private fun PsiElement.originalFilePath() =
(this.containingFile.viewProvider.virtualFile as? LightVirtualFile)?.originalFile?.name
}
Expand Up @@ -5,6 +5,7 @@ import io.gitlab.arturbosch.detekt.test.TestConfig
import org.assertj.core.api.Assertions.assertThat
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
import java.nio.file.Paths

class MaximumLineLengthSpec : Spek({

Expand All @@ -17,12 +18,24 @@ class MaximumLineLengthSpec : Spek({

describe("a single function") {

val code = "fun f() { /* 123456789012345678901234567890 */ }"
val code = """
package home.test
fun f() { /* 123456789012345678901234567890 */ }
""".trimIndent()

it("reports line which exceeds the threshold") {
assertThat(subject.lint(code)).hasSize(1)
}

it("reports issues with the filename and package as signature") {
val finding = subject.lint(
code,
Paths.get("home", "test", "Test.kt").toString()
).first()

assertThat(finding.entity.signature).isEqualTo("home.test.Test.kt:2")
}

it("does not report line which does not exceed the threshold") {
val config = TestConfig(MaximumLineLength.MAX_LINE_LENGTH to code.length)
assertThat(MaximumLineLength(config).lint(code)).isEmpty()
Expand Down
Expand Up @@ -9,8 +9,8 @@ import org.jetbrains.kotlin.com.intellij.openapi.util.text.StringUtilRt
import java.io.File
import java.nio.file.Paths

fun FormattingRule.lint(content: String): List<Finding> {
val root = compileContentForTest(content)
fun FormattingRule.lint(content: String, fileName: String = "Test.kt"): List<Finding> {
val root = compileContentForTest(content, fileName)
this.visit(root)
root.node.visit { node -> this.apply(node) }
return this.findings
Expand Down
1 change: 0 additions & 1 deletion detekt-gradle-plugin/build.gradle.kts
Expand Up @@ -4,7 +4,6 @@ plugins {
}

dependencies {
implementation(kotlin("gradle-plugin"))
implementation(kotlin("gradle-plugin-api"))
}

Expand Down
5 changes: 0 additions & 5 deletions detekt-gradle-plugin/gradle/wrapper/gradle-wrapper.properties

This file was deleted.

Expand Up @@ -99,14 +99,14 @@ abstract class DslTestBuilder {

private const val GROOVY_PLUGINS_SECTION = """
|plugins {
| id "org.jetbrains.kotlin.jvm"
| id 'java-library'
| id "io.gitlab.arturbosch.detekt"
|}
|"""

private const val KOTLIN_PLUGINS_SECTION = """
|plugins {
| kotlin("jvm")
| `java-library`
| id("io.gitlab.arturbosch.detekt")
|}
|"""
Expand All @@ -120,12 +120,10 @@ abstract class DslTestBuilder {
|"""

private const val GROOVY_APPLY_PLUGINS = """
|apply plugin: "kotlin"
|apply plugin: "io.gitlab.arturbosch.detekt"
|"""

private const val KOTLIN_APPLY_PLUGINS = """
|plugins.apply("kotlin")
|plugins.apply("io.gitlab.arturbosch.detekt")
|"""
}
Expand Down
2 changes: 1 addition & 1 deletion docs/_config.yml
Expand Up @@ -113,4 +113,4 @@ description: "Meet detekt, a static code analysis tool for Kotlin."
url: https://detekt.github.io/detekt/
baseurl: /

detekt_version: 1.11.1
detekt_version: 1.11.2
9 changes: 9 additions & 0 deletions docs/pages/changelog 1.x.x.md
Expand Up @@ -6,6 +6,15 @@ permalink: changelog.html
toc: true
---

#### 1.11.2 - 2020-08-19

##### Changelog

- Fix formatting regression where issues printed the whole filename - [#2988](https://github.com/detekt/detekt/pull/2988)
- Baseline adds file path instead package - [#2985](https://github.com/detekt/detekt/issues/2985)

See all issues at: [1.11.2](https://github.com/detekt/detekt/milestone/74)

#### 1.11.1 - 2020-08-18

##### Changelog
Expand Down

0 comments on commit 2464940

Please sign in to comment.