mirror of
https://github.com/jlengrand/detekt.git
synced 2026-03-10 08:11:23 +00:00
Move processors to metrics module (#2725)
* Move metric processors to metrics module * Remove obsolete test files in core resources * Inline metric test files
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
package io.gitlab.arturbosch.detekt.cli.console
|
||||
|
||||
import io.gitlab.arturbosch.detekt.api.Detektion
|
||||
import io.gitlab.arturbosch.detekt.core.processors.commentLinesKey
|
||||
import io.gitlab.arturbosch.detekt.core.processors.complexityKey
|
||||
import io.gitlab.arturbosch.detekt.core.processors.linesKey
|
||||
import io.gitlab.arturbosch.detekt.core.processors.logicalLinesKey
|
||||
import io.gitlab.arturbosch.detekt.core.processors.sourceLinesKey
|
||||
import io.github.detekt.metrics.processors.commentLinesKey
|
||||
import io.github.detekt.metrics.processors.complexityKey
|
||||
import io.github.detekt.metrics.processors.linesKey
|
||||
import io.github.detekt.metrics.processors.logicalLinesKey
|
||||
import io.github.detekt.metrics.processors.sourceLinesKey
|
||||
|
||||
class ComplexityMetric(detektion: Detektion) {
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
io.gitlab.arturbosch.detekt.cli.DetektProgressListener
|
||||
io.gitlab.arturbosch.detekt.core.processors.KtFileCountProcessor
|
||||
io.gitlab.arturbosch.detekt.core.processors.PackageCountProcessor
|
||||
io.gitlab.arturbosch.detekt.core.processors.ClassCountProcessor
|
||||
io.gitlab.arturbosch.detekt.core.processors.FunctionCountProcessor
|
||||
io.gitlab.arturbosch.detekt.core.processors.PropertyCountProcessor
|
||||
io.gitlab.arturbosch.detekt.core.processors.ProjectComplexityProcessor
|
||||
io.gitlab.arturbosch.detekt.core.processors.ProjectLLOCProcessor
|
||||
io.gitlab.arturbosch.detekt.core.processors.ProjectCLOCProcessor
|
||||
io.gitlab.arturbosch.detekt.core.processors.ProjectLOCProcessor
|
||||
io.gitlab.arturbosch.detekt.core.processors.ProjectSLOCProcessor
|
||||
io.github.detekt.metrics.processors.KtFileCountProcessor
|
||||
io.github.detekt.metrics.processors.PackageCountProcessor
|
||||
io.github.detekt.metrics.processors.ClassCountProcessor
|
||||
io.github.detekt.metrics.processors.FunctionCountProcessor
|
||||
io.github.detekt.metrics.processors.PropertyCountProcessor
|
||||
io.github.detekt.metrics.processors.ProjectComplexityProcessor
|
||||
io.github.detekt.metrics.processors.ProjectLLOCProcessor
|
||||
io.github.detekt.metrics.processors.ProjectCLOCProcessor
|
||||
io.github.detekt.metrics.processors.ProjectLOCProcessor
|
||||
io.github.detekt.metrics.processors.ProjectSLOCProcessor
|
||||
io.gitlab.arturbosch.detekt.rules.documentation.LicenceHeaderLoaderExtension
|
||||
|
||||
@@ -41,7 +41,7 @@ class FileProcessorLocatorSpec : Spek({
|
||||
})
|
||||
|
||||
private fun getProcessorClasses(): List<Class<out FileProcessListener>> {
|
||||
return Reflections("io.gitlab.arturbosch.detekt.core.processors")
|
||||
return Reflections("io.github.detekt.metrics.processors")
|
||||
.getSubTypesOf(FileProcessListener::class.java)
|
||||
.filter { !Modifier.isAbstract(it.modifiers) }
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ package io.gitlab.arturbosch.detekt.cli.console
|
||||
|
||||
import io.gitlab.arturbosch.detekt.api.Detektion
|
||||
import io.gitlab.arturbosch.detekt.cli.createFinding
|
||||
import io.gitlab.arturbosch.detekt.core.processors.commentLinesKey
|
||||
import io.gitlab.arturbosch.detekt.core.processors.complexityKey
|
||||
import io.gitlab.arturbosch.detekt.core.processors.linesKey
|
||||
import io.gitlab.arturbosch.detekt.core.processors.logicalLinesKey
|
||||
import io.gitlab.arturbosch.detekt.core.processors.sourceLinesKey
|
||||
import io.github.detekt.metrics.processors.commentLinesKey
|
||||
import io.github.detekt.metrics.processors.complexityKey
|
||||
import io.github.detekt.metrics.processors.linesKey
|
||||
import io.github.detekt.metrics.processors.logicalLinesKey
|
||||
import io.github.detekt.metrics.processors.sourceLinesKey
|
||||
import io.gitlab.arturbosch.detekt.test.TestDetektion
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.spekframework.spek2.Spek
|
||||
|
||||
@@ -3,11 +3,11 @@ package io.gitlab.arturbosch.detekt.cli.console
|
||||
import io.gitlab.arturbosch.detekt.api.Detektion
|
||||
import io.gitlab.arturbosch.detekt.cli.createFinding
|
||||
import io.gitlab.arturbosch.detekt.core.DetektResult
|
||||
import io.gitlab.arturbosch.detekt.core.processors.commentLinesKey
|
||||
import io.gitlab.arturbosch.detekt.core.processors.complexityKey
|
||||
import io.gitlab.arturbosch.detekt.core.processors.linesKey
|
||||
import io.gitlab.arturbosch.detekt.core.processors.logicalLinesKey
|
||||
import io.gitlab.arturbosch.detekt.core.processors.sourceLinesKey
|
||||
import io.github.detekt.metrics.processors.commentLinesKey
|
||||
import io.github.detekt.metrics.processors.complexityKey
|
||||
import io.github.detekt.metrics.processors.linesKey
|
||||
import io.github.detekt.metrics.processors.logicalLinesKey
|
||||
import io.github.detekt.metrics.processors.sourceLinesKey
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
|
||||
@@ -6,11 +6,11 @@ import io.gitlab.arturbosch.detekt.api.ProjectMetric
|
||||
import io.gitlab.arturbosch.detekt.cli.createEntity
|
||||
import io.gitlab.arturbosch.detekt.cli.createFinding
|
||||
import io.gitlab.arturbosch.detekt.cli.createIssue
|
||||
import io.gitlab.arturbosch.detekt.core.processors.commentLinesKey
|
||||
import io.gitlab.arturbosch.detekt.core.processors.complexityKey
|
||||
import io.gitlab.arturbosch.detekt.core.processors.linesKey
|
||||
import io.gitlab.arturbosch.detekt.core.processors.logicalLinesKey
|
||||
import io.gitlab.arturbosch.detekt.core.processors.sourceLinesKey
|
||||
import io.github.detekt.metrics.processors.commentLinesKey
|
||||
import io.github.detekt.metrics.processors.complexityKey
|
||||
import io.github.detekt.metrics.processors.linesKey
|
||||
import io.github.detekt.metrics.processors.logicalLinesKey
|
||||
import io.github.detekt.metrics.processors.sourceLinesKey
|
||||
import io.gitlab.arturbosch.detekt.core.whichDetekt
|
||||
import io.gitlab.arturbosch.detekt.test.TestDetektion
|
||||
import io.github.detekt.test.utils.createTempFileForTest
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
|
||||
import io.gitlab.arturbosch.detekt.core.path
|
||||
import io.github.detekt.test.utils.compileForTest
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
import java.nio.file.Path
|
||||
|
||||
class ComplexityVisitorTest : Spek({
|
||||
describe("something") {
|
||||
|
||||
it("complexityOfDefaultCaseIsOne") {
|
||||
val path = path.resolve("Default.kt")
|
||||
|
||||
val mcc = calcComplexity(path)
|
||||
|
||||
assertThat(mcc).isEqualTo(0)
|
||||
}
|
||||
|
||||
it("complexityOfComplexAndNestedClass") {
|
||||
val path = path.resolve("ComplexClass.kt")
|
||||
|
||||
val mcc = calcComplexity(path)
|
||||
|
||||
assertThat(mcc).isEqualTo(44)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
private fun calcComplexity(path: Path) = with(compileForTest(path)) {
|
||||
accept(ComplexityVisitor())
|
||||
getUserData(complexityKey)
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package comments
|
||||
|
||||
@Suppress("Unused")
|
||||
class CommentsClass {
|
||||
|
||||
/**
|
||||
* Doc comment
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
fun x(args: String) { // comment total: 10
|
||||
/*
|
||||
comment
|
||||
*/
|
||||
//Comment
|
||||
|
||||
println(args)
|
||||
|
||||
println("/* no comment */")
|
||||
println("// no comment //")
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package empty
|
||||
|
||||
@Suppress("Unused")
|
||||
enum class EmptyEnum
|
||||
@@ -1,4 +0,0 @@
|
||||
package empty
|
||||
|
||||
@Suppress("Unused")
|
||||
interface EmptyInterface
|
||||
@@ -1,8 +0,0 @@
|
||||
package fields
|
||||
|
||||
@Suppress("unused")
|
||||
class ClassWithFields {
|
||||
|
||||
private var x = 0
|
||||
val y = 0
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.gitlab.arturbosch.detekt.api.DetektVisitor
|
||||
import io.gitlab.arturbosch.detekt.api.Detektion
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.gitlab.arturbosch.detekt.api.Detektion
|
||||
import io.gitlab.arturbosch.detekt.api.ProjectMetric
|
||||
@@ -1,7 +1,7 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.gitlab.arturbosch.detekt.api.DetektVisitor
|
||||
import io.gitlab.arturbosch.detekt.core.processors.util.collectByType
|
||||
import io.github.detekt.metrics.processors.util.collectByType
|
||||
import org.jetbrains.kotlin.com.intellij.openapi.util.Key
|
||||
import org.jetbrains.kotlin.psi.KtClass
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
@@ -1,7 +1,7 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.gitlab.arturbosch.detekt.api.DetektVisitor
|
||||
import io.gitlab.arturbosch.detekt.core.processors.util.collectByType
|
||||
import io.github.detekt.metrics.processors.util.collectByType
|
||||
import org.jetbrains.kotlin.com.intellij.openapi.util.Key
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.gitlab.arturbosch.detekt.api.DetektVisitor
|
||||
import org.jetbrains.kotlin.com.intellij.openapi.util.Key
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.gitlab.arturbosch.detekt.api.DetektVisitor
|
||||
import io.gitlab.arturbosch.detekt.api.Detektion
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.gitlab.arturbosch.detekt.api.DetektVisitor
|
||||
import org.jetbrains.kotlin.com.intellij.openapi.util.Key
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.github.detekt.metrics.CyclomaticComplexity
|
||||
import io.gitlab.arturbosch.detekt.api.DetektVisitor
|
||||
@@ -1,7 +1,7 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.gitlab.arturbosch.detekt.api.DetektVisitor
|
||||
import io.gitlab.arturbosch.detekt.core.processors.util.LLOC
|
||||
import io.github.detekt.metrics.processors.util.LLOC
|
||||
import org.jetbrains.kotlin.com.intellij.openapi.util.Key
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.gitlab.arturbosch.detekt.api.DetektVisitor
|
||||
import org.jetbrains.kotlin.com.intellij.openapi.util.Key
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.gitlab.arturbosch.detekt.api.DetektVisitor
|
||||
import org.jetbrains.kotlin.com.intellij.openapi.util.Key
|
||||
@@ -1,7 +1,7 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.gitlab.arturbosch.detekt.api.DetektVisitor
|
||||
import io.gitlab.arturbosch.detekt.core.processors.util.collectByType
|
||||
import io.github.detekt.metrics.processors.util.collectByType
|
||||
import org.jetbrains.kotlin.com.intellij.openapi.util.Key
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtProperty
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors.util
|
||||
package io.github.detekt.metrics.processors.util
|
||||
|
||||
import io.gitlab.arturbosch.detekt.api.DetektVisitor
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
@@ -1,4 +1,4 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors.util
|
||||
package io.github.detekt.metrics.processors.util
|
||||
|
||||
object LLOC {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.gitlab.arturbosch.detekt.core.path
|
||||
import io.github.detekt.test.utils.compileForTest
|
||||
import io.github.detekt.test.utils.compileContentForTest
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
@@ -10,7 +9,7 @@ class CLOCVisitorTest : Spek({
|
||||
describe("CLOC") {
|
||||
|
||||
it("commentCases") {
|
||||
val file = compileForTest(path.resolve("../comments/CommentsClass.kt"))
|
||||
val file = compileContentForTest(commentsClass)
|
||||
val commentLines = with(file) {
|
||||
accept(CLOCVisitor())
|
||||
getUserData(commentLinesKey)
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.gitlab.arturbosch.detekt.core.path
|
||||
import io.github.detekt.test.utils.compileForTest
|
||||
import io.github.detekt.test.utils.compileContentForTest
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.spekframework.spek2.Spek
|
||||
@@ -12,23 +11,23 @@ class ClassCountVisitorTest : Spek({
|
||||
|
||||
it("twoClassesInSeparateFile") {
|
||||
val files = arrayOf(
|
||||
compileForTest(path.resolve("Test.kt")),
|
||||
compileForTest(path.resolve("Default.kt"))
|
||||
compileContentForTest(default),
|
||||
compileContentForTest(classWithFields)
|
||||
)
|
||||
val count = getClassCount(files)
|
||||
assertThat(count).isEqualTo(2)
|
||||
}
|
||||
|
||||
it("oneClassWithOneNestedClass") {
|
||||
val file = compileForTest(path.resolve("ComplexClass.kt"))
|
||||
val file = compileContentForTest(complexClass)
|
||||
val count = getClassCount(arrayOf(file))
|
||||
assertThat(count).isEqualTo(2)
|
||||
}
|
||||
|
||||
it("testEnumAndInterface") {
|
||||
val files = arrayOf(
|
||||
compileForTest(path.resolve("../empty/EmptyEnum.kt")),
|
||||
compileForTest(path.resolve("../empty/EmptyInterface.kt"))
|
||||
compileContentForTest(emptyEnum),
|
||||
compileContentForTest(emptyInterface)
|
||||
)
|
||||
val count = getClassCount(files)
|
||||
assertThat(count).isEqualTo(2)
|
||||
@@ -38,14 +37,13 @@ class ClassCountVisitorTest : Spek({
|
||||
|
||||
private fun getClassCount(files: Array<KtFile>): Int {
|
||||
return files
|
||||
.map { getData(it) }
|
||||
.sum()
|
||||
.map { getData(it) }
|
||||
.sum()
|
||||
}
|
||||
|
||||
private fun getData(file: KtFile): Int {
|
||||
return with(file) {
|
||||
accept(ClassCountVisitor())
|
||||
@Suppress("UnsafeCallOnNullableType")
|
||||
getUserData(numberOfClassesKey)!!
|
||||
checkNotNull(getUserData(numberOfClassesKey))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.github.detekt.test.utils.compileContentForTest
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
|
||||
class ComplexityVisitorTest : Spek({
|
||||
describe("something") {
|
||||
|
||||
it("complexityOfDefaultCaseIsOne") {
|
||||
val mcc = calcComplexity(default)
|
||||
|
||||
assertThat(mcc).isEqualTo(0)
|
||||
}
|
||||
|
||||
it("complexityOfComplexAndNestedClass") {
|
||||
val mcc = calcComplexity(complexClass)
|
||||
|
||||
assertThat(mcc).isEqualTo(44)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
private fun calcComplexity(content: String) =
|
||||
with(compileContentForTest(content)) {
|
||||
accept(ComplexityVisitor())
|
||||
getUserData(complexityKey)
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.gitlab.arturbosch.detekt.core.path
|
||||
import io.github.detekt.test.utils.compileForTest
|
||||
import io.github.detekt.test.utils.compileContentForTest
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
@@ -10,7 +9,7 @@ class FieldCountVisitorTest : Spek({
|
||||
describe("something") {
|
||||
|
||||
it("defaultFieldCount") {
|
||||
val file = compileForTest(path.resolve("../fields/ClassWithFields.kt"))
|
||||
val file = compileContentForTest(classWithFields)
|
||||
val count = with(file) {
|
||||
accept(PropertyCountVisitor())
|
||||
getUserData(numberOfFieldsKey)
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.gitlab.arturbosch.detekt.core.path
|
||||
import io.github.detekt.test.utils.compileForTest
|
||||
import io.github.detekt.test.utils.compileContentForTest
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.spekframework.spek2.Spek
|
||||
@@ -12,12 +11,12 @@ class KtFileCountVisitorTest : Spek({
|
||||
|
||||
it("twoFiles") {
|
||||
val files = arrayOf(
|
||||
compileForTest(path.resolve("Default.kt")),
|
||||
compileForTest(path.resolve("Test.kt"))
|
||||
compileContentForTest(default),
|
||||
compileContentForTest(complexClass)
|
||||
)
|
||||
val count = files
|
||||
.map { getData(it) }
|
||||
.sum()
|
||||
.map { getData(it) }
|
||||
.sum()
|
||||
assertThat(count).isEqualTo(2)
|
||||
}
|
||||
}
|
||||
@@ -26,7 +25,6 @@ class KtFileCountVisitorTest : Spek({
|
||||
private fun getData(file: KtFile): Int {
|
||||
return with(file) {
|
||||
accept(KtFileCountVisitor())
|
||||
@Suppress("UnsafeCallOnNullableType")
|
||||
getUserData(numberOfFilesKey)!!
|
||||
checkNotNull(getUserData(numberOfFilesKey))
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.gitlab.arturbosch.detekt.core.path
|
||||
import io.github.detekt.test.utils.compileForTest
|
||||
import io.github.detekt.test.utils.compileContentForTest
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
|
||||
class LLOCVisitorTest : Spek({
|
||||
describe("seomthing") {
|
||||
describe("LLOC Visitor") {
|
||||
|
||||
it("defaultCaseHasOneClassAndAnnotationLine") {
|
||||
val file = compileForTest(path.resolve("Default.kt"))
|
||||
val file = compileContentForTest(default)
|
||||
|
||||
val lloc = with(file) {
|
||||
accept(LLOCVisitor())
|
||||
@@ -21,7 +20,7 @@ class LLOCVisitorTest : Spek({
|
||||
}
|
||||
|
||||
it("llocOfComplexClass") {
|
||||
val file = compileForTest(path.resolve("ComplexClass.kt"))
|
||||
val file = compileContentForTest(complexClass)
|
||||
|
||||
val lloc = with(file) {
|
||||
accept(LLOCVisitor())
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.gitlab.arturbosch.detekt.core.path
|
||||
import io.github.detekt.test.utils.compileForTest
|
||||
import io.github.detekt.test.utils.compileContentForTest
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
@@ -10,7 +9,7 @@ class LOCVisitorTest : Spek({
|
||||
describe("LOC Visitor") {
|
||||
|
||||
it("defaultClass") {
|
||||
val file = compileForTest(path.resolve("Default.kt"))
|
||||
val file = compileContentForTest(default)
|
||||
val loc = with(file) {
|
||||
accept(LOCVisitor())
|
||||
getUserData(linesKey)
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.gitlab.arturbosch.detekt.core.path
|
||||
import io.github.detekt.test.utils.compileForTest
|
||||
import io.github.detekt.test.utils.compileContentForTest
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.spekframework.spek2.Spek
|
||||
@@ -11,7 +10,7 @@ class MethodCountVisitorTest : Spek({
|
||||
describe("Method Count Visitor") {
|
||||
|
||||
it("defaultMethodCount") {
|
||||
val file = compileForTest(path.resolve("ComplexClass.kt"))
|
||||
val file = compileContentForTest(complexClass)
|
||||
val count = getMethodCount(file)
|
||||
assertThat(count).isEqualTo(6)
|
||||
}
|
||||
@@ -21,7 +20,6 @@ class MethodCountVisitorTest : Spek({
|
||||
private fun getMethodCount(file: KtFile): Int {
|
||||
return with(file) {
|
||||
accept(FunctionCountVisitor())
|
||||
@Suppress("UnsafeCallOnNullableType")
|
||||
getUserData(numberOfFunctionsKey)!!
|
||||
checkNotNull(getUserData(numberOfFunctionsKey))
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.gitlab.arturbosch.detekt.core.path
|
||||
import io.github.detekt.test.utils.compileForTest
|
||||
import io.github.detekt.test.utils.compileContentForTest
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.spekframework.spek2.Spek
|
||||
@@ -12,13 +11,13 @@ class PackageCountVisitorTest : Spek({
|
||||
|
||||
it("twoClassesInSeparatePackage") {
|
||||
val files = arrayOf(
|
||||
compileForTest(path.resolve("Default.kt")),
|
||||
compileForTest(path.resolve("../empty/EmptyEnum.kt"))
|
||||
compileContentForTest(default),
|
||||
compileContentForTest(emptyEnum)
|
||||
)
|
||||
val count = files
|
||||
.map { getData(it) }
|
||||
.distinct()
|
||||
.count()
|
||||
.map { getData(it) }
|
||||
.distinct()
|
||||
.count()
|
||||
assertThat(count).isEqualTo(2)
|
||||
}
|
||||
}
|
||||
@@ -27,7 +26,6 @@ class PackageCountVisitorTest : Spek({
|
||||
private fun getData(file: KtFile): String {
|
||||
return with(file) {
|
||||
accept(PackageCountVisitor())
|
||||
@Suppress("UnsafeCallOnNullableType")
|
||||
getUserData(numberOfPackagesKey)!!
|
||||
checkNotNull(getUserData(numberOfPackagesKey))
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.gitlab.arturbosch.detekt.core.processors
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
import io.gitlab.arturbosch.detekt.core.path
|
||||
import io.github.detekt.test.utils.compileForTest
|
||||
import io.github.detekt.test.utils.compileContentForTest
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
@@ -10,7 +9,7 @@ class SLOCVisitorTest : Spek({
|
||||
describe("SLOC Visitor") {
|
||||
|
||||
it("defaultClass") {
|
||||
val file = compileForTest(path.resolve("Default.kt"))
|
||||
val file = compileContentForTest(default)
|
||||
val loc = with(file) {
|
||||
accept(SLOCVisitor())
|
||||
getUserData(sourceLinesKey)
|
||||
@@ -0,0 +1,209 @@
|
||||
package io.github.detekt.metrics.processors
|
||||
|
||||
val default = """
|
||||
package cases
|
||||
|
||||
/**
|
||||
* A comment
|
||||
*/
|
||||
@Suppress("Unused")
|
||||
class Default
|
||||
""".trimStart()
|
||||
|
||||
val emptyEnum = """
|
||||
package empty
|
||||
|
||||
@Suppress("Unused")
|
||||
enum class EmptyEnum
|
||||
""".trimStart()
|
||||
|
||||
val emptyInterface = """
|
||||
package empty
|
||||
|
||||
@Suppress("Unused")
|
||||
interface EmptyInterface
|
||||
""".trimStart()
|
||||
|
||||
val classWithFields = """
|
||||
package fields
|
||||
|
||||
@Suppress("unused")
|
||||
class ClassWithFields {
|
||||
|
||||
private var x = 0
|
||||
val y = 0
|
||||
}
|
||||
""".trimStart()
|
||||
|
||||
val commentsClass = """
|
||||
package comments
|
||||
|
||||
@Suppress("Unused")
|
||||
class CommentsClass {
|
||||
|
||||
/**
|
||||
* Doc comment
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
fun x(args: String) { // comment total: 10
|
||||
/*
|
||||
comment
|
||||
*/
|
||||
//Comment
|
||||
|
||||
println(args)
|
||||
|
||||
println("/* no comment */")
|
||||
println("// no comment //")
|
||||
}
|
||||
}
|
||||
""".trimStart()
|
||||
|
||||
val complexClass = """
|
||||
package cases
|
||||
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
|
||||
@Suppress("unused")
|
||||
class ComplexClass {// McCabe: 44, LLOC: 20 + 20 + 4x4
|
||||
|
||||
class NestedClass { //14
|
||||
fun complex() { //1 +
|
||||
try {//4
|
||||
while (true) {
|
||||
if (true) {
|
||||
when ("string") {
|
||||
"" -> println()
|
||||
else -> println()
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ex: Exception) { //1 + 3
|
||||
try {
|
||||
println()
|
||||
} catch (ex: Exception) {
|
||||
while (true) {
|
||||
if (false) {
|
||||
println()
|
||||
} else {
|
||||
println()
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally { // 3
|
||||
try {
|
||||
println()
|
||||
} catch (ex: Exception) {
|
||||
while (true) {
|
||||
if (false) {
|
||||
println()
|
||||
} else {
|
||||
println()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
(1..10).forEach {
|
||||
//1
|
||||
println()
|
||||
}
|
||||
for (i in 1..10) { //1
|
||||
println()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun complex() { //1 +
|
||||
try {//4
|
||||
while (true) {
|
||||
if (true) {
|
||||
when ("string") {
|
||||
"" -> println()
|
||||
else -> println()
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ex: Exception) { //1 + 3
|
||||
try {
|
||||
println()
|
||||
} catch (ex: Exception) {
|
||||
while (true) {
|
||||
if (false) {
|
||||
println()
|
||||
} else {
|
||||
println()
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally { // 3
|
||||
try {
|
||||
println()
|
||||
} catch (ex: Exception) {
|
||||
while (true) {
|
||||
if (false) {
|
||||
println()
|
||||
} else {
|
||||
println()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
(1..10).forEach {
|
||||
//1
|
||||
println()
|
||||
}
|
||||
for (i in 1..10) { //1
|
||||
println()
|
||||
}
|
||||
}
|
||||
|
||||
fun manyClosures() {//4
|
||||
true.let {
|
||||
true.apply {
|
||||
true.run {
|
||||
true.sure {
|
||||
""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun manyClosures2() {//4
|
||||
true.let {
|
||||
true.apply {
|
||||
true.run {
|
||||
true.sure {
|
||||
""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun manyClosures3() {//4
|
||||
true.let {
|
||||
true.apply {
|
||||
true.run {
|
||||
true.sure {
|
||||
""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun manyClosures4() {//4
|
||||
true.let {
|
||||
true.apply {
|
||||
true.run {
|
||||
true.sure {
|
||||
""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""".trimStart()
|
||||
Reference in New Issue
Block a user