diff --git a/Dangerfile b/Dangerfile new file mode 100755 index 0000000..0e9da1c --- /dev/null +++ b/Dangerfile @@ -0,0 +1,8 @@ +kotlin_detekt.severity = "warning" +kotlin_detekt.gradle_task = "detektVerification" +kotlin_detekt.report_file = "app/build/reports/detekt/detekt-checkstyle.xml" +kotlin_detekt.detekt(inline_mode: true) + +checkstyle_format.base_path = Dir.pwd +checkstyle_format.gradle_task = "ktlintVerification" +checkstyle_format.report 'app/build/reports/ktlint/ktlint-checkstyle.xml' \ No newline at end of file diff --git a/Gemfile b/Gemfile index 10a87ad..8b22f47 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ -# frozen_string_literal: true - source "https://rubygems.org" git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } -gem 'danger' \ No newline at end of file +gem "danger", "~> 7.0.0" +gem "danger-kotlin_detekt", :github => "sp4wna1/danger-kotlin_detekt" +gem "danger-checkstyle_format", :github => "sp4wna1/danger-checkstyle_format" \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 104a64b..a59eb26 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,8 +1,26 @@ +GIT + remote: https://github.com/sp4wna1/danger-checkstyle_format + revision: 3df9a0ab7ee1cdc6ec0901f3cb2a67f60a758dc4 + specs: + danger-checkstyle_format (0.1.0) + danger-plugin-api (~> 1.0) + ox (~> 2.0) + +GIT + remote: https://github.com/sp4wna1/danger-kotlin_detekt + revision: b45824e4bc8e02feb4f3fc78cb7e2741cb7fcdb5 + specs: + danger-kotlin_detekt (0.0.3) + danger-plugin-api (~> 1.0) + oga + GEM remote: https://rubygems.org/ specs: addressable (2.7.0) public_suffix (>= 2.0.2, < 5.0) + ansi (1.5.0) + ast (2.4.0) claide (1.0.3) claide-plugins (0.9.2) cork @@ -11,26 +29,29 @@ GEM colored2 (3.1.2) cork (0.3.0) colored2 (~> 3.1) - danger (6.3.2) + danger (7.0.1) 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.6) + git (~> 1.7) kramdown (~> 2.0) kramdown-parser-gfm (~> 1.0) no_proxy_fix octokit (~> 4.7) terminal-table (~> 1) - faraday (0.17.3) + danger-plugin-api (1.0.0) + danger (> 2.0) + faraday (1.0.1) multipart-post (>= 1.2, < 3) - faraday-http-cache (2.1.0) - faraday (~> 0.8) - git (1.6.0) + faraday-http-cache (2.2.0) + faraday (>= 0.8) + git (1.7.0) rchardet (~> 1.8) - kramdown (2.1.0) + kramdown (2.2.1) + rexml kramdown-parser-gfm (1.1.0) kramdown (~> 2.0) multipart-post (2.1.1) @@ -39,9 +60,17 @@ GEM octokit (4.18.0) faraday (>= 0.9) sawyer (~> 0.8.0, >= 0.5.3) + oga (3.2) + ast + ruby-ll (~> 2.1) open4 (1.3.4) - public_suffix (4.0.4) + ox (2.13.2) + public_suffix (4.0.5) rchardet (1.8.0) + rexml (3.2.4) + ruby-ll (2.1.2) + ansi + ast sawyer (0.8.2) addressable (>= 2.3.5) faraday (> 0.8, < 2.0) @@ -53,7 +82,9 @@ PLATFORMS ruby DEPENDENCIES - danger + danger (~> 7.0.0) + danger-checkstyle_format! + danger-kotlin_detekt! BUNDLED WITH 2.1.4 diff --git a/app/src/androidTest/java/br/com/prado/staticanalysis/ExampleInstrumentedTest.kt b/app/src/androidTest/java/br/com/prado/staticanalysis/ExampleInstrumentedTest.kt index 9c29902..a3757de 100644 --- a/app/src/androidTest/java/br/com/prado/staticanalysis/ExampleInstrumentedTest.kt +++ b/app/src/androidTest/java/br/com/prado/staticanalysis/ExampleInstrumentedTest.kt @@ -1,13 +1,11 @@ package br.com.prado.staticanalysis -import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 - +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.* import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.* - /** * Instrumented test, which will execute on an Android device. * diff --git a/app/src/main/java/br/com/prado/staticanalysis/TestDetekt.kt b/app/src/main/java/br/com/prado/staticanalysis/TestDetekt.kt index 22e1978..f791550 100644 --- a/app/src/main/java/br/com/prado/staticanalysis/TestDetekt.kt +++ b/app/src/main/java/br/com/prado/staticanalysis/TestDetekt.kt @@ -2,6 +2,4 @@ package br.com.prado.staticanalysis import java.util.* -class TestDetektErro { - -} \ No newline at end of file +class TestDetektErro diff --git a/app/src/main/java/br/com/prado/staticanalysis/TestKtlint.kt b/app/src/main/java/br/com/prado/staticanalysis/TestKtlint.kt index a52346a..efafa91 100644 --- a/app/src/main/java/br/com/prado/staticanalysis/TestKtlint.kt +++ b/app/src/main/java/br/com/prado/staticanalysis/TestKtlint.kt @@ -2,16 +2,15 @@ package br.com.prado.staticanalysis import java.util.* -class TestKtlint { +class TestKtlint -} +class A -class A {} +class B +fun G() {} -class B {} - -fun f(): Unit {} +fun f() {} /* OUTPUT da Task Gradle @@ -24,4 +23,4 @@ staticanalysis/TestKtlint.kt:11:1: Needless blank line(s) staticanalysis/TestKtlint.kt:12:9: Unnecessary block ("{}") staticanalysis/TestKtlint.kt:14:10: Unnecessary "Unit" return type - */ \ No newline at end of file + */ diff --git a/app/src/test/java/br/com/prado/staticanalysis/ExampleUnitTest.kt b/app/src/test/java/br/com/prado/staticanalysis/ExampleUnitTest.kt index be6ed0e..b096c7d 100644 --- a/app/src/test/java/br/com/prado/staticanalysis/ExampleUnitTest.kt +++ b/app/src/test/java/br/com/prado/staticanalysis/ExampleUnitTest.kt @@ -1,8 +1,7 @@ package br.com.prado.staticanalysis -import org.junit.Test - import org.junit.Assert.* +import org.junit.Test /** * Example local unit test, which will execute on the development machine (host). diff --git a/arquivosModificados.sh b/arquivosModificados.sh deleted file mode 100755 index c16bd50..0000000 --- a/arquivosModificados.sh +++ /dev/null @@ -1,10 +0,0 @@ -declare -a myArray=$(echo $(git diff $1 --diff-filter=d --name-only --relative | grep '\.kt[s"]\?$')) -repo_root=$(echo $(pwd)) -last_occurrence=$(echo ${myArray} | sed 's#.* ##g') -for file in ${myArray}; do -if [[ "$file" == "$last_occurrence" || $2 == 'ktlint' ]]; then -echo ${repo_root}/${file}; -else -echo ${repo_root}/${file},; -fi -done \ No newline at end of file diff --git a/config/detekt/detekt-config.yml b/config/detekt/detekt-config.yml index 707612e..d1d04b8 100644 --- a/config/detekt/detekt-config.yml +++ b/config/detekt/detekt-config.yml @@ -1,5 +1,5 @@ build: - maxIssues: 0 + maxIssues: 10 excludeCorrectable: false weights: # complexity: 2 @@ -132,6 +132,7 @@ empty-blocks: active: true EmptyFunctionBlock: active: true + threshold: 4 ignoreOverridden: false EmptyIfBlock: active: true @@ -343,6 +344,7 @@ naming: functionPattern: '^([a-z$][a-zA-Z$0-9]*)|(`.*`)$' excludeClassPattern: '$^' ignoreOverridden: true + threshold: 4 FunctionParameterNaming: active: true excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt" @@ -355,6 +357,7 @@ naming: MatchingDeclarationName: active: true mustBeFirst: true + threshold: 4 MemberNameEqualsClassName: active: true ignoreOverridden: true diff --git a/config/detekt/detekt.gradle b/config/detekt/detekt.gradle index e53fbd3..350e33c 100644 --- a/config/detekt/detekt.gradle +++ b/config/detekt/detekt.gradle @@ -6,28 +6,16 @@ dependencies { detekt libraries.detekt } -def static execute(cmd, output) { - cmd.execute().waitForProcessOutput(output, System.err) -} - -task detektVerification(group: "verification") { +task detektVerification(type: JavaExec, group: "verification") { description = "Check Kotlin code smells, code complexity based on detekt-config.yml." - doFirst { - new ByteArrayOutputStream().withStream { output -> + main = "io.gitlab.arturbosch.detekt.cli.Main" + classpath = configurations.detekt - execute("./arquivosModificados.sh origin/master detekt", output) - - if (!"$output".isEmpty()) { - javaexec { - main = "io.gitlab.arturbosch.detekt.cli.Main" - classpath = configurations.detekt - def dir = "$rootDir/config/detekt" - def config = "$dir/detekt-config.yml" - def params = ["-i", "$output", "-c", config] - args(params) - } - } - } - } -} \ No newline at end of file + def input = "$projectDir" + def dir = "$rootDir/config/detekt" + def config = "$dir/detekt-config.yml" + def report = "xml:$buildDir/reports/detekt/detekt-checkstyle.xml" + def params = ["-i", input, "-c", config, "-r", report] + args(params) +} diff --git a/config/ktlint/ktlint.gradle b/config/ktlint/ktlint.gradle index 61a00ec..a88e834 100644 --- a/config/ktlint/ktlint.gradle +++ b/config/ktlint/ktlint.gradle @@ -4,26 +4,13 @@ configurations { dependencies { ktlint libraries.ktlint } -def static execute(cmd, output) { - cmd.execute().waitForProcessOutput(output, System.err) -} -task ktlintVerification(group: "verification") { - description = "Check Kotlin code style." - doFirst { - new ByteArrayOutputStream().withStream { output -> - execute("./arquivosModificados.sh origin/master ktlint", output) +task ktlintVerification(type: JavaExec, group: "verification") { + description = "Check Kotlin code style." + classpath = configurations.ktlint + main = "com.pinterest.ktlint.Main" + args "-F", "src/**/*.kt", "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/reports/ktlint/ktlint-checkstyle.xml" - if (!"$output".isEmpty()) { - javaexec { - classpath = configurations.ktlint - main = "com.pinterest.ktlint.Main" - args "$output".split("\n") - } - } else { - print("What") - } - } - } + ignoreExitValue true } \ No newline at end of file