Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make plugin testable by stubbing the detekt instance avoiding compile…
…r classpath errors (#177) * Make plugin testable by using a DetektStub * Remove obsolete import * Fix skipping non KtFiles
- Loading branch information
1 parent
3cf7dde
commit 8551673
Showing
10 changed files
with
127 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/main/kotlin/io/gitlab/arturbosch/detekt/idea/config/DetektConfigStorage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/test/kotlin/io/gitlab/arturbosch/detekt/idea/DetektStub.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package io.gitlab.arturbosch.detekt.idea | ||
|
||
import io.github.detekt.psi.FilePath | ||
import io.github.detekt.tooling.api.AnalysisResult | ||
import io.github.detekt.tooling.api.Detekt | ||
import io.github.detekt.tooling.api.DetektProvider | ||
import io.github.detekt.tooling.api.spec.ProcessingSpec | ||
import io.github.detekt.tooling.internal.DefaultAnalysisResult | ||
import io.gitlab.arturbosch.detekt.api.CodeSmell | ||
import io.gitlab.arturbosch.detekt.api.Debt | ||
import io.gitlab.arturbosch.detekt.api.Detektion | ||
import io.gitlab.arturbosch.detekt.api.Entity | ||
import io.gitlab.arturbosch.detekt.api.Finding | ||
import io.gitlab.arturbosch.detekt.api.Issue | ||
import io.gitlab.arturbosch.detekt.api.Location | ||
import io.gitlab.arturbosch.detekt.api.Notification | ||
import io.gitlab.arturbosch.detekt.api.ProjectMetric | ||
import io.gitlab.arturbosch.detekt.api.RuleSetId | ||
import io.gitlab.arturbosch.detekt.api.Severity | ||
import io.gitlab.arturbosch.detekt.api.SourceLocation | ||
import io.gitlab.arturbosch.detekt.api.TextLocation | ||
import org.jetbrains.kotlin.com.intellij.openapi.util.Key | ||
import org.jetbrains.kotlin.psi.KtFile | ||
import org.jetbrains.kotlin.resolve.BindingContext | ||
import java.nio.file.Path | ||
import java.nio.file.Paths | ||
|
||
class DetektProviderStub : DetektProvider { | ||
|
||
override fun get(processingSpec: ProcessingSpec): Detekt = DetektStub() | ||
} | ||
|
||
class DetektStub : Detekt { | ||
|
||
override fun run(): AnalysisResult { | ||
throw UnsupportedOperationException() | ||
} | ||
|
||
override fun run(path: Path): AnalysisResult { | ||
throw UnsupportedOperationException() | ||
} | ||
|
||
override fun run(sourceCode: String, filename: String): AnalysisResult { | ||
if (!filename.contains("Poko.kt")) { | ||
throw UnsupportedOperationException("Only Poko.kt runs are supported.") | ||
} | ||
return DefaultAnalysisResult(object : Detektion { | ||
override val findings: Map<RuleSetId, List<Finding>> = mapOf( | ||
"empty-blocks" to listOf( | ||
CodeSmell( | ||
Issue( | ||
"EmptyDefaultConstructor", | ||
Severity.Minor, | ||
"empty", | ||
Debt.FIVE_MINS | ||
), | ||
Entity( | ||
"Poko", | ||
"testData.Poko.kt", | ||
Location( | ||
SourceLocation(3, 10), | ||
TextLocation(28, 30), | ||
FilePath(Paths.get(filename)) | ||
) | ||
), | ||
"empty constructor" | ||
) | ||
) | ||
) | ||
override val metrics: Collection<ProjectMetric> = emptyList() | ||
override val notifications: Collection<Notification> = emptyList() | ||
|
||
override fun add(notification: Notification) { | ||
// ignore | ||
} | ||
|
||
override fun add(projectMetric: ProjectMetric) { | ||
// ignore | ||
} | ||
|
||
override fun <V> addData(key: Key<V>, value: V) { | ||
// ignore | ||
} | ||
|
||
override fun <V> getData(key: Key<V>): V? { | ||
// ignore | ||
return null | ||
} | ||
}) | ||
} | ||
|
||
override fun run(files: Collection<KtFile>, bindingContext: BindingContext): AnalysisResult { | ||
throw UnsupportedOperationException() | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/test/resources/META-INF/services/io.github.detekt.tooling.api.DetektProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.gitlab.arturbosch.detekt.idea.DetektProviderStub |