Skip to content

Commit 9bd3a9e

Browse files
RBusarowkodiakhq[bot]
authored andcommitted
Update detekt to v1.23.1
1 parent 72bdfc4 commit 9bd3a9e

File tree

6 files changed

+48
-19
lines changed

6 files changed

+48
-19
lines changed

build-logic/core/src/main/kotlin/modulecheck/builds/domainObjectCollection.kt

+25
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
package modulecheck.builds
1717

1818
import org.gradle.api.DomainObjectCollection
19+
import org.gradle.api.Named
20+
import org.gradle.api.NamedDomainObjectCollection
21+
import org.gradle.api.internal.DefaultNamedDomainObjectCollection
1922

2023
/**
2124
* Returns a collection containing the objects in this collection of the
@@ -43,3 +46,25 @@ inline fun <reified S : Any> DomainObjectCollection<in S>.withType(
4346
*/
4447
inline fun <reified S : Any> DomainObjectCollection<in S>.withType(): DomainObjectCollection<S> =
4548
withType(S::class.java)
49+
50+
/**
51+
* Executes the specified action when an element is registered in the [NamedDomainObjectCollection].
52+
* This function does not cause the registered element to be initialized or configured.
53+
*
54+
* @param action The action to execute when an element is registered.
55+
* It takes the name of the registered element as a parameter.
56+
* @receiver The receiver [NamedDomainObjectCollection] to observe for element registration.
57+
* @throws IllegalArgumentException if the receiver collection
58+
* does not extend [DefaultNamedDomainObjectCollection].
59+
*/
60+
inline fun <reified T : Named> NamedDomainObjectCollection<T>.whenElementRegistered(
61+
crossinline action: (name: String) -> Unit
62+
) {
63+
require(this is DefaultNamedDomainObjectCollection<*>) {
64+
"The receiver collection must extend " +
65+
"${DefaultNamedDomainObjectCollection::class.qualifiedName}, " +
66+
"but this type is ${this::class.java.canonicalName}."
67+
}
68+
69+
whenElementKnown { action(it.name) }
70+
}

detekt/detekt-config.yml

-2
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,6 @@ style:
685685
active: true
686686
OptionalUnit:
687687
active: false
688-
OptionalWhenBraces:
689-
active: false
690688
PreferToOverPairSyntax:
691689
active: false
692690
ProtectedMemberInFinalClass:

modulecheck-api/src/main/kotlin/modulecheck/api/context/MustBeApi.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ private suspend fun McProject.mustBeApiIn(
237237
* @since 0.12.0
238238
*/
239239
suspend inline fun <reified T : ConfiguredDependency> T.maybeAsApi(dependentProject: McProject): T {
240-
val mustBeApi = when (this as ConfiguredDependency) {
240+
val mustBeApi = when (val dep: ConfiguredDependency = this@maybeAsApi) {
241241
is ExternalDependency -> false
242242
is ProjectDependency -> when {
243243
configurationName.isKapt() -> false
244-
else -> (this as ProjectDependency).project(dependentProject.projectCache)
244+
else -> dep.project(dependentProject.projectCache)
245245
.mustBeApiIn(
246246
dependentProject = dependentProject,
247247
sourceSetName = configurationName.toSourceSetName(),

modulecheck-model/dependency/api/src/main/kotlin/modulecheck/model/dependency/ConfiguredDependency.kt

+15-13
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,22 @@ sealed interface ConfiguredDependency : Dependency {
4343
inline fun <reified T : ConfiguredDependency> T.copy(
4444
configurationName: ConfigurationName = this.configurationName,
4545
isTestFixture: Boolean = this.isTestFixture
46-
): ConfiguredDependency = when (this as ConfiguredDependency) {
47-
is ExternalDependency -> (this as ExternalDependency).copy(
48-
configurationName = configurationName,
49-
group = group,
50-
moduleName = moduleName,
51-
version = version,
52-
isTestFixture = isTestFixture
53-
)
46+
): ConfiguredDependency {
47+
return when (val dep: ConfiguredDependency = this@copy) {
48+
is ExternalDependency -> dep.copy(
49+
configurationName = configurationName,
50+
group = dep.group,
51+
moduleName = dep.moduleName,
52+
version = dep.version,
53+
isTestFixture = isTestFixture
54+
)
5455

55-
is ProjectDependency -> (this as ProjectDependency).copy(
56-
configurationName = configurationName,
57-
path = projectPath,
58-
isTestFixture = isTestFixture
59-
)
56+
is ProjectDependency -> dep.copy(
57+
configurationName = configurationName,
58+
path = dep.projectPath,
59+
isTestFixture = isTestFixture
60+
)
61+
}
6062
}
6163
}
6264
}

modulecheck-parsing/groovy-antlr/src/main/kotlin/modulecheck/parsing/groovy/antlr/AntlrTreePrinter.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ internal class AntlrTreePrinter(
2424
) : AbstractTreePrinter<Tree>(whitespaceChar) {
2525

2626
override fun Tree.children(): Sequence<Tree> = sequence {
27-
(0 until childCount).forEach { yield(getChild(it)) }
27+
for (it in 0 until childCount) {
28+
yield(getChild(it))
29+
}
2830
}
2931

3032
override fun Tree.text(): String = (this as ParseTree).text

modulecheck-parsing/groovy-antlr/src/main/kotlin/modulecheck/parsing/groovy/antlr/extensions.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ fun Tree.childrenBreadthFirst(predicate: (Tree) -> Boolean): Sequence<Tree> =
107107

108108
/** @return a sequence of the children [Tree] nodes. */
109109
fun Tree.children(): Sequence<Tree> = sequence {
110-
(0 until childCount).forEach { yield(getChild(it)) }
110+
for (it in 0 until childCount) {
111+
yield(getChild(it))
112+
}
111113
}
112114

113115
internal inline fun <reified T> ParserRuleContext.childrenOfType(): List<T> {

0 commit comments

Comments
 (0)