v0.14.0
What's Changed
1.0.0
, but this will be a big change, so instead we decided to follow more granular deprecation strategy to facilitate future upgrades. API with deprecation target for 1.0.0
has beed updated to 0.16.0
(#902). From now on deprecated methods will be available for 2 minor versions (until 1.0.0 release). After 1.0.0 release Konsist will follow semantic versioning scheme meaning breaking changes will be introduced only when major version of the Konsist changes. Deprecated methods (with initial removal targeted for 1.0.0
) will be removed in next release (deprecation target has bee updated). Please update your by removing Deprecated
Konsist API to facilitate future migration.
Thanks you for your feedback 🙏
New Contributors
- @guiguegon made their first contribution in #720
- @TheMaxCoder made their first contribution in #827
- @pkubowicz made their first contribution in #831
- @kollstrom made their first contribution in #780
- @jibidus made their first contribution in #830
- @ablx made their first contribution in #830
1. Added declaration references
Konsist understands the code's structure better. This new feature, highly requested by the community, provides link between declarations, giving you more control over code quality checks. Konsist now works with declarations directly, allowing you to precisely verify type properties, inheritance relationships, and more e.g.
All parent interfaces have actual
modifier:
Konsist
.scopeFromProject()
.classes()
.parentInterfaces()
.assertTrue {
it.hasActualModifier() // Can access other properties of the interface
}
All function parameters are interfaces:
Konsist
.scopeFromPackage("com.app.worker..")
.functions()
.parameters
.types
.assertTrue {
it.isInterface // Can
}
All classes have test classes with Test
annotation and a name containing its name:
Konsist
.scopeFromProject()
.classes()
.assertTrue {
it.testClasses().all { testClass ->
testClass.hasAnnotationOf<Test>() && testClass.hasNameContaining(it.name)
}
}
All interfaces have children (child classes and child interfaces) resided in ..somepackage..
package:
Konsist
.scopeFromProject()
.interfaces()
.assertTrue {
it.hasAllChildren(indirectChildren = true) { child ->
child.resideInPackage("..somepackage..")
}
}
See Declaration References docs.
2. Retrieve indirect parents
The indirectParents
parameter has been added to parent retrieval methods (parents()
, hasParentClass()
, hasAllParentInterfacesOf
etc.). This parameter specifies whether or not to include parents such as parent of the parent. By default, indirectParents
is false
e.g.
// Class hierarchy
ClassA
↓
ClassB
↓
ClassC
For above inheritance hierarchy is possible to retrieve direct parents of ClassC
(ClassB
) as well as all parents present in the codebase (ClassB
and ClassC
).
Konsist
.scopeFromProject()
.classes()
.first { it.name == "ClassC" }
.parents() // returns direct parents listOf(ClassB)
Konsist
.scopeFromProject()
.classes()
.first { it.name == "SampleClass" }
.parents(indirectParents = true) // returns listOf(ClassB, ClassA)
3. Improved assertArchitecture
methods
Following other assert
methods, we added the testName
and additionalMessage
arguments to the assertArchitecture
methods.
You can now manually set the test name that will be displayed in the test failure message and used to suppress tests. This is useful for Kotest
and dynamic tests.
scope
.assertArchitecture(
testName = "sample name",
additionalMessage = "sample message"
) {
// some dependencies
}
4. Added support for variables
Now Konsist will allow to access and verify variables located inside functions, init blocks, getters, setters and enum constants.
Konsist
.scopeFromProject()
.functions()
.assertTrue {
it.hasVariable { variable ->
variable.name == "sampleVariable"
}
}
5. Ability to check tacit
type
Now Konsist can check whether the properties or variables have a tacit type. Tacit type means that the declaration has an explicitly or implicitly specified type.
val sut: Foo = someCollection.first() // hasTacitTypeOf(SampleClass::class) == true
val sut = Foo("some text") // hasTacitTypeOf(SampleClass::class) == true
val sut = someCollection.first() // hasTacitTypeOf(SampleClass::class) == false
One scenario where tacit type
is useful is verification of sut
(system under test / class under test) existence:
Konsist
.scopeFromTest()
.classes()
.assertTrue {
// Get type name from test class e.g. FooTest -> Foo
val type = it.name.removeSuffix("Test")
val sut = it
.properties()
.firstOrNull { property -> property.name == "sut" }
sut != null && sut.hasTacitType(type)
}
6. Ability to check sourceType
and bareSourceType
Now Konsist provides sourceType
and bareSourceType
properties for better type analysis:
val car: MyClass // sourceType == "MyClass".
val car: MyClass<String> // sourceType == "MyClass<String>"
val car: MyClass // bareSourceType == "MyClass".
val car: MyClass? // bareSourceType == "MyClass".
val car: MyClass<String> // bareSourceType == "MyClass"
val car: MyClass<String?>? // bareSourceType == "MyClass"
val car: com.app.MyClass // bareSourceType == "MyClass"
One scenario where bareSourceType
is useful is naming verification of property with List
type:
Konsist
.scopeFromProject()
.properties()
.types
.withBareSourceTypeOf(List::class)
.assertTrue {
it.hasNameEndingWith("s") || it.hasNameEndingWith("es")
}
7. Ability to check whether a property is read-only
Now Konsist provides isReadOnly
property that checks whether a property is specified with a val
modifier:
val foo = Foo("some text") // isReadOnly == true
var foo = Foo("some text") // isReadOnly == false
Complete list of changes
⚠️ Breaking API Changes
- KON-369 Add Parent Declaration References by @nataliapeterwas in #709
- KON-541 Add KoVariableDeclaration by @nataliapeterwas in #717
- KON-368 Add Tests Declaration References by @nataliapeterwas in #784
- KON-547 Add Type Declarations by @nataliapeterwas in #868
🐛 Bug Fixes
- Replace REGEX to allow using .. as wildcard again by @guiguegon in #720
- Fix wrong detection of Git root project dir by @pkubowicz in #831
- Fix git dir resolver uses the wrong paths by @kollstrom in #780
- KON-578 Fix fully qualified name by @jibidus in #830
- KON-560 Methods With KClass Parameter Fails When Name Of The Class Defined In The File Is The Same As Imported Class by @nataliapeterwas in #775
- KON-577 Layer doesn't allow string that uses a package wildcard twice by @nataliapeterwas in #892
- KON-593 KoPackageMatchingPathProviderCore.hasMatchingPath fails on windows by @nataliapeterwas in #893
💡 Improvements
- Update Kotest Snippets by @nataliapeterwas in #701
- KON-538 Add
testName
ToassertArchitecture
by @nataliapeterwas in #712 - KON-553: Allow
null
values in representsType() by @yonatankarp in #719 - KON-369 Add Parent Declaration References by @nataliapeterwas in #709
- KON-205 Add Konsist Test Which Check That All Core Declarations Override
toString
by @nataliapeterwas in #735 - KON-541 Add KoVariableDeclaration by @nataliapeterwas in #717
- KON-564 Extract if statements to variable by @ablx in #730
- KON-571 Fix
isKotlinType
Property Where Generic Types Where Treated As Kotlin Collections by @igorwojda in #754 - KON-570 Add
KoSourceAndAliasTypeProviderCore.baseSourceType
by @igorwojda in #753 - KON-572 Fix for
sourcetype
stripping?
by @igorwojda in #756 - KON-574 Add
isKotlinBasicType
AndisKotlinCollectionType
by @igorwojda in #757 - KON-570 Rename
baseSourceType
TobareSourcetype
by @igorwojda in #758 - KON-570 Remove Package From
bareType
by @igorwojda in #759 - Update Gitignore by @igorwojda in #762
- Update
check_kttxt_snippets
by @igorwojda in #764 - KON-365 Add
indirectParents=false
Parameter by @nataliapeterwas in #726 - KON-366 Change Return Type Of
containingDeclaration
by @nataliapeterwas in #715 - KON-367 Add Child Declaration References by @nataliapeterwas in #736
- Add Tests by @igorwojda in #842
- Remove Scope Violation Suppress by @igorwojda in #855
- KON-432 Add Konsist Tests Which Check That All Declarations And Providers Implement Correct Parents by @nataliapeterwas in #772
- KON-368 Add Tests Declaration References by @nataliapeterwas in #784
- KON-264 add lists scope from directory by @JonathanSarco in #778
- KON-579 Create
konsist-declaration-tester
by @nataliapeterwas in #858 - KON-583 Add possibility to create scope passing sets of items by @nataliapeterwas in #861
- KON-525 Add isReadOnly property to the KoPropertyDeclaration by @jibidus in #867
- KON-543 Add
hasTacitType
by @nataliapeterwas in #773 - KON-371 Initialize All KoFiles At Start by @igorwojda in #878
- KON-547 Add Type Declarations by @nataliapeterwas in #868
- KON-602 Improve layer verification by @nataliapeterwas in #897
- KON-596 Add extensions to retrieve properties of the source type by @nataliapeterwas in #900
- KON-565 Upgrade Spotless by @igorwojda in #907
- Simplify Snippet Usgae Verification Regex by @igorwojda in #908
- KON-609 Add Type Extensions by @igorwojda in #914
- Add Missing Kotlin Basic Types -
Unit
,Any
andNothing
by @nataliapeterwas in #926 - Use
sourceX
Properties by @nataliapeterwas in #927 - Rename
sourceX
toasXDeclaration()
by @nataliapeterwas in #930
📕 Documentation
- Update README.md by @igorwojda in #771
- Fixed broken link to the getting started guide by @TheMaxCoder in #827
- KON-531 Add Dynamic Test Samples by @igorwojda in #702
- Upd Konsist Artifact Description by @igorwojda in #703
- Fix Typo by @igorwojda in #704
- Update Dynamic Tests by @igorwojda in #706
- Update Sample Projects Docs by @igorwojda in #716
- Upd Snippets by @igorwojda in #723
- Upd docs by @igorwojda in #733
- Upd docs by @igorwojda in #734
- Add Snippet by @igorwojda in #740
- Add Project Icon by @igorwojda in #761
- Add Spring Snippet #766by @igorwojda in #766
- Rename koTest to Kotestby @igorwojda in #837
- Remove "konsist-starter-" prefix from dir names by @igorwojda in #838
- Add Slack Badge #877by @igorwojda in #877
- KON-601 Update KDoc for isInitialized property by @nataliapeterwas in #895
- KON-603 Update Deprecated Version by @nataliapeterwas in #902
- KON-586 Add KDocs for DeclarationReference by @nataliapeterwas in #904
- Update Kdoc by @igorwojda in #915
🏗️ CI
- Fix Artifact Upload by @igorwojda in #698
- KON-537 Update update Snippets Script To Make Sure PR Is Opened From The Newest Version Of Docs by @nataliapeterwas in #695
- KON-563: Run only 1 CI pipeline in parallel for each PR by @yonatankarp in #725
- Improve Gradle build performance by @igorwojda in #749
- KON-562: Improve snippet CI verification by @yonatankarp in #724
- Upgrade CI Java Version by @igorwojda in #854
- KON-589 Upload Check results as artifacts by @igorwojda in #880
- KON-591 Run path test projects on MacOs by @igorwojda in #881
- KON-590 Root Path Testers Are Failin On Ubuntu by @igorwojda in #882
- KON-604 Update Artifact Verification by @igorwojda in #901
- KON-606 Refactor Starter Projects Scripts by @igorwojda in #906
- Rename CI Jobs by @igorwojda in #909
📦 Dependency Upgrade
- Update plugin testLogger to v4 by @renovate in #710
- Update tj-actions/changed-files action to v39.2.2 by @renovate
- Update plugin dokka to v1.9.10 by @renovate
- Update tj-actions/changed-files action to v39.2.3 by @renovate
- Update spring boot to v3.1.5 by @renovate
- Update tj-actions/changed-files action to v39.2.4 by @renovate
- Update dependency androidx.navigation:navigation-fragment-ktx to v2.7.5 by @renovate in #741
- Update plugin io.kotest.multiplatform to v5.8.0 by @renovate
- Update dependency io.kotest:kotest-runner-junit5-jvm to v5.8.0 by @renovate
- Update dependency io.kotest:kotest-runner-junit5 to v5.8.0 by @renovate
- Update kotlin monorepo to v1.9.20 by @renovate
- Update plugin detekt to v1.23.3 by @renovate
- Update dependency androidx.navigation:navigation-ui-ktx to v2.7.5 by @renovate
- Update plugin de.mannodermaus.android-junit5 to v1.10.0.0 by @renovate
- Update junit5 monorepo to v5.10.1 by @renovate
- Update tj-actions/changed-files action to v40.2.2 by @renovate
- Update tj-actions/changed-files action to v40.2.1 by @renovate
- Update plugin com.android.library to v8.2.0 by @renovate
- Update plugin com.android.application to v8.2.0 by @renovate
- Update dependency gradle to v8.5 by @renovate
- Update tj-actions/changed-files action to v40.2.0 by @renovate
- Update plugin detekt to v1.23.4 by @renovate
- Update dependency org.codehaus.mojo:build-helper-maven-plugin to v3.5.0 by @renovate
- Update spring boot to v3.2.0 by @renovate
- Update kotlin monorepo to v1.9.21 by @renovate
- Update plugin com.android.library to v8.1.4 by @renovate
- Update plugin com.android.application to v8.1.4 by @renovate
- Update plugin io.spring.dependency-management to v1.1.4 by @renovate
- Update tj-actions/changed-files action to v40.1.1 by @renovate
- Update plugin com.android.library to v8.1.3 by @renovate
- Update plugin com.android.application to v8.1.3 by @renovate
- Update tj-actions/changed-files action to v40 (#745) by @renovate in #745
- Update dependency org.jetbrains.kotlin-wrappers:kotlin-emotion to v11.11.1-pre.694 by @renovate
- Update dependency org.jetbrains.kotlin-wrappers:kotlin-emotion to v11.11.1-pre.693 by @renovate in #848
- Update dependency org.jetbrains.kotlinx:kotlinx-html-jvm to v0.11.0 by @renovate in #849
- Update plugin org.jetbrains.kotlin.multiplatform to v1.9.22 by @renovate in #845
- Update dependency org.jetbrains.kotlin-wrappers:kotlin-react to v18.2.0-pre.693 by @renovate
- Update dependency io.kotest:kotest-runner-junit5 to v5.8.0 by @renovate in #846
- Update dependency io.ktor:ktor-server-netty to v2.3.8 by @renovate
- Update dependency org.jetbrains.kotlin-wrappers:kotlin-react-dom to v18.2.0-pre.693 by @renovate in #840
- Update tj-actions/changed-files action to v42 by @renovate in #819
- Update actions/setup-java action to v4 by @renovate in #797
- Update actions/setup-python action to v5 by @renovate in #801
- Update actions/upload-artifact action to v4 by @renovate in #808
- Update dependency io.ktor:ktor-server-html-builder-jvm to v2.3.8 by @renovate
- Update junit5 monorepo to v5.10.2 by @renovate
- Update dependency gradle to v8.6 by @renovate
- Update plugin detekt to v1.23.5 by @renovate
- Update plugin com.android.library to v8.2.2 by @renovate
- Update plugin com.android.application to v8.2.2 by @renovate
- Update spring boot to v3.2.2 by @renovate
- Update dependency io.mockk:mockk to v1.13.9 by @renovate
- Update plugin com.android.library to v8.2.1 by @renovate
- Update plugin com.android.application to v8.2.1 by @renovate
- Update kotlin monorepo to v1.9.22 by @renovate
- Update spring boot to v3.2.1 by @renovate
- Update tj-actions/changed-files action to v40.2.3 by @renovate
- Update dependency com.google.android.material:material to v1.11.0 by @renovate
- Update dependency androidx.navigation:navigation-ui-ktx to v2.7.6 by @renovate
- Update dependency androidx.navigation:navigation-fragment-ktx to v2.7.6 by @renovate
- Update dependency org.jetbrains.kotlin-wrappers:kotlin-emotion to v11.11.1-pre.710 by @renovate in #887
- Update dependency org.jetbrains.kotlin-wrappers:kotlin-react to v18.2.0-pre.710 by @renovate in #888
- Update plugin com.android.library to v8.3.0 by @renovate in #890
- Update dependency io.ktor:ktor-server-netty to v2.3.9 by @renovate in #884
- Update dependency org.jetbrains.kotlin-wrappers:kotlin-react-dom to v18.2.0-pre.710 by @renovate in #889
- Update plugin dokka to v1.9.20 by @renovate in #885
- Update tj-actions/changed-files action to v42.0.7 by @renovate in #891
- Update plugin com.android.application to v8.3.0 by @renovate in #886
- Update kotlin monorepo by @renovate in #894
- Update Dev Readme by @renovate in #898
- Update Kotlin Compiler Version by @renovate in #857 by @renovate
- Update plugin io.kotest.multiplatform to v5.8.0 by @renovate in #850 by @renovate
- Update dependency org.jetbrains.kotlin-wrappers:kotlin-react-dom to v18.2.0-pre.694 by @renovate
- Update dependency org.jetbrains.kotlin-wrappers:kotlin-react to v18.2.0-pre.694 by @renovate
- Update plugin io.kotest.multiplatform to v5.8.1 by @renovate in #929
- Update dependency org.jetbrains.kotlin-wrappers:kotlin-react-dom to v18.2.0-pre.712 by @renovate in #928
- Update dependency org.jetbrains.kotlin-wrappers:kotlin-react to v18.2.0-pre.712 by @renovate in #925
- Update dependency org.jetbrains.kotlin-wrappers:kotlin-emotion to v11.11.4-pre.712 by @renovate in #924
- Update dependency io.kotest:kotest-runner-junit5 to v5.8.1 by @renovate in #921
- Update dependency io.kotest:kotest-runner-junit5-jvm to v5.8.1 by @renovate in #922
- Update Kdoc by @renovate in #915
- Update dependency org.jetbrains.kotlin-wrappers:kotlin-react-dom to v18.2.0-pre.711 by @renovate in #913
- Update dependency org.jetbrains.kotlin-wrappers:kotlin-react to v18.2.0-pre.711 by @renovate in #912
- Update dependency org.jetbrains.kotlin-wrappers:kotlin-emotion to v11.11.4-pre.711 by @renovate
- Update tj-actions/changed-files action to v42.1.0 by @renovate
- Update dependency io.ktor:ktor-server-html-builder-jvm to v2.3.9 by @renovate in #883
Full Changelog: v0.13.0...v0.14.0