From ac61cd13aa1a8d1ab4ccc97bcfc1c429520dd565 Mon Sep 17 00:00:00 2001 From: Almas Date: Tue, 1 Oct 2024 04:39:06 +0900 Subject: [PATCH 01/11] Upgraded dependencies to latest versions --- build.gradle | 60 +++++++++++-------- gradle.properties | 4 +- gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 0 .../hint/rules/LackOfCohesionMethods.kt | 3 + .../detekt/hint/rules/OpenClosedPrinciple.kt | 3 + .../UseCompositionInsteadOfInheritance.kt | 2 + 7 files changed, 45 insertions(+), 29 deletions(-) mode change 100644 => 100755 gradlew diff --git a/build.gradle b/build.gradle index a992b70..c8ac3c4 100644 --- a/build.gradle +++ b/build.gradle @@ -1,33 +1,33 @@ plugins { - id "org.jetbrains.kotlin.jvm" version "1.3.61" - id("io.gitlab.arturbosch.detekt").version("1.5.0") - id "com.vanniktech.maven.publish" version "0.8.0" + id "org.jetbrains.kotlin.jvm" version "1.9.20" + id "io.gitlab.arturbosch.detekt" version "1.23.7" + id "com.vanniktech.maven.publish" version "0.29.0" id "jacoco" + id "org.jetbrains.dokka" version "1.9.20" } repositories { - jcenter() mavenCentral() } dependencies { // When creating a sample extension, change this dependency to the detekt-api version you build against // e.g. io.gitlab.arturbosch.detekt:detekt-api:1.x.x - implementation("io.gitlab.arturbosch.detekt:detekt-api:1.5.0") + implementation "io.gitlab.arturbosch.detekt:detekt-api:1.23.7" // When creating a sample extension, change this dependency to the detekt-test version you build against // e.g. io.gitlab.arturbosch.detekt:detekt-test:1.x.x - testImplementation("io.gitlab.arturbosch.detekt:detekt-test:1.5.0") + testImplementation "io.gitlab.arturbosch.detekt:detekt-test:1.23.7" // Do you want to write integration or system tests? Add the cli dependency. - testImplementation("io.gitlab.arturbosch.detekt:detekt-cli:1.5.0") + testImplementation "io.gitlab.arturbosch.detekt:detekt-cli:1.23.7" - testImplementation("org.assertj:assertj-core:3.14.0") - testImplementation("org.spekframework.spek2:spek-dsl-jvm:2.0.9") - - testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.5.2") - testRuntimeOnly("org.spekframework.spek2:spek-runner-junit5:2.0.9") - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - detektPlugins "io.github.mkohm:detekt-hint:0.1.4" + testImplementation "org.assertj:assertj-core:3.26.3" + testImplementation "org.spekframework.spek2:spek-dsl-jvm:2.0.19" + testRuntimeOnly "org.junit.platform:junit-platform-launcher:1.10.0" + testRuntimeOnly "org.spekframework.spek2:spek-runner-junit5:2.0.19" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.10" + detektPlugins "io.github.mkohm:detekt-hint:0.1.5" + runtimeOnly 'org.jetbrains.dokka:jekyll-plugin:1.9.20' } compileKotlin { kotlinOptions { @@ -40,22 +40,27 @@ compileTestKotlin { } } +java { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 +} + detekt { config = files("$projectDir/config/detekt.yml") reports { html { - enabled = true - destination = file("build/reports/detekt/detekt.html") + required = true + outputLocation = file("build/reports/detekt/detekt.html") } xml { - enabled = true - destination = file("build/reports/detekt/detekt-checkstyle.xml") + required = true + outputLocation = file("build/reports/detekt/detekt-checkstyle.xml") } txt { - enabled = true - destination = file("build/reports/detekt/detekt.txt") + required = true + outputLocation = file("build/reports/detekt/detekt.txt") } } } @@ -66,13 +71,16 @@ test { jacocoTestReport { reports { - xml.enabled true - html.enabled false + xml.required = true + html.required = false } } -// A new dokka task for generating github flavoured markdown to the docs directory -task customDokkaTask(type: org.jetbrains.dokka.gradle.DokkaTask) { - outputFormat = "jekyll" - outputDirectory = "$projectDir/docs" +tasks.dokkaJekyll { + dokkaSourceSets { + configureEach { + outputDirectory.set(file("$projectDir/docs")) + // other configurations + } + } } diff --git a/gradle.properties b/gradle.properties index 7dee24c..73f84df 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ GROUP=io.github.mkohm POM_ARTIFACT_ID=detekt-hint POM_NAME=Detekt Hint -VERSION_NAME=0.1.6 +VERSION_NAME=0.1.7 POM_PACKAGING=jar POM_DESCRIPTION=A Detekt extension that looks for violations of programming principles. POM_INCEPTION_YEAR=2020 @@ -13,4 +13,4 @@ POM_LICENCE_NAME=The Apache Software License, Version 2.0 POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt POM_LICENCE_DIST=repo POM_DEVELOPER_ID=mkohm -POM_DEVELOPER_NAME=Marius Kohmann \ No newline at end of file +POM_DEVELOPER_NAME=Marius Kohmann diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 44e7c4d..1e2fbf0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/kotlin/io/github/mkohm/detekt/hint/rules/LackOfCohesionMethods.kt b/src/main/kotlin/io/github/mkohm/detekt/hint/rules/LackOfCohesionMethods.kt index 19d7f47..ae8aa74 100644 --- a/src/main/kotlin/io/github/mkohm/detekt/hint/rules/LackOfCohesionMethods.kt +++ b/src/main/kotlin/io/github/mkohm/detekt/hint/rules/LackOfCohesionMethods.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.psi.psiUtil.isProtected import org.jetbrains.kotlin.psi.psiUtil.isPublic import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall +import org.jetbrains.kotlin.utils.IDEAPluginsCompatibilityAPI /** * A rule that notifies if there is too much lack of cohesion. Remember to configure it correctly in the detekt.yml. @@ -178,6 +179,7 @@ class LackOfCohesionMethods(config: Config = Config.empty) : Rule(config) { /** * We need to ensure that the found reference not only have the same name as the property, but if it is a member of the correct class as well. */ + @OptIn(IDEAPluginsCompatibilityAPI::class) private fun isReferenceOfPropertyClass( reference: KtReferenceExpression, expression: KtExpression @@ -194,6 +196,7 @@ class LackOfCohesionMethods(config: Config = Config.empty) : Rule(config) { * From public, protected, initializer methods etc. Calls to private methods can exist. * We need to find all such calls and look for references there as well. */ + @OptIn(IDEAPluginsCompatibilityAPI::class) private fun getReachableExpressions( property: KtNamedDeclaration, expression: KtExpression, diff --git a/src/main/kotlin/io/github/mkohm/detekt/hint/rules/OpenClosedPrinciple.kt b/src/main/kotlin/io/github/mkohm/detekt/hint/rules/OpenClosedPrinciple.kt index 91a6efb..14c10d3 100644 --- a/src/main/kotlin/io/github/mkohm/detekt/hint/rules/OpenClosedPrinciple.kt +++ b/src/main/kotlin/io/github/mkohm/detekt/hint/rules/OpenClosedPrinciple.kt @@ -15,6 +15,7 @@ import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.calls.callUtil.getType import org.jetbrains.kotlin.types.typeUtil.isEnum +import org.jetbrains.kotlin.utils.IDEAPluginsCompatibilityAPI /** * Open closed principle rule. Only supports catching the easiest cases. Not complex when expressions, with type checking and use of enums. @@ -80,6 +81,7 @@ class OpenClosedPrinciple(config: Config = Config.empty) : Rule(config) { return allClasses.map { "`${it?.text}`" }.reduceRight { ktTypeReference, acc -> "$acc, $ktTypeReference" } } + @OptIn(IDEAPluginsCompatibilityAPI::class) private fun getEnumName(expression: KtWhenExpression): String = expression.subjectExpression?.getType(bindingContext).toString() private fun isTypeCheckWhenExpression(expression: KtWhenExpression): Boolean = entriesContainsIsExpression(expression) @@ -94,5 +96,6 @@ class OpenClosedPrinciple(config: Config = Config.empty) : Rule(config) { private fun isEnumWhenExpression(expression: KtWhenExpression): Boolean = subjectExpressionIsEnum(expression) + @OptIn(IDEAPluginsCompatibilityAPI::class) private fun subjectExpressionIsEnum(expression: KtWhenExpression): Boolean = expression.subjectExpression?.getType(bindingContext)?.isEnum() ?: false } \ No newline at end of file diff --git a/src/main/kotlin/io/github/mkohm/detekt/hint/rules/UseCompositionInsteadOfInheritance.kt b/src/main/kotlin/io/github/mkohm/detekt/hint/rules/UseCompositionInsteadOfInheritance.kt index 5cc9ef8..7cca4fc 100644 --- a/src/main/kotlin/io/github/mkohm/detekt/hint/rules/UseCompositionInsteadOfInheritance.kt +++ b/src/main/kotlin/io/github/mkohm/detekt/hint/rules/UseCompositionInsteadOfInheritance.kt @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes.SUPER_TYPE_CAL import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe +import org.jetbrains.kotlin.utils.IDEAPluginsCompatibilityAPI /** * A rule suggesting the use of composition instead of inheritance. It will help you test for Liskov Substitution. @@ -37,6 +38,7 @@ class UseCompositionInsteadOfInheritance(config: Config = Config.empty) : Rule(c Debt.TWENTY_MINS ) + @OptIn(IDEAPluginsCompatibilityAPI::class) override fun visitClass(klass: KtClass) { super.visitClass(klass) if (bindingContext == BindingContext.EMPTY) return From 47b385117bc0166cc79baaa568a5fc16f35234ed Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 25 Jan 2023 03:23:42 +0000 Subject: [PATCH 02/11] Bump git from 1.5.0 to 1.13.1 Bumps [git](https://github.com/ruby-git/ruby-git) from 1.5.0 to 1.13.1. - [Release notes](https://github.com/ruby-git/ruby-git/releases) - [Changelog](https://github.com/ruby-git/ruby-git/blob/master/CHANGELOG.md) - [Commits](https://github.com/ruby-git/ruby-git/compare/v1.5.0...v1.13.1) --- updated-dependencies: - dependency-name: git dependency-type: indirect ... Signed-off-by: dependabot[bot] --- Gemfile.lock | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1e1301b..4aeada8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,8 +1,8 @@ GEM remote: https://rubygems.org/ specs: - addressable (2.7.0) - public_suffix (>= 2.0.2, < 5.0) + addressable (2.8.1) + public_suffix (>= 2.0.2, < 6.0) ansi (1.5.0) ast (2.4.0) claide (1.0.3) @@ -13,14 +13,14 @@ GEM colored2 (3.1.2) cork (0.3.0) colored2 (~> 3.1) - danger (6.1.0) + danger (8.0.4) claide (~> 1.0) claide-plugins (>= 0.9.2) colored2 (~> 3.1) cork (~> 0.1) - faraday (~> 0.9) + faraday (>= 0.9.0, < 2.0) faraday-http-cache (~> 2.0) - git (~> 1.5) + git (~> 1.7) kramdown (~> 2.0) kramdown-parser-gfm (~> 1.0) no_proxy_fix @@ -34,14 +34,16 @@ GEM multipart-post (>= 1.2, < 3) faraday-http-cache (2.0.0) faraday (~> 0.8) - git (1.5.0) + git (1.13.1) + addressable (~> 2.8) + rchardet (~> 1.8) kramdown (2.1.0) kramdown-parser-gfm (1.1.0) kramdown (~> 2.0) multipart-post (2.1.1) nap (1.1.0) no_proxy_fix (0.1.2) - octokit (4.15.0) + octokit (4.22.0) faraday (>= 0.9) sawyer (~> 0.8.0, >= 0.5.3) oga (3.2) @@ -49,6 +51,7 @@ GEM ruby-ll (~> 2.1) open4 (1.3.4) public_suffix (4.0.3) + rchardet (1.8.0) ruby-ll (2.1.2) ansi ast From 0fd6ef7f48aa0f412a484058303022d8af7c1b01 Mon Sep 17 00:00:00 2001 From: Almas Date: Tue, 1 Oct 2024 04:58:02 +0900 Subject: [PATCH 03/11] Fixed and upgraded dependency and deprecated --- build.gradle | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index c8ac3c4..108c927 100644 --- a/build.gradle +++ b/build.gradle @@ -25,9 +25,9 @@ dependencies { testRuntimeOnly "org.junit.platform:junit-platform-launcher:1.10.0" testRuntimeOnly "org.spekframework.spek2:spek-runner-junit5:2.0.19" - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.10" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.20" detektPlugins "io.github.mkohm:detekt-hint:0.1.5" - runtimeOnly 'org.jetbrains.dokka:jekyll-plugin:1.9.20' + runtimeOnly "org.jetbrains.dokka:jekyll-plugin:1.9.20" } compileKotlin { kotlinOptions { @@ -46,22 +46,19 @@ java { } detekt { - config = files("$projectDir/config/detekt.yml") + config.setFrom("$projectDir/config/detekt.yml") +} + +tasks.named("detekt").configure { reports { - html { - required = true - outputLocation = file("build/reports/detekt/detekt.html") - } + html.required.set(true) + html.outputLocation.set(file("build/reports/detekt/detekt-checkstyle.xml")) - xml { - required = true - outputLocation = file("build/reports/detekt/detekt-checkstyle.xml") - } + xml.required.set(true) + xml.outputLocation.set(file("build/reports/detekt/detekt-checkstyle.xml")) - txt { - required = true - outputLocation = file("build/reports/detekt/detekt.txt") - } + txt.required.set(true) + txt.outputLocation.set(file("build/reports/detekt/detekt-checkstyle.xml")) } } From b73f10a14cee82695e28838e9ee3849120a3a91b Mon Sep 17 00:00:00 2001 From: Almas Date: Tue, 1 Oct 2024 04:58:36 +0900 Subject: [PATCH 04/11] Fixed code style --- .../io/github/mkohm/detekt/hint/rules/LackOfCohesionMethods.kt | 2 +- .../io/github/mkohm/detekt/hint/rules/OpenClosedPrinciple.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/io/github/mkohm/detekt/hint/rules/LackOfCohesionMethods.kt b/src/main/kotlin/io/github/mkohm/detekt/hint/rules/LackOfCohesionMethods.kt index ae8aa74..ebd7d20 100644 --- a/src/main/kotlin/io/github/mkohm/detekt/hint/rules/LackOfCohesionMethods.kt +++ b/src/main/kotlin/io/github/mkohm/detekt/hint/rules/LackOfCohesionMethods.kt @@ -227,7 +227,7 @@ class LackOfCohesionMethods(config: Config = Config.empty) : Rule(config) { for (reachableExpression in reachableExpressionsFromThisExpressions) { // Memoize the results of the calculation to speed things up - var newResult = listOf() + var newResult: List if (memoizedResults.containsKey(reachableExpression)) { // After each call we put the result into the map, we therefore know that the key exists. diff --git a/src/main/kotlin/io/github/mkohm/detekt/hint/rules/OpenClosedPrinciple.kt b/src/main/kotlin/io/github/mkohm/detekt/hint/rules/OpenClosedPrinciple.kt index 14c10d3..38e13e5 100644 --- a/src/main/kotlin/io/github/mkohm/detekt/hint/rules/OpenClosedPrinciple.kt +++ b/src/main/kotlin/io/github/mkohm/detekt/hint/rules/OpenClosedPrinciple.kt @@ -74,7 +74,7 @@ class OpenClosedPrinciple(config: Config = Config.empty) : Rule(config) { ) } - private fun getClassNames(expression: KtWhenExpression): String? { + private fun getClassNames(expression: KtWhenExpression): String { val allClasses = expression.collectDescendantsOfType().map { it.typeReference } + expression.collectDescendantsOfType().map { it.typeReference } From babe77b1f0ef12bf590b4be621799e9263abd7c5 Mon Sep 17 00:00:00 2001 From: Almas Date: Tue, 1 Oct 2024 05:34:46 +0900 Subject: [PATCH 05/11] Fixed NullPointerException with cast to KtNamedFunction Caused by: java.lang.NullPointerException: null cannot be cast to non-null type org.jetbrains.kotlin.psi.KtNamedFunction --- .../io/github/mkohm/detekt/hint/rules/LackOfCohesionMethods.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/io/github/mkohm/detekt/hint/rules/LackOfCohesionMethods.kt b/src/main/kotlin/io/github/mkohm/detekt/hint/rules/LackOfCohesionMethods.kt index ebd7d20..8cd9f6e 100644 --- a/src/main/kotlin/io/github/mkohm/detekt/hint/rules/LackOfCohesionMethods.kt +++ b/src/main/kotlin/io/github/mkohm/detekt/hint/rules/LackOfCohesionMethods.kt @@ -209,6 +209,8 @@ class LackOfCohesionMethods(config: Config = Config.empty) : Rule(config) { (it.getResolvedCall(bindingContext)?.resultingDescriptor?.findPsi() as KtNamedFunction).bodyExpression } catch (e: java.lang.ClassCastException) { null + } catch (e: java.lang.NullPointerException) { + null } }.filter { !foundExpressions.contains(it) && isCalleeInPropertyClass( From 257d9574f1bd7a2633016c5090fc054989d1eeb9 Mon Sep 17 00:00:00 2001 From: Almas Date: Tue, 1 Oct 2024 05:42:26 +0900 Subject: [PATCH 06/11] Updated README.md CLI run make easy No need to build entire detekt. It's better to use released jar. --- README.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2ab11e4..57f6c75 100644 --- a/README.md +++ b/README.md @@ -101,14 +101,19 @@ Having trouble? Please [create an issue](https://github.com/Mkohm/detekt-hint/is ### With the command line If you only want to do some analysis on your code without the power of Danger commenting on your PR you can use the tool from the command line. You must first clone detekt and detekt-hint repositories, and then build the required jars: ``` -git clone https://github.com/Mkohm/detekt-hint && git clone https://github.com/arturbosch/detekt && cd detekt-hint && ./gradlew jar && cd ../detekt/ && ./gradlew build shadowJar && cd .. +git clone https://github.com/Mkohm/detekt-hint +cd detekt-hint +./gradlew jar ``` -Use the command line utility: + +Download detekt-cli-[version]-all.jar file from and put it to the directory detekt-hint/build/libs. + +Then, you can use the command line utility like below: ```bash -java -jar detekt/detekt-cli/build/libs/detekt-cli-[version]-all.jar --plugins detekt-hint/build/libs/detekt-hint-[version].jar --config detekt-hint/config/detekt.yml --classpath --input +java -jar detekt-hint/build/libs/detekt-cli-[version]-all.jar --plugins detekt-hint/build/libs/detekt-hint-[version].jar --config detekt-hint/config/detekt.yml --classpath --input ``` For example: ```bash -java -jar detekt/detekt-cli/build/libs/detekt-cli-1.5.0-all.jar --plugins detekt-hint/build/libs/detekt-hint-0.0.2.jar --config detekt-hint/config/detekt.yml --classpath detekt-hint/ --input detekt-hint/ +java -jar detekt-hint/build/libs/detekt-cli-1.5.0-all.jar --plugins detekt-hint/build/libs/detekt-hint-0.0.2.jar --config detekt-hint/config/detekt.yml --classpath detekt-hint/ --input detekt-hint/ ``` Remember to enter the [latest](https://mvnrepository.com/artifact/io.gitlab.arturbosch.detekt/detekt-cli) detekt-cli version, the [latest](https://mvnrepository.com/artifact/io.github.mkohm/detekt-hint) detekt-hint version and the path to your classpath and source code. Also, make sure that the detekt.yml you are using contains the unique package name in the configuration for the UseCompositionInsteadOfInheritance rule. From 65524b9cc509c353f5a72a6a93a491f62c6a03db Mon Sep 17 00:00:00 2001 From: Almas Date: Tue, 1 Oct 2024 11:52:34 +0900 Subject: [PATCH 07/11] README update, gitignore update, re-organize config yaml --- .gitignore | 1 + README.md | 95 ++++++++++++++++-------- config/detekt-airthings.yml | 20 ----- config/{detekt-detekt.yml => detekt.yml} | 0 4 files changed, 67 insertions(+), 49 deletions(-) delete mode 100644 config/detekt-airthings.yml rename config/{detekt-detekt.yml => detekt.yml} (100%) diff --git a/.gitignore b/.gitignore index 78e1e55..3bbe4cb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ out/ .idea .DS_Store .gradle/ +local.properties diff --git a/README.md b/README.md index 57f6c75..d31afb2 100644 --- a/README.md +++ b/README.md @@ -1,52 +1,69 @@ -
+# detekt-hint (clone) + +(Cloned from Github) -# detekt-hint (Attention: Looking for developers) Detection of design principle violations in Kotlin added as comments on pull requests. ## [Getting started](#getting-started) | :checkered_flag: [Roadmap](#upcoming-features) | :thought_balloon: [Ask a question](https://github.com/Mkohm/detekt-hint/issues/new) | :book: [Documentation](https://mkohm.github.io/detekt-hint/docs/) - - [![Maintainability](https://api.codeclimate.com/v1/badges/307995daba5f21506f4d/maintainability)](https://codeclimate.com/github/Mkohm/detekt-hint/maintainability) [![codecov](https://codecov.io/gh/Mkohm/detekt-hint/branch/master/graph/badge.svg)](https://codecov.io/gh/Mkohm/detekt-hint) [![Build Status](https://travis-ci.com/Mkohm/detekt-hint.svg?branch=master)](https://travis-ci.com/Mkohm/detekt-hint) [ ![Download](https://api.bintray.com/packages/bintray/jcenter/io.github.mkohm%3Adetekt-hint/images/download.svg) ](https://bintray.com/bintray/jcenter/io.github.mkohm%3Adetekt-hint/_latestVersion) [![Kotlinlang slack](https://img.shields.io/static/v1?label=kotlinlang&message=detekt-hint&color=brightgreen&logo=slack&style=flat-square)](https://app.slack.com/client/T09229ZC6/C012ZSM6L1J) [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) - ![ucih](images/demo.png) -
- -detekt-hint is a plugin for [detekt](https://github.com/arturbosch/detekt) that includes detection of violation of programming principles. Since such violations are hard to detect with low false-positive rates, detekt-hint will provide hints during QA, minimizing noise during development. The idea is that a higher false-positive rate can be accepted if the detection could be of high value, and is easy to ignore. Detections on the architectural level of code is therefore most likely to provide value. +detekt-hint is a plugin for [detekt](https://github.com/arturbosch/detekt) that includes detection +of violation of programming principles. Since such violations are hard to detect with low +false-positive rates, detekt-hint will provide hints during QA, minimizing noise during development. +The idea is that a higher false-positive rate can be accepted if the detection could be of high +value, and is easy to ignore. Detections on the architectural level of code is therefore most likely +to provide value. -Through integration with [Danger](https://github.com/danger/danger) comments are added to the PR. Getting feedback directly on the PR makes it easy to ignore possible false-positives. Comments also include context and tips, making it easier for the developer to make the correct decisions. +Through integration with [Danger](https://github.com/danger/danger) comments are added to the PR. +Getting feedback directly on the PR makes it easy to ignore possible false-positives. Comments also +include context and tips, making it easier for the developer to make the correct decisions. -Contributions are very much welcome and if you like the project - help me out with a :star:. Especially help in which rules to implement, how to implement them and how to reduce the false-positives. +Contributions are very much welcome and if you like the project - help me out with a :star:. +Especially help in which rules to implement, how to implement them and how to reduce the +false-positives. ## Currently supported detections -:white_check_mark: Use composition instead of inheritance - Will help developer ensure Liskov Substitution Principle is not violated. Will not report if you inherit from third-party libraries. + +:white_check_mark: Use composition instead of inheritance - Will help developer ensure Liskov +Substitution Principle is not violated. Will not report if you inherit from third-party libraries. :white_check_mark: Lack Of Cohesion of Methods - Notifies you if the LCOM value is too high. -:white_check_mark: Interface Segregation Principles - Notifies you if you implement methods that the class does not need. +:white_check_mark: Interface Segregation Principles - Notifies you if you implement methods that the +class does not need. -:white_check_mark: Open-Closed Principle - This rule reports use of switching on enums and classes, which may be a sign of violation the open closed principle. +:white_check_mark: Open-Closed Principle - This rule reports use of switching on enums and classes, +which may be a sign of violation the open closed principle. ### Interface Segregation Principle + ![lcom](images/comment_isp.png) ### Single Responsibility Principle + ![lcom](images/comment_lackOfCohesion.png) ### Open-Closed Principle + ![lcom](images/comment_ocp2.png) ## Using detekt-hint -If you just want to analyze some code without bothering with the Danger integration (which really defeats the purpose of the tool) head to the [command line section](#With-the-command-line). + +If you just want to analyze some code without bothering with the Danger integration (which really +defeats the purpose of the tool) head to the [command line section](#With-the-command-line). ### With Github Actions -1. Configure a detekt-hint-config.yml to include detekt-hint rules and put it in a folder called "config" in your root project folder. + +1. Configure a detekt-hint-config.yml to include detekt-hint rules and put it in a folder called " + config" in your root project folder. config/detekt-hint-config.yml + ```yml detekt-hint: UseCompositionInsteadOfInheritance: @@ -56,16 +73,18 @@ detekt-hint: active: true threshold: "0.8" InterfaceSegregationPrinciple: - active: true + active: true OpenClosedPrinciple: - active: true + active: true ``` -Make sure you enter your unique package name in the configuration for the UseCompositionInsteadOfInheritance rule. +Make sure you enter your unique package name in the configuration for the +UseCompositionInsteadOfInheritance rule. -2. Create a github action using the detekt-hint docker action. +2. Create a github action using the detekt-hint docker action. .github/workflows/detekt-hint.yml + ```yml name: detekt hint @@ -78,16 +97,16 @@ jobs: gradle: strategy: matrix: - os: [ubuntu-latest] - jdk: [11] + os: [ ubuntu-latest ] + jdk: [ 11 ] runs-on: ${{ matrix.os }} if: ${{ !contains(github.event.head_commit.message, 'detekt hint skip') }} env: - JDK_VERSION: ${{ matrix.jdk }} + JDK_VERSION: ${{ matrix.jdk }} steps: - name: Checkout Repo uses: actions/checkout@v2 - + - name: Run detekt hint uses: mkohm/detekt-hint-action@v1.1 with: @@ -96,24 +115,42 @@ jobs: 3. Create a PR and see detekt-hint run as a separate action. -Having trouble? Please [create an issue](https://github.com/Mkohm/detekt-hint/issues/new) or contact me on the kotlinlang Slack (username: mkohm), and i will help you out. +Having trouble? Please [create an issue](https://github.com/Mkohm/detekt-hint/issues/new) or contact +me on the kotlinlang Slack (username: mkohm), and i will help you out. ### With the command line -If you only want to do some analysis on your code without the power of Danger commenting on your PR you can use the tool from the command line. You must first clone detekt and detekt-hint repositories, and then build the required jars: + +If you only want to do some analysis on your code without the power of Danger commenting on your PR +you can use the tool from the command line. You must first clone detekt and detekt-hint +repositories, and then build the required jars: + ``` git clone https://github.com/Mkohm/detekt-hint cd detekt-hint ./gradlew jar ``` -Download detekt-cli-[version]-all.jar file from and put it to the directory detekt-hint/build/libs. +Download detekt-cli-[version]-all.jar file from and put +it to the directory detekt-hint/build/libs. Then, you can use the command line utility like below: + ```bash -java -jar detekt-hint/build/libs/detekt-cli-[version]-all.jar --plugins detekt-hint/build/libs/detekt-hint-[version].jar --config detekt-hint/config/detekt.yml --classpath --input +java -jar /detekt-cli-[version]-all.jar --plugins /detekt-hint-[version].jar --config /detekt.yml --classpath --input --report txt:/detekt-hint.txt --report xml:/detekt-hint.xml --report html:/detekt-hint.html ``` + For example: + ```bash -java -jar detekt-hint/build/libs/detekt-cli-1.5.0-all.jar --plugins detekt-hint/build/libs/detekt-hint-0.0.2.jar --config detekt-hint/config/detekt.yml --classpath detekt-hint/ --input detekt-hint/ +java -jar detekt-hint/build/libs/detekt-cli-1.5.0-all.jar --plugins detekt-hint/build/libs/detekt-hint.jar --config detekt-hint/config/detekt.yml --classpath detekt-hint/ --input detekt-hint/ --report txt:build/reports/detekt-hint.txt --report xml:build/reports/detekt-hint.xml --report html:build/reports/detekt-hint.html ``` -Remember to enter the [latest](https://mvnrepository.com/artifact/io.gitlab.arturbosch.detekt/detekt-cli) detekt-cli version, the [latest](https://mvnrepository.com/artifact/io.github.mkohm/detekt-hint) detekt-hint version and the path to your classpath and source code. Also, make sure that the detekt.yml you are using contains the unique package name in the configuration for the UseCompositionInsteadOfInheritance rule. + +Remember to enter +the [latest](https://mvnrepository.com/artifact/io.gitlab.arturbosch.detekt/detekt-cli) detekt-cli +version, the [latest](https://mvnrepository.com/artifact/io.github.mkohm/detekt-hint) detekt-hint +version and the path to your classpath and source code. Also, make sure that the detekt.yml you are +using contains the unique package name in the configuration for the +UseCompositionInsteadOfInheritance rule. + +You can find more information from the page "Run detekt using Command Line +Interface" (). diff --git a/config/detekt-airthings.yml b/config/detekt-airthings.yml deleted file mode 100644 index c94bf84..0000000 --- a/config/detekt-airthings.yml +++ /dev/null @@ -1,20 +0,0 @@ -build: - weights: - # complexity: 2 - # LongParameterList: 1 - # style: 1 - # comments: 1 - detekt-hint: 0 - -detekt-hint: - UseCompositionInsteadOfInheritance: - active: true - yourUniquePackageName: "com.airthings" - LackOfCohesionMethods: - active: true - threshold: "0.8" - InterfaceSegregationPrinciple: - active: true - OpenClosedPrinciple: - active: true - diff --git a/config/detekt-detekt.yml b/config/detekt.yml similarity index 100% rename from config/detekt-detekt.yml rename to config/detekt.yml From f2ddddb1b8ec2560fc9f4d1b00766b36b5480dfd Mon Sep 17 00:00:00 2001 From: Almas Date: Tue, 1 Oct 2024 11:54:40 +0900 Subject: [PATCH 08/11] Fixed report paths --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 108c927..593ae4b 100644 --- a/build.gradle +++ b/build.gradle @@ -52,13 +52,13 @@ detekt { tasks.named("detekt").configure { reports { html.required.set(true) - html.outputLocation.set(file("build/reports/detekt/detekt-checkstyle.xml")) + html.outputLocation.set(file("build/reports/detekt/detekt-hint.html")) xml.required.set(true) - xml.outputLocation.set(file("build/reports/detekt/detekt-checkstyle.xml")) + xml.outputLocation.set(file("build/reports/detekt/detekt-hint.xml")) txt.required.set(true) - txt.outputLocation.set(file("build/reports/detekt/detekt-checkstyle.xml")) + txt.outputLocation.set(file("build/reports/detekt/detekt-hint.txt")) } } From 397a4b37fafe3168453632a025b6c13c84a42b12 Mon Sep 17 00:00:00 2001 From: Almas Date: Tue, 1 Oct 2024 11:55:36 +0900 Subject: [PATCH 09/11] Added dependency repositories for fix build issue --- build.gradle | 2 ++ settings.gradle | 7 +++++++ 2 files changed, 9 insertions(+) create mode 100644 settings.gradle diff --git a/build.gradle b/build.gradle index 593ae4b..db9bb4a 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,8 @@ plugins { } repositories { + gradlePluginPortal() + google() mavenCentral() } diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..492070d --- /dev/null +++ b/settings.gradle @@ -0,0 +1,7 @@ +pluginManagement { + repositories { + gradlePluginPortal() + google() + mavenCentral() + } +} From e87fb2a7094b2df0e68e7aac14e5e93c85d0fdc0 Mon Sep 17 00:00:00 2001 From: Almas Date: Tue, 1 Oct 2024 11:58:13 +0900 Subject: [PATCH 10/11] Revert README header --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index d31afb2..51e9bcb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,4 @@ -# detekt-hint (clone) - -(Cloned from Github) +# detekt-hint (Attention: Looking for developers) Detection of design principle violations in Kotlin added as comments on pull requests. From 39080f0d2168e336b3cb483a85a6dd8e74e67ef5 Mon Sep 17 00:00:00 2001 From: Almas Date: Tue, 1 Oct 2024 13:38:44 +0900 Subject: [PATCH 11/11] Added Licence file. It was there in gradle.properties. --- LICENSE | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License.