Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detekt: Add Kotlin Script file support. #147

Merged
merged 1 commit into from
Aug 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ buildscript {
classpath 'com.github.ben-manes:gradle-versions-plugin:0.20.0'
classpath 'com.vanniktech:gradle-code-quality-tools-plugin:0.12.0'
classpath 'com.vanniktech:gradle-android-junit-jacoco-plugin:0.12.0'
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.4.0'
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.5.0'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,29 +328,29 @@ class CodeQualityToolsPlugin implements Plugin<Project> {
return false
}

protected static boolean addDetekt(final Project project, final Project rootProject, final CodeQualityToolsPluginExtension extension) {
def isNotIgnored = !shouldIgnore(project, extension)
protected static boolean addDetekt(final Project subProject, final Project rootProject, final CodeQualityToolsPluginExtension extension) {
def isNotIgnored = !shouldIgnore(subProject, extension)
def isEnabled = extension.detekt.enabled
def isDetektSupported = isKotlinProject(project)
def isDetektSupported = isKotlinProject(subProject)

if (isNotIgnored && isEnabled && isDetektSupported) {
def task = project.tasks.create("detektCheck", DetektCheckTask)
def task = subProject.tasks.create("detektCheck", DetektCheckTask)
task.version = extension.detekt.toolVersion
task.group = GROUP_VERIFICATION
task.description = "Runs detekt."
task.outputDirectory = new File(project.buildDir, "reports/detekt/")
task.outputDirectory = new File(subProject.buildDir, "reports/detekt/")
task.configFile = rootProject.file(extension.detekt.config)
task.inputs.files(project.fileTree(dir: ".", include: "**/*.kt"))
task.inputs.files(subProject.fileTree(dir: ".", includes: ["**/*.kt", "**/*.kts"]))

task.inputs.property("baseline-file-exists", false)

if (extension.detekt.baselineFileName != null) {
def file = project.file(extension.detekt.baselineFileName)
def file = subProject.file(extension.detekt.baselineFileName)
task.baselineFilePath = file.toString()
task.inputs.property("baseline-file-exists", file.exists())
}

project.check.dependsOn 'detektCheck'
subProject.check.dependsOn 'detektCheck'

return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class CodeQualityToolsPluginDetektTest {
.succeeds()
}

@Test fun noSrcFolder() {
Roboter(testProjectDir)
.withConfiguration("failFast: true")
.succeeds()
}

@Test fun differentConfigFile() {
Roboter(testProjectDir, config = "code_quality_tools/config-detekt.yml")
.withConfiguration("failFast: true")
Expand All @@ -32,6 +38,13 @@ class CodeQualityToolsPluginDetektTest {
.fails()
}

@Test fun failsOnKotlinScript() {
Roboter(testProjectDir)
.withConfiguration("failFast: true")
.withKotlinFile("build.gradle.kts", "fun foo() = Unit")
.fails()
}

@Test fun disabled() {
Roboter(testProjectDir, enabled = false)
.withConfiguration("failFast: true")
Expand Down