-
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
33 changed files
with
508 additions
and
478 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
19 changes: 19 additions & 0 deletions
19
diktat-api/src/main/kotlin/com/saveourtool/diktat/api/DiktatRuleConfig.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,19 @@ | ||
package com.saveourtool.diktat.api | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* Configuration of individual [DiktatRule] | ||
* | ||
* @property name name of the rule | ||
* @property enabled | ||
* @property configuration a map of strings with configuration options | ||
* @property ignoreAnnotated if a code block is marked with these annotations - it will not be checked by this rule | ||
*/ | ||
@Serializable | ||
data class DiktatRuleConfig( | ||
val name: String, | ||
val enabled: Boolean = true, | ||
val configuration: Map<String, String> = emptyMap(), | ||
val ignoreAnnotated: Set<String> = emptySet(), | ||
) |
14 changes: 14 additions & 0 deletions
14
diktat-api/src/main/kotlin/com/saveourtool/diktat/api/DiktatRuleConfigReader.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,14 @@ | ||
package com.saveourtool.diktat.api | ||
|
||
import java.io.InputStream | ||
|
||
/** | ||
* A reader for [DiktatRuleConfig] | ||
*/ | ||
fun interface DiktatRuleConfigReader : Function1<InputStream, List<DiktatRuleConfig>> { | ||
/** | ||
* @param inputStream | ||
* @return parsed [DiktatRuleConfig]s | ||
*/ | ||
override operator fun invoke(inputStream: InputStream): List<DiktatRuleConfig> | ||
} |
20 changes: 3 additions & 17 deletions
20
diktat-api/src/main/kotlin/com/saveourtool/diktat/api/DiktatRuleSetFactory.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 |
---|---|---|
@@ -1,26 +1,12 @@ | ||
package com.saveourtool.diktat.api | ||
|
||
import java.nio.file.Path | ||
import kotlin.io.path.absolutePathString | ||
|
||
/** | ||
* A factory which creates a [DiktatRuleSet]. | ||
*/ | ||
interface DiktatRuleSetFactory : Function0<DiktatRuleSet> { | ||
fun interface DiktatRuleSetFactory : Function1<List<DiktatRuleConfig>, DiktatRuleSet> { | ||
/** | ||
* @param rulesConfig all configurations for rules | ||
* @return the default instance of [DiktatRuleSet] | ||
*/ | ||
override operator fun invoke(): DiktatRuleSet | ||
|
||
/** | ||
* @param configFile a path to file with configuration for diktat (`diktat-analysis.yml`) | ||
* @return created [DiktatRuleSet] using [configFile] | ||
*/ | ||
fun create(configFile: String): DiktatRuleSet | ||
|
||
/** | ||
* @param configFile a file with configuration for diktat (`diktat-analysis.yml`) | ||
* @return created [DiktatRuleSet] using [configFile] | ||
*/ | ||
fun create(configFile: Path): DiktatRuleSet = create(configFile.absolutePathString()) | ||
override operator fun invoke(rulesConfig: List<DiktatRuleConfig>): DiktatRuleSet | ||
} |
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
42 changes: 42 additions & 0 deletions
42
...ommon/src/main/kotlin/com/saveourtool/diktat/common/config/reader/AbstractConfigReader.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,42 @@ | ||
package com.saveourtool.diktat.common.config.reader | ||
|
||
import mu.KotlinLogging | ||
import java.io.IOException | ||
import java.io.InputStream | ||
import kotlin.jvm.Throws | ||
|
||
/** | ||
* This class is used to read input stream in any format that you will specify. | ||
* Usage: | ||
* 1) implement this class with implementing the method: | ||
* a. parse - implement parser for your file format (for example parse it to a proper json) | ||
* 2) Use your new class MyReader().read(someInputStream) | ||
* | ||
* @param T - class name parameter that will be used in calculation of classpath | ||
*/ | ||
abstract class AbstractConfigReader<T : Any> { | ||
/** | ||
* @param inputStream - input stream | ||
* @return object of type [T] if resource has been parsed successfully | ||
*/ | ||
fun read(inputStream: InputStream): T? = try { | ||
parse(inputStream) | ||
} catch (e: IOException) { | ||
log.error("Cannot read config from input stream due to: ", e) | ||
null | ||
} | ||
|
||
/** | ||
* you can specify your own parser, in example for parsing stream as a json | ||
* | ||
* @param inputStream a [InputStream] representing loaded content | ||
* @return resource parsed as type [T] | ||
* @throws IOException | ||
*/ | ||
@Throws(IOException::class) | ||
protected abstract fun parse(inputStream: InputStream): T | ||
|
||
companion object { | ||
private val log = KotlinLogging.logger {} | ||
} | ||
} |
61 changes: 0 additions & 61 deletions
61
...n/src/main/kotlin/com/saveourtool/diktat/common/config/reader/JsonResourceConfigReader.kt
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.