Skip to content

Commit

Permalink
Merge branch 'master' into feature/migrate_tests_to_save
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheshiriks committed Jul 4, 2022
2 parents e29f5d9 + f44aa97 commit 1764a4b
Show file tree
Hide file tree
Showing 36 changed files with 177 additions and 77 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ DiKTat is a strict [coding standard ](info/guide/diktat-coding-convention.md) fo
as AST visitors on the top of [KTlint](https://ktlint.github.io/). It can be used for detecting and autofixing code smells in CI/CD process.
The full list of available supported rules and inspections can be found [here](info/available-rules.md).

Now diKTat was already added to the lists of [static analysis tools](https://github.com/analysis-tools-dev/static-analysis), to [kotlin-awesome](https://github.com/KotlinBy/awesome-kotlin) and to [kompar](https://catalog.kompar.tools/Analyzer/diKTat/1.2.0). Thanks to the community for this support!
Now diKTat was already added to the lists of [static analysis tools](https://github.com/analysis-tools-dev/static-analysis), to [kotlin-awesome](https://github.com/KotlinBy/awesome-kotlin) and to [kompar](https://catalog.kompar.tools/Analyzer/diKTat/1.2.1). Thanks to the community for this support!

## See first

Expand Down Expand Up @@ -56,11 +56,11 @@ Main features of diktat are the following:
curl -sSLO https://github.com/pinterest/ktlint/releases/download/0.43.2/ktlint && chmod a+x ktlint
```

2. Load diKTat manually: [here](https://github.com/saveourtool/diKTat/releases/download/v1.2.0/diktat-1.2.0.jar)
2. Load diKTat manually: [here](https://github.com/saveourtool/diKTat/releases/download/v1.2.1/diktat-1.2.1.jar)

**OR** use curl:
```bash
$ curl -sSLO https://github.com/saveourtool/diKTat/releases/download/v1.2.0/diktat-1.2.0.jar
$ curl -sSLO https://github.com/saveourtool/diKTat/releases/download/v1.2.1/diktat-1.2.1.jar
```
</details>

Expand Down Expand Up @@ -187,7 +187,7 @@ This plugin is available since version 0.1.5. You can see how the plugin is conf

```kotlin
plugins {
id("org.cqfn.diktat.diktat-gradle-plugin") version "1.2.0"
id("org.cqfn.diktat.diktat-gradle-plugin") version "1.2.1"
}
```

Expand All @@ -198,7 +198,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("org.cqfn.diktat:diktat-gradle-plugin:1.2.0")
classpath("org.cqfn.diktat:diktat-gradle-plugin:1.2.1")
}
}

Expand All @@ -219,17 +219,17 @@ diktat {
Also `diktat` extension has different reporters. You can specify `json`, `html`, `sarif`, `plain` (default) or your own custom reporter (it should be added as a dependency into `diktat` configuration):
```kotlin
diktat {
// since 1.2.0 to keep in line with maven properties
// since 1.2.1 to keep in line with maven properties
reporter = "json" // "html", "json", "plain" (default), "sarif"
// before 1.2.0
// before 1.2.1
// reporterType = "json" // "html", "json", "plain" (default), "sarif"
}
```

You can also specify an output.
```kotlin
diktat {
// since 1.2.0 (reporterType for old versions)
// since 1.2.1 (reporterType for old versions)
reporter = "json"
output = "someFile.json"
}
Expand Down Expand Up @@ -270,7 +270,7 @@ spotless {
```kotlin
spotless {
kotlin {
diktat("1.2.0").configFile("full/path/to/diktat-analysis.yml")
diktat("1.2.1").configFile("full/path/to/diktat-analysis.yml")
}
}
```
Expand Down Expand Up @@ -301,7 +301,7 @@ Diktat can be run via spotless-maven-plugin since version 2.8.0

```xml
<diktat>
<version>1.2.0</version> <!-- optional -->
<version>1.2.1</version> <!-- optional -->
<configFile>full/path/to/diktat-analysis.yml</configFile> <!-- optional, configuration file path -->
</diktat>
```
Expand Down
13 changes: 12 additions & 1 deletion diktat-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.cqfn.diktat</groupId>
<artifactId>diktat-parent</artifactId>
<version>1.2.1-SNAPSHOT</version>
<version>1.2.2-SNAPSHOT</version>
</parent>

<dependencies>
Expand All @@ -29,6 +29,15 @@
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</dependency>
<dependency>
<groupId>io.github.microutils</groupId>
<artifactId>kotlin-logging-jvm</artifactId>
</dependency>
<!-- ktlint-core is needed only for `initKtLintKLogger` method -->
<dependency>
<groupId>com.pinterest.ktlint</groupId>
<artifactId>ktlint-core</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down Expand Up @@ -85,6 +94,8 @@
</execution>
</executions>
<configuration>
<apiVersion>1.6</apiVersion>
<languageVersion>1.6</languageVersion>
<compilerPlugins>
<plugin>kotlinx-serialization</plugin>
</compilerPlugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cqfn.diktat.common.config.reader

import org.slf4j.LoggerFactory
import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
import mu.KotlinLogging

import java.io.IOException
import java.util.Properties
Expand Down Expand Up @@ -35,7 +36,7 @@ open class ApplicationProperties(propertiesFileName: String) {
}

companion object {
private val log = LoggerFactory.getLogger(ApplicationProperties::class.java)
private val log = KotlinLogging.loggerWithKtlintConfig(ApplicationProperties::class)
private const val EXIT_STATUS_MISSING_PROPERTIES = 4
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.cqfn.diktat.common.config.reader

import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
import mu.KotlinLogging
import org.slf4j.Logger
import org.slf4j.LoggerFactory

import java.io.BufferedReader
import java.io.IOException
Expand Down Expand Up @@ -60,6 +61,6 @@ abstract class JsonResourceConfigReader<T> {
/**
* A [Logger] that can be used
*/
val log: Logger = LoggerFactory.getLogger(JsonResourceConfigReader::class.java)
val log: Logger = KotlinLogging.loggerWithKtlintConfig(JsonResourceConfigReader::class)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ package org.cqfn.diktat.common.config.rules

import org.cqfn.diktat.common.config.reader.JsonResourceConfigReader
import org.cqfn.diktat.common.config.rules.RulesConfigReader.Companion.log
import org.cqfn.diktat.common.utils.loggerWithKtlintConfig

import com.charleskorn.kaml.Yaml
import com.charleskorn.kaml.YamlConfiguration
import mu.KotlinLogging
import org.slf4j.Logger
import org.slf4j.LoggerFactory

import java.io.BufferedReader
import java.io.File
Expand Down Expand Up @@ -110,7 +111,7 @@ open class RulesConfigReader(override val classLoader: ClassLoader) : JsonResour
/**
* A [Logger] that can be used
*/
val log: Logger = LoggerFactory.getLogger(RulesConfigReader::class.java)
val log: Logger = KotlinLogging.loggerWithKtlintConfig(RulesConfigReader::class)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Utilities related to logging
*/

package org.cqfn.diktat.common.utils

import com.pinterest.ktlint.core.initKtLintKLogger
import mu.KotlinLogging
import org.slf4j.LoggerFactory
import kotlin.reflect.KClass

/**
* Create a logger using [KotlinLogging] and configure it by ktlint's mechanism
*
* @param func empty fun which is used to get enclosing class name
* @return a logger
*/
fun KotlinLogging.loggerWithKtlintConfig(func: () -> Unit) =
logger(func).initKtLintKLogger()

/**
* Create a logger using [KotlinLogging] and configure it by ktlint's mechanism
*
* @param clazz a class for which logger is needed
* @return a logger
*/
fun KotlinLogging.loggerWithKtlintConfig(clazz: KClass<*>) =
logger(LoggerFactory.getLogger(clazz.java)).initKtLintKLogger()
2 changes: 1 addition & 1 deletion diktat-gradle-plugin/gradle-plugin-marker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>diktat-gradle-plugin</artifactId>
<groupId>org.cqfn.diktat</groupId>
<version>1.2.1-SNAPSHOT</version>
<version>1.2.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
8 changes: 4 additions & 4 deletions diktat-gradle-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>diktat-parent</artifactId>
<groupId>org.cqfn.diktat</groupId>
<version>1.2.1-SNAPSHOT</version>
<version>1.2.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -26,11 +26,11 @@
<dependencies>
<dependency>
<groupId>org.cqfn.diktat</groupId>
<artifactId>diktat-rules</artifactId>
<artifactId>diktat-common</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<!-- Since we need diktat-rules only for property name, we can exclude everything else -->
<!-- Since we need diktat-common only for property name, we can exclude everything else -->
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
Expand Down Expand Up @@ -197,4 +197,4 @@
</properties>
</profile>
</profiles>
</project>
</project>
2 changes: 1 addition & 1 deletion diktat-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>diktat-parent</artifactId>
<groupId>org.cqfn.diktat</groupId>
<version>1.2.1-SNAPSHOT</version>
<version>1.2.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
6 changes: 5 additions & 1 deletion diktat-rules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.cqfn.diktat</groupId>
<artifactId>diktat-parent</artifactId>
<version>1.2.1-SNAPSHOT</version>
<version>1.2.2-SNAPSHOT</version>
</parent>

<properties>
Expand Down Expand Up @@ -51,6 +51,10 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>io.github.microutils</groupId>
<artifactId>kotlin-logging-jvm</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package org.cqfn.diktat.ruleset.rules

import org.cqfn.diktat.common.config.rules.RulesConfig
import org.cqfn.diktat.common.config.rules.isRuleEnabled
import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
import org.cqfn.diktat.ruleset.constants.EmitType
import org.cqfn.diktat.ruleset.utils.getFilePath

import com.pinterest.ktlint.core.Rule
import mu.KotlinLogging
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.slf4j.LoggerFactory

private typealias DiktatConfigRule = org.cqfn.diktat.common.config.rules.Rule

Expand Down Expand Up @@ -75,6 +76,6 @@ abstract class DiktatRule(
abstract fun logic(node: ASTNode)

companion object {
private val log = LoggerFactory.getLogger(DiktatRule::class.java)
private val log = KotlinLogging.loggerWithKtlintConfig(DiktatRule::class)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.cqfn.diktat.common.config.rules.DIKTAT_CONF_PROPERTY
import org.cqfn.diktat.common.config.rules.DIKTAT_RULE_SET_ID
import org.cqfn.diktat.common.config.rules.RulesConfig
import org.cqfn.diktat.common.config.rules.RulesConfigReader
import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
import org.cqfn.diktat.ruleset.constants.Warnings
import org.cqfn.diktat.ruleset.rules.OrderedRuleSet.Companion.ordered
import org.cqfn.diktat.ruleset.rules.chapter1.FileNaming
Expand Down Expand Up @@ -85,14 +86,14 @@ import org.cqfn.diktat.ruleset.rules.chapter6.classes.StatelessClassesRule

import com.pinterest.ktlint.core.RuleSet
import com.pinterest.ktlint.core.RuleSetProvider
import mu.KotlinLogging
import org.jetbrains.kotlin.org.jline.utils.Levenshtein
import org.slf4j.LoggerFactory

import java.io.File

/**
* [RuleSetProvider] that provides diKTat ruleset.
* By default it is expected to have diktat-analysis.yml configuration in the root folder where 'ktlint' is run
* By default, it is expected to have diktat-analysis.yml configuration in the root folder where 'ktlint' is run
* otherwise it will use default configuration where some rules are disabled
*
* @param diktatConfigFile - configuration file where all configurations for inspections and rules are stored
Expand All @@ -107,7 +108,6 @@ class DiktatRuleSetProvider(private var diktatConfigFile: String = DIKTAT_ANALYS
@Suppress(
"LongMethod",
"TOO_LONG_FUNCTION",
"SpreadOperator"
)
override fun get(): RuleSet {
log.debug("Will run $DIKTAT_RULE_SET_ID with $diktatConfigFile" +
Expand Down Expand Up @@ -257,6 +257,6 @@ class DiktatRuleSetProvider(private var diktatConfigFile: String = DIKTAT_ANALYS
private fun resolveConfigFileFromSystemProperty(): String? = System.getProperty(DIKTAT_CONF_PROPERTY)

companion object {
private val log = LoggerFactory.getLogger(DiktatRuleSetProvider::class.java)
private val log = KotlinLogging.loggerWithKtlintConfig(DiktatRuleSetProvider::class)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.cqfn.diktat.ruleset.rules.chapter1
import org.cqfn.diktat.common.config.rules.CommonConfiguration
import org.cqfn.diktat.common.config.rules.RulesConfig
import org.cqfn.diktat.common.config.rules.getCommonConfiguration
import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
import org.cqfn.diktat.ruleset.constants.Warnings.INCORRECT_PACKAGE_SEPARATOR
import org.cqfn.diktat.ruleset.constants.Warnings.PACKAGE_NAME_INCORRECT_CASE
import org.cqfn.diktat.ruleset.constants.Warnings.PACKAGE_NAME_INCORRECT_PATH
Expand All @@ -24,12 +25,12 @@ import com.pinterest.ktlint.core.ast.ElementType.REFERENCE_EXPRESSION
import com.pinterest.ktlint.core.ast.ElementType.WHITE_SPACE
import com.pinterest.ktlint.core.ast.children
import com.pinterest.ktlint.core.ast.isLeaf
import mu.KotlinLogging
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafPsiElement
import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl
import org.jetbrains.kotlin.konan.file.File
import org.jetbrains.kotlin.lexer.KtTokens.PACKAGE_KEYWORD
import org.slf4j.LoggerFactory

import java.util.concurrent.atomic.AtomicInteger

Expand Down Expand Up @@ -281,7 +282,7 @@ class PackageNaming(configRules: List<RulesConfig>) : DiktatRule(
}

companion object {
private val log = LoggerFactory.getLogger(PackageNaming::class.java)
private val log = KotlinLogging.loggerWithKtlintConfig(PackageNaming::class)
const val NAME_ID = "package-naming"

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cqfn.diktat.ruleset.rules.chapter2.comments

import org.cqfn.diktat.common.config.rules.RulesConfig
import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
import org.cqfn.diktat.ruleset.constants.ListOfPairs
import org.cqfn.diktat.ruleset.constants.Warnings.COMMENTED_OUT_CODE
import org.cqfn.diktat.ruleset.rules.DiktatRule
Expand All @@ -12,13 +13,13 @@ import com.pinterest.ktlint.core.ast.ElementType.EOL_COMMENT
import com.pinterest.ktlint.core.ast.ElementType.FILE
import com.pinterest.ktlint.core.ast.ElementType.WHITE_SPACE
import com.pinterest.ktlint.core.ast.prevSibling
import mu.KotlinLogging
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.com.intellij.psi.TokenType
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.resolve.ImportPath
import org.slf4j.LoggerFactory

/**
* This rule performs checks if there is any commented code.
Expand Down Expand Up @@ -173,7 +174,7 @@ class CommentsRule(configRules: List<RulesConfig>) : DiktatRule(

@Suppress("MaxLineLength")
companion object {
private val logger = LoggerFactory.getLogger(CommentsRule::class.java)
private val logger = KotlinLogging.loggerWithKtlintConfig(CommentsRule::class)
const val NAME_ID = "comments"
private val importKeywordWithSpace = "${KtTokens.IMPORT_KEYWORD.value} "
private val packageKeywordWithSpace = "${KtTokens.PACKAGE_KEYWORD.value} "
Expand Down
Loading

0 comments on commit 1764a4b

Please sign in to comment.