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 rule configs #1686

Merged
merged 21 commits into from
Jun 13, 2023
Merged
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
66 changes: 66 additions & 0 deletions diktat-cli/src/main/kotlin/org/cqfn/diktat/DiktatMainRunner.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.cqfn.diktat
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed

import org.cqfn.diktat.api.DiktatRuleSet
import org.cqfn.diktat.api.DiktatRuleSetFactory
import org.cqfn.diktat.ktlint.DiktatProcessorFactoryImpl
import org.cqfn.diktat.ruleset.rules.DiktatRuleSetFactoryImpl
import mu.KotlinLogging
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.core.LoggerContext
import org.slf4j.event.Level

private val log = KotlinLogging.logger { }
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed

fun main() {
Fixed Show fixed Hide fixed
// a temporary
val logLevel = Level.ERROR
// set log level
LogManager.getContext(false)
.let { it as LoggerContext }
.also { ctx ->
ctx.configuration.rootLogger.level = when (logLevel) {
Level.ERROR -> org.apache.logging.log4j.Level.ERROR
Level.WARN -> org.apache.logging.log4j.Level.WARN
Level.INFO -> org.apache.logging.log4j.Level.INFO
Level.DEBUG -> org.apache.logging.log4j.Level.DEBUG
Level.TRACE -> org.apache.logging.log4j.Level.TRACE
}
}
.updateLoggers()

// default implementations
val diktatRuleSetFactory = DiktatRuleSetFactoryImpl()
val diktatProcessorFactory = DiktatProcessorFactoryImpl()

// ruleSet
val diktatRuleSet: DiktatRuleSet = diktatRuleSetFactory()
val diktatProcessor: DiktatProcessor = diktatProcessorFactory(diktatRuleSet)

val code = mutableListOf<String>()
Fixed Show fixed Hide fixed
while (true) {
val line = readln()
if (line == "CHECK") {
diktatProcessor.check(
code = code.joinToString(),
isScript = true
) { error, _ ->
println(error.toString())
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
}
code.clear()
} else if (line == "FIX") {
val result = diktatProcessor.fix(
code = code.joinToString(),
isScript = true
) { error, _ ->
println(error.toString())
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
}
code.clear()
println("Formatted code:")
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
println(result)
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
} else if (line == "END") {
break
} else {
code.add(line)
}
}
}