-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
200 additions
and
127 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
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 |
---|---|---|
@@ -1,67 +1,52 @@ | ||
package org.cqfn.diktat | ||
|
||
import org.cqfn.diktat.api.DiktatLogLevel | ||
import org.cqfn.diktat.api.DiktatReporterType | ||
import org.cqfn.diktat.common.config.rules.DIKTAT | ||
import org.cqfn.diktat.common.config.rules.DIKTAT_ANALYSIS_CONF | ||
import org.cqfn.diktat.ruleset.rules.DiktatRuleSetProvider | ||
import com.pinterest.ktlint.core.Reporter | ||
import kotlinx.cli.ArgParser | ||
import kotlinx.cli.ArgType | ||
import kotlinx.cli.default | ||
import kotlinx.cli.multiple | ||
import kotlinx.cli.vararg | ||
import org.cqfn.diktat.api.DiktatError | ||
import org.cqfn.diktat.api.DiktatMode | ||
import org.cqfn.diktat.cli.DiktatProperties | ||
import org.cqfn.diktat.ktlint.unwrap | ||
import java.nio.file.Files | ||
import java.nio.file.Paths | ||
import kotlin.io.path.absolutePathString | ||
import kotlin.io.path.extension | ||
|
||
fun main(args: Array<String>) { | ||
val parser = ArgParser(DIKTAT) | ||
val config: String by parser.option( | ||
type = ArgType.String, | ||
fullName = "config", | ||
shortName = "c", | ||
description = """ | ||
Specify the location of the YAML configuration file. | ||
By default, $DIKTAT_ANALYSIS_CONF in the current | ||
directory is used. | ||
""".trimIndent(), | ||
).default(DIKTAT_ANALYSIS_CONF) | ||
val doFormat: Boolean by parser.option( | ||
type = ArgType.Boolean, | ||
fullName = "format", | ||
shortName = "F", | ||
description = "Fix any deviations from the code style." | ||
).default(false) | ||
val reporters: List<DiktatReporterType> by parser.option( | ||
type = ArgType.Choice<DiktatReporterType>(), | ||
fullName = "reporter", | ||
shortName = "r", | ||
description = "The reporter to use", | ||
) | ||
.default(DiktatReporterType.PLAIN) | ||
.multiple() | ||
val output: String? by parser.option( | ||
type = ArgType.String, | ||
fullName = "output", | ||
shortName = "o", | ||
description = "Redirect the reporter output to a file.", | ||
) | ||
val logLevel: DiktatLogLevel by parser.option( | ||
type = ArgType.Choice<DiktatLogLevel>(), | ||
fullName = "log-level", | ||
shortName = "l", | ||
description = "Enable the output with specific level", | ||
).default(DiktatLogLevel.INFO) | ||
val patterns: List<String> by parser.argument( | ||
type = ArgType.String, | ||
description = "" | ||
) | ||
.vararg() | ||
val properties = DiktatProperties.parse(args) | ||
properties.configureLogger() | ||
|
||
parser.parse(args) | ||
|
||
val diktatRuleSetProvider = DiktatRuleSetProvider(config) | ||
val reporter = properties.reporter() | ||
reporter.beforeAll() | ||
|
||
val currentFolder = Paths.get(".") | ||
properties.patterns | ||
.asSequence() | ||
.flatMap { pattern -> | ||
Files.newDirectoryStream(currentFolder, pattern).asSequence() | ||
} | ||
.map { file -> | ||
val result = mutableListOf<Pair<DiktatError, Boolean>>() | ||
DiktatProcessCommand.Builder() | ||
.file(file) | ||
.config(properties.config) | ||
.callback { error, isCorrected -> | ||
result.add(error to isCorrected) | ||
} | ||
.isScript(!file.extension.endsWith(".kt", ignoreCase = true)) | ||
.logLevel(properties.logLevel) | ||
.build() | ||
.let { command -> | ||
when (properties.mode) { | ||
DiktatMode.CHECK -> command.check() | ||
DiktatMode.FIX -> command.check() | ||
} | ||
} | ||
file to result | ||
} | ||
.forEach { (file, result) -> | ||
reporter.before(file.absolutePathString()) | ||
result.forEach { (error, isCorrected) -> | ||
reporter.onLintError(file.absolutePathString(), error.unwrap(), isCorrected) | ||
} | ||
reporter.after(file.absolutePathString()) | ||
} | ||
reporter.afterAll() | ||
} | ||
// | ||
//private fun loadReporter(): Reporter { | ||
// | ||
//} |
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
10 changes: 0 additions & 10 deletions
10
diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatLogLevel.kt
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
diktat/src/main/kotlin/org/cqfn/diktat/api/DiktatReporterType.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.