KonsistScope

interface KonsistScope : KoScope(source)

Receiver of a konsist { } block: Konsist's own query vocabulary, plus the three words katachi answers with.

Everything on the left of the dot is Konsist's — classes(), functions(), declarations(), withNameEndingWith(...) and the rest arrive through Konsist's KoScope and Konsist's list extensions, unchanged. What katachi replaces is the right of the dot: where Konsist would end a query with its own assertTrue, a konsist { } block ends it with must, mustNot or mustBeEmpty.

The reason is the report, not taste. assertTrue throws on the first rejection and says so in prose; katachi needs the rejected declarations themselves, because the first line of an [UnsatisfiedFileConstraint] block is a real path a reader can open. Collecting them is the only way a block that rejects four classes can produce four blocks pointing at four files. All twelve of Konsist's assertions are therefore shadowed below as compile errors — one declaration per spelling, so that classes().first().assertTrue { } and classes().asSequence().assertTrue { } cannot slip past a shadow written only for lists.

What this scope cannot do

  • KoFileDeclaration.projectPath and moduleName are not usable here. The scope is built with scopeFromExternalDirectories, which Konsist documents as not resolving its own project root, so both are relative to whatever root Konsist inferred rather than to the project katachi walked. Use KoScope queries and the paths in the report instead.

  • .kts files are never in the scope. Konsist 0.17.3 parses a file only when its name ends in .kt (File.isKotlinFile), so a build.gradle.kts or any other script inside what a constraint covers is invisible here however the layout was written. A rule about build scripts has to be written as a plain fileConstraint { } reading the text itself.

  • assertArchitecture is not shadowed. It is a member extension of KoArchitectureAssertion, so it does not resolve from inside a konsist { } block at all — unless a block writes with(KoArchitectureCreator) { } to bring the dispatch receiver in. That spelling is the same escape as building a list outside the block, and it is not one katachi can close.

Example 1: every class in the covered files is internal

"is not exposed outside its feature".konsist {
classes().must { it.hasInternalModifier }
}

Example 2: a query over every declaration, not just classes

konsist {
declarations().mustNot { it.toString().contains("TODO") }
}

Properties

Link copied to clipboard
abstract val annotations: List<KoAnnotationDeclaration>
Link copied to clipboard
abstract val files: List<KoFileDeclaration>
Link copied to clipboard
abstract val imports: List<KoImportDeclaration>
Link copied to clipboard
abstract val packages: List<KoPackageDeclaration>
Link copied to clipboard
abstract val typeAliases: List<KoTypeAliasDeclaration>

Functions

Link copied to clipboard
open fun <E : KoBaseProvider> List<E?>.assertEmpty(strict: Boolean = false, additionalMessage: String? = null, testName: String? = null): Nothing

Konsist's own emptiness assertion over a list. Not usable here — see assertTrue.

open fun <E : KoBaseProvider> Sequence<E?>.assertEmpty(strict: Boolean = false, additionalMessage: String? = null, testName: String? = null): Nothing

Konsist's own emptiness assertion over a sequence. Not usable here — see assertTrue.

Link copied to clipboard
open fun <E : KoBaseProvider> E?.assertFalse(strict: Boolean = false, additionalMessage: String? = null, testName: String? = null, function: (E) -> Boolean?): Nothing

Konsist's own assertion over a single declaration. Not usable here — see assertTrue.

open fun <E : KoBaseProvider> List<E?>.assertFalse(strict: Boolean = false, additionalMessage: String? = null, testName: String? = null, function: (E) -> Boolean?): Nothing

Konsist's own assertion over a list. Not usable here — see assertTrue.

open fun <E : KoBaseProvider> Sequence<E?>.assertFalse(strict: Boolean = false, additionalMessage: String? = null, testName: String? = null, function: (E) -> Boolean?): Nothing

Konsist's own assertion over a sequence. Not usable here — see assertTrue.

Link copied to clipboard
open fun <E : KoBaseProvider> List<E?>.assertNotEmpty(strict: Boolean = false, additionalMessage: String? = null, testName: String? = null): Nothing

Konsist's own non-emptiness assertion over a list. Not usable here — see assertNotNull for why katachi has no word for it.

open fun <E : KoBaseProvider> Sequence<E?>.assertNotEmpty(strict: Boolean = false, additionalMessage: String? = null, testName: String? = null): Nothing

Konsist's own non-emptiness assertion over a sequence. Not usable here — see assertNotNull for why katachi has no word for it.

Link copied to clipboard
open fun <E : KoBaseProvider> E?.assertNotNull(additionalMessage: String? = null, testName: String? = null): Nothing

Konsist's own not-null assertion. Not usable here — see assertTrue.

Link copied to clipboard
open fun <E : KoBaseProvider> E?.assertNull(additionalMessage: String? = null, testName: String? = null): Nothing

Konsist's own null assertion. Not usable here — see assertTrue.

Link copied to clipboard
open fun <E : KoBaseProvider> E?.assertTrue(strict: Boolean = false, additionalMessage: String? = null, testName: String? = null, function: (E) -> Boolean?): Nothing

Konsist's own assertion over a single declaration. Not usable here — see assertTrue.

open fun <E : KoBaseProvider> List<E?>.assertTrue(strict: Boolean = false, additionalMessage: String? = null, testName: String? = null, function: (E) -> Boolean?): Nothing

Konsist's own assertion over a list. Not usable here.

open fun <E : KoBaseProvider> Sequence<E?>.assertTrue(strict: Boolean = false, additionalMessage: String? = null, testName: String? = null, function: (E) -> Boolean?): Nothing

Konsist's own assertion over a sequence. Not usable here — see assertTrue.

Link copied to clipboard
abstract fun classes(includeNested: Boolean, includeLocal: Boolean): List<KoClassDeclaration>
Link copied to clipboard
abstract fun classesAndInterfaces(includeNested: Boolean, includeLocal: Boolean): List<KoClassAndInterfaceDeclaration>
Link copied to clipboard
abstract fun classesAndInterfacesAndObjects(includeNested: Boolean, includeLocal: Boolean): List<KoClassAndInterfaceAndObjectDeclaration>
Link copied to clipboard
abstract fun classesAndObjects(includeNested: Boolean, includeLocal: Boolean): List<KoClassAndObjectDeclaration>
Link copied to clipboard
abstract fun declarations(includeNested: Boolean, includeLocal: Boolean): List<KoBaseDeclaration>
Link copied to clipboard
abstract operator override fun equals(other: Any?): Boolean
Link copied to clipboard
abstract fun functions(includeNested: Boolean, includeLocal: Boolean): List<KoFunctionDeclaration>
Link copied to clipboard
abstract override fun hashCode(): Int
Link copied to clipboard
abstract fun interfaces(includeNested: Boolean): List<KoInterfaceDeclaration>
Link copied to clipboard
abstract fun interfacesAndObjects(includeNested: Boolean): List<KoInterfaceAndObjectDeclaration>
Link copied to clipboard
abstract operator fun minus(scope: KoScope): KoScope
Link copied to clipboard
abstract operator fun minusAssign(scope: KoScope)
Link copied to clipboard
abstract fun <T : KoBaseProvider> List<T>.must(predicate: (T) -> Boolean)

Rejects the elements of this list that predicate answers false for.

Link copied to clipboard
abstract fun <T : KoBaseProvider> List<T>.mustBeEmpty()

Rejects every element of this list, so that a query which finds anything at all fails.

Link copied to clipboard
abstract fun <T : KoBaseProvider> List<T>.mustNot(predicate: (T) -> Boolean)

Rejects the elements of this list that predicate answers true for.

Link copied to clipboard
abstract fun objects(includeNested: Boolean): List<KoObjectDeclaration>
Link copied to clipboard
abstract operator fun plus(scope: KoScope): KoScope
Link copied to clipboard
abstract operator fun plusAssign(scope: KoScope)
Link copied to clipboard
abstract fun print(prefix: String?, predicate: (KoScope) -> String?): KoScope
Link copied to clipboard
abstract fun properties(includeNested: Boolean): List<KoPropertyDeclaration>
Link copied to clipboard
abstract fun slice(predicate: (KoFileDeclaration) -> Boolean): KoScope
Link copied to clipboard
abstract override fun toString(): String