Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/kdoc_formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
orchestr7 authored Dec 7, 2024
2 parents 24166ca + cd77a0b commit ffd6dd2
Show file tree
Hide file tree
Showing 27 changed files with 47 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
path: '**/build/reports/'
retention-days: 1
- name: Code coverage report
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5
# Do not run coverage for forks since they cannot upload the results to codecov.
# For reference, see:
# https://docs.github.com/en/actions/using-jobs/using-conditions-to-control-job-execution#example-only-run-job-for-specific-repository
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/diktat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
--build-cache
-PgprUser=${{ github.actor }}
-PgprKey=${{ secrets.GITHUB_TOKEN }}
--stacktrace
- name: Upload SARIF report to Github
uses: github/codeql-action/upload-sarif@v3
if: ${{ always() }}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ Requires a gradle version no lower than 7.0

You can see how the plugin is configured in our examples:
- [Kotlin DSL](examples/gradle-kotlin-dsl/build.gradle.kts)
- [Kotlin DSL for multi-module project](examples/gradle-kotlin-dsl/build.gradle.kts)
- [Groovy DSL](examples/gradle-kotlin-dsl/build.gradle.kts)
- [Kotlin DSL for multi-module project](examples/gradle-kotlin-dsl-multiproject/build.gradle.kts)
- [Groovy DSL](examples/gradle-groovy-dsl/build.gradle)

<details>
<summary>Add this plugin to your `build.gradle.kts`:</summary>
Expand Down
23 changes: 2 additions & 21 deletions detekt-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ complexity:
threshold: 10
includeStaticDeclarations: false
includePrivateDeclarations: false
ComplexMethod:
CyclomaticComplexMethod:
active: true
threshold: 15
ignoreSingleWhenExpression: false
Expand Down Expand Up @@ -253,7 +253,6 @@ naming:
parameterPattern: '[a-z][A-Za-z0-9]*'
privateParameterPattern: '[a-z][A-Za-z0-9]*'
excludeClassPattern: '$^'
ignoreOverridden: true
EnumNaming:
active: true
excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**']
Expand All @@ -275,14 +274,12 @@ naming:
excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**']
functionPattern: '([a-z][a-zA-Z0-9]*)|(`.*`)'
excludeClassPattern: '$^'
ignoreOverridden: true
ignoreAnnotated: ['Composable']
FunctionParameterNaming:
active: true
excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**']
parameterPattern: '[a-z][A-Za-z0-9]*'
excludeClassPattern: '$^'
ignoreOverridden: true
InvalidPackageDeclaration:
active: false
excludes: ['*.kts']
Expand Down Expand Up @@ -328,7 +325,6 @@ naming:
variablePattern: '[a-z][A-Za-z0-9]*'
privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*'
excludeClassPattern: '$^'
ignoreOverridden: true

performance:
active: true
Expand All @@ -351,8 +347,6 @@ potential-bugs:
active: true
DontDowncastCollectionTypes:
active: true
DuplicateCaseInWhenExpression:
active: true
EqualsAlwaysReturnsTrueOrFalse:
active: true
EqualsWithHashCodeExist:
Expand All @@ -365,7 +359,7 @@ potential-bugs:
active: false
IgnoredReturnValue:
active: true
restrictToAnnotatedMethods: true
restrictToConfig: true
returnValueAnnotations: ['*.CheckReturnValue', '*.CheckResult']
ImplicitDefaultLocale:
active: false
Expand All @@ -384,13 +378,8 @@ potential-bugs:
ignoreOnClassesPattern: ''
MapGetWithNotNullAssertionOperator:
active: false
MissingWhenCase:
active: true
allowElseExpression: true
NullableToStringCall:
active: false
RedundantElseInWhen:
active: true
UnconditionalJumpStatementInLoop:
active: false
UnnecessaryNotNullOperator:
Expand Down Expand Up @@ -437,10 +426,6 @@ style:
ExpressionBodySyntax:
active: false
includeLineWrapping: false
ForbiddenComment:
active: true
values: ['TODO:', 'STOPSHIP:']
allowedPatterns: ''
ForbiddenImport:
active: false
imports: []
Expand Down Expand Up @@ -486,8 +471,6 @@ style:
ignoreEnums: false
ignoreRanges: false
ignoreExtensionFunctions: true
MandatoryBracesIfStatements:
active: false
MandatoryBracesLoops:
active: false
MaxLineLength:
Expand All @@ -512,8 +495,6 @@ style:
active: true
OptionalUnit:
active: false
OptionalWhenBraces:
active: false
PreferToOverPairSyntax:
active: false
ProtectedMemberInFinalClass:
Expand Down
2 changes: 1 addition & 1 deletion diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# or: "1, 2, 3, 4, 5, 6"
disabledChapters: ""
testDirs: test
kotlinVersion: 1.9
kotlinVersion: 2.1
srcDirectories: "main"
# Checks that the Class/Enum/Interface name matches Pascal case
- name: CLASS_NAME_INCORRECT
Expand Down
11 changes: 6 additions & 5 deletions diktat-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import com.saveourtool.diktat.buildutils.configurePom

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.getCurrentOperatingSystem
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

@Suppress("DSL_SCOPE_VIOLATION", "RUN_IN_SCRIPT") // https://github.com/gradle/gradle/issues/22797
Expand Down Expand Up @@ -31,13 +33,12 @@ dependencies {
}

tasks.withType<KotlinCompile> {
kotlinOptions {
compilerOptions {
// kotlin 1.4 api is the latest support version in kotlin 1.9
// min supported Gradle is 7.0
languageVersion = "1.4"
apiVersion = "1.4"
jvmTarget = "1.8"
freeCompilerArgs = freeCompilerArgs - "-Werror"
languageVersion.set(KotlinVersion.KOTLIN_2_0)
apiVersion.set(KotlinVersion.KOTLIN_2_0)
jvmTarget.set(JvmTarget.JVM_1_8)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.saveourtool.diktat.api.DiktatProcessorListener
import com.saveourtool.diktat.ktlint.DiktatReporterImpl.Companion.wrap

import com.pinterest.ktlint.cli.reporter.baseline.Baseline
import com.pinterest.ktlint.cli.reporter.baseline.BaselineErrorHandling
import com.pinterest.ktlint.cli.reporter.baseline.BaselineReporterProvider
import com.pinterest.ktlint.cli.reporter.baseline.loadBaseline

Expand All @@ -23,7 +24,7 @@ class DiktatBaselineFactoryImpl : DiktatBaselineFactory {
override fun tryToLoad(
baselineFile: Path,
sourceRootDir: Path?,
): DiktatBaseline? = loadBaseline(baselineFile.absolutePathString())
): DiktatBaseline? = loadBaseline(baselineFile.absolutePathString(), BaselineErrorHandling.LOG)
.takeIf { it.status == Baseline.Status.VALID }
?.let { ktLintBaseline ->
DiktatBaseline { file ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class DiktatProcessorFactoryImpl : DiktatProcessorFactory {
code: Code,
callback: LintCallback,
): String {
// this API method is significantly changed in Ktlint, so -werror was disabled due to it
@Suppress("Deprecation")
val formatResult = format(code)
lint(
code = Code(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class KtLintRuleWrapper(
about = about,
visitorModifiers = createVisitorModifiers(rule, prevRuleId),
) {
@Deprecated("Marked for removal in Ktlint 2.0. Please implement interface RuleAutocorrectApproveHandler.")
override fun beforeVisitChildNodes(
node: ASTNode,
autoCorrect: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ class MultipleModifiersSequence(configRules: List<RulesConfig>) : DiktatRule(
KtTokens.CROSSINLINE_KEYWORD, KtTokens.VARARG_KEYWORD, KtTokens.SUSPEND_KEYWORD, KtTokens.INNER_KEYWORD,
KtTokens.OUT_KEYWORD, KtTokens.ENUM_KEYWORD, KtTokens.ANNOTATION_KEYWORD, KtTokens.COMPANION_KEYWORD,
KtTokens.VALUE_KEYWORD, KtTokens.INLINE_KEYWORD, KtTokens.NOINLINE_KEYWORD, KtTokens.REIFIED_KEYWORD, KtTokens.INFIX_KEYWORD,
KtTokens.OPERATOR_KEYWORD, KtTokens.DATA_KEYWORD, KtTokens.IN_KEYWORD, KtTokens.HEADER_KEYWORD,
KtTokens.IMPL_KEYWORD)
KtTokens.OPERATOR_KEYWORD, KtTokens.DATA_KEYWORD, KtTokens.IN_KEYWORD)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.saveourtool.diktat.ruleset.utils

import org.jetbrains.kotlin.KtNodeTypes.BLOCK
import org.jetbrains.kotlin.KtNodeTypes.IMPORT_LIST
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.environment.setIdeaIoUseFallback
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
Expand All @@ -17,6 +16,7 @@ import org.jetbrains.kotlin.com.intellij.pom.PomTransaction
import org.jetbrains.kotlin.com.intellij.pom.impl.PomTransactionBase
import org.jetbrains.kotlin.com.intellij.pom.tree.TreeAspect
import org.jetbrains.kotlin.com.intellij.psi.TokenType.ERROR_ELEMENT
import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.lexer.KtTokens.IMPORT_KEYWORD
Expand All @@ -30,7 +30,7 @@ import sun.reflect.ReflectionFactory
class KotlinParser {
private val project: Project by lazy {
val compilerConfiguration = CompilerConfiguration()
compilerConfiguration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE) // mute the output logging to process it themselves
compilerConfiguration.put(CommonConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE) // mute the output logging to process it themselves
val pomModel: PomModel = object : UserDataHolderBase(), PomModel {
override fun runTransaction(transaction: PomTransaction) {
(transaction as PomTransactionBase).run()
Expand Down
2 changes: 1 addition & 1 deletion diktat-rules/src/main/resources/diktat-analysis-huawei.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# testDirs: test
disabledChapters: ""
testDirs: test
kotlinVersion: 1.9
kotlinVersion: 2.1
srcDirectories: "main"
# Checks that the Class/Enum/Interface name matches Pascal case
- name: CLASS_NAME_INCORRECT
Expand Down
2 changes: 1 addition & 1 deletion diktat-rules/src/main/resources/diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# expected values: disabledChapters: "Naming, Comments, General, Variables, Functions, Classes"
# or: "1, 2, 3, 4, 5, 6"
disabledChapters: ""
kotlinVersion: 1.9
kotlinVersion: 2.1
srcDirectories: "main"
# Checks that the Class/Enum/Interface name matches Pascal case
- name: CLASS_NAME_INCORRECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ import kotlin.contracts.contract

internal const val TEST_FILE_NAME = "TestFileName.kt"

private val debuggerPromptPrefixes: Array<out String> = arrayOf(
"Listening for transport dt_socket at address: ",
"Listening for transport dt_shmem at address: ",
)

/**
* Casts a nullable value to a non-`null` one, similarly to the `!!`
* operator.
Expand All @@ -43,59 +38,6 @@ internal fun <T : Any> T?.assertNotNull(lazyFailureMessage: () -> String = { "Ex
return this ?: fail(lazyFailureMessage())
}

/**
* Calls the [block] callback giving it a sequence of all the lines in this file
* and closes the reader once the processing is complete.
*
* If [filterDebuggerPrompt] is `true`, the JVM debugger prompt is filtered out
* from the sequence of lines before it is consumed by [block].
*
* If [filterDebuggerPrompt] is `false`, this function behaves exactly as the
* overloaded function from the standard library.
*
* @param filterDebuggerPrompt whether the JVM debugger prompt should be
* filtered out.
* @param block the callback which consumes the lines produced by this [Reader].
* @return the value returned by [block].
*/
@OptIn(ExperimentalContracts::class)
internal fun <T> Reader.useLines(
filterDebuggerPrompt: Boolean,
block: (Sequence<String>) -> T,
): T {
contract {
callsInPlace(block, EXACTLY_ONCE)
}

return when {
filterDebuggerPrompt -> {
/*
* Transform the line consumer.
*/
{ lines ->
lines.filterNot(String::isDebuggerPrompt).let(block)
}
}

else -> block
}.let(this::useLines)
}

private fun String.isDebuggerPrompt(printIfTrue: Boolean = true): Boolean {
val isDebuggerPrompt = debuggerPromptPrefixes.any { prefix ->
this.startsWith(prefix)
}
if (isDebuggerPrompt && printIfTrue) {
/*
* Print the prompt to the standard out,
* so that the IDE can attach to the debugger.
*/
@Suppress("DEBUG_PRINT")
println(this)
}
return isDebuggerPrompt
}

/**
* This utility function lets you run arbitrary code on every node of given [code].
* It also provides you with counter which can be incremented inside [applyToNode] and then will be compared to [expectedAsserts].
Expand Down
2 changes: 1 addition & 1 deletion examples/gradle-groovy-dsl/diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# expected values: disabledChapters: "Naming, Comments, General, Variables, Functions, Classes"
# or: "1, 2, 3, 4, 5, 6"
disabledChapters: ""
kotlinVersion: 1.9
kotlinVersion: 2.1
srcDirectories: "main"
# Checks that the Class/Enum/Interface name matches Pascal case
- name: CLASS_NAME_INCORRECT
Expand Down
2 changes: 1 addition & 1 deletion examples/gradle-kotlin-dsl-multiproject/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import com.saveourtool.diktat.plugin.gradle.DiktatExtension
import com.saveourtool.diktat.plugin.gradle.DiktatGradlePlugin

plugins {
kotlin("jvm") version "1.9.24"
kotlin("jvm") version "2.1.0"
id("com.saveourtool.diktat") version "2.0.0" apply false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# expected values: disabledChapters: "Naming, Comments, General, Variables, Functions, Classes"
# or: "1, 2, 3, 4, 5, 6"
disabledChapters: ""
kotlinVersion: 1.9
kotlinVersion: 2.1
srcDirectories: "main"
# Checks that the Class/Enum/Interface name matches Pascal case
- name: CLASS_NAME_INCORRECT
Expand Down
2 changes: 1 addition & 1 deletion examples/gradle-kotlin-dsl/diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# expected values: disabledChapters: "Naming, Comments, General, Variables, Functions, Classes"
# or: "1, 2, 3, 4, 5, 6"
disabledChapters: ""
kotlinVersion: 1.9
kotlinVersion: 2.1
srcDirectories: "main"
# Checks that the Class/Enum/Interface name matches Pascal case
- name: CLASS_NAME_INCORRECT
Expand Down
2 changes: 1 addition & 1 deletion examples/maven-multiproject/diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# expected values: disabledChapters: "Naming, Comments, General, Variables, Functions, Classes"
# or: "1, 2, 3, 4, 5, 6"
disabledChapters: ""
kotlinVersion: 1.9
kotlinVersion: 2.1
srcDirectories: "main"
# Checks that the Class/Enum/Interface name matches Pascal case
- name: CLASS_NAME_INCORRECT
Expand Down
2 changes: 1 addition & 1 deletion examples/maven/diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# expected values: disabledChapters: "Naming, Comments, General, Variables, Functions, Classes"
# or: "1, 2, 3, 4, 5, 6"
disabledChapters: ""
kotlinVersion: 1.9
kotlinVersion: 2.1
srcDirectories: "main"
# Checks that the Class/Enum/Interface name matches Pascal case
- name: CLASS_NAME_INCORRECT
Expand Down
Loading

0 comments on commit ffd6dd2

Please sign in to comment.