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

Diktat command #1649

Merged
merged 19 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 7 additions & 10 deletions diktat-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ plugins {

dependencies {
implementation(kotlin("gradle-plugin-api"))
implementation(projects.diktatRuleset)
implementation(libs.sarif4k.jvm)

api(projects.diktatCommon) {
exclude("org.jetbrains.kotlin", "kotlin-compiler-embeddable")
exclude("org.jetbrains.kotlin", "kotlin-stdlib-jdk8")
exclude("org.jetbrains.kotlin", "kotlin-stdlib-jdk7")
exclude("org.jetbrains.kotlin", "kotlin-stdlib")
exclude("org.jetbrains.kotlin", "kotlin-stdlib-common")
exclude("org.slf4j", "slf4j-log4j12")
}

implementation(libs.ktlint.core)
implementation(libs.ktlint.reporter.plain)
implementation(libs.ktlint.reporter.sarif)
implementation(libs.ktlint.reporter.json)
implementation(libs.ktlint.reporter.html)
implementation(libs.ktlint.reporter.baseline)
testImplementation(libs.junit.jupiter.api)
testRuntimeOnly(libs.junit.jupiter.engine)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.cqfn.diktat.plugin.gradle

import org.cqfn.diktat.plugin.gradle.tasks.DiktatCheckTask.Companion.registerDiktatCheckTask
import org.cqfn.diktat.plugin.gradle.tasks.DiktatFixTask.Companion.registerDiktatFixTask
import org.cqfn.diktat.plugin.gradle.tasks.configureMergeReportsTask
import generated.DIKTAT_VERSION
import generated.KTLINT_VERSION
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.ExternalModuleDependency
import org.gradle.api.attributes.Bundling
import org.gradle.api.tasks.util.PatternSet

/**
Expand All @@ -28,38 +26,8 @@ class DiktatGradlePlugin : Plugin<Project> {
diktatConfigFile = project.rootProject.file("diktat-analysis.yml")
}

// Configuration that will be used as classpath for JavaExec task.
val diktatConfiguration = project.configurations.create(DIKTAT_CONFIGURATION) { configuration ->
configuration.isVisible = false
configuration.dependencies.add(project.dependencies.create("com.pinterest:ktlint:$KTLINT_VERSION", closureOf<ExternalModuleDependency> {
/*
* Prevent the discovery of standard rules by excluding them as
* dependencies.
*/
val ktlintRuleSets = sequenceOf(
"standard",
"experimental",
"test",
"template"
)
ktlintRuleSets.forEach { ktlintRuleSet ->
exclude(
mutableMapOf(
"group" to "com.pinterest.ktlint",
"module" to "ktlint-ruleset-$ktlintRuleSet"
)
)
}

attributes {
it.attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling::class.java, Bundling.EXTERNAL))
}
}))
configuration.dependencies.add(project.dependencies.create("org.cqfn.diktat:diktat-rules:$DIKTAT_VERSION"))
}

project.registerDiktatCheckTask(diktatExtension, diktatConfiguration, patternSet)
project.registerDiktatFixTask(diktatExtension, diktatConfiguration, patternSet)
project.registerDiktatCheckTask(diktatExtension, patternSet)
project.registerDiktatFixTask(diktatExtension, patternSet)
project.configureMergeReportsTask(diktatExtension)
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,28 @@ fun <T> Any.closureOf(action: T.() -> Unit): Closure<Any?> =
* @param diktatExtension extension of type [DiktatExtension]
* @return CLI flag as string
*/
fun Project.createReporterFlag(diktatExtension: DiktatExtension): String {
fun Project.getReporterType(diktatExtension: DiktatExtension): String {
val name = diktatExtension.reporter.trim()
val validReporters = listOf("sarif", "plain", "json", "html")
val reporterFlag = when {
val reporterType = when {
diktatExtension.githubActions -> {
if (diktatExtension.reporter.isNotEmpty()) {
logger.warn("`diktat.githubActions` is set to true, so custom reporter [$name] will be ignored and SARIF reporter will be used")
}
"--reporter=sarif"
"sarif"
}
name.isEmpty() -> {
logger.info("Reporter name was not set. Using 'plain' reporter")
"--reporter=plain"
"plain"
}
name !in validReporters -> {
logger.warn("Reporter name is invalid (provided value: [$name]). Falling back to 'plain' reporter")
"--reporter=plain"
"plain"
}
else -> "--reporter=$name"
else -> name
}

return reporterFlag
return reporterType
}

/**
Expand Down
Loading