Skip to content

v0.14.0

Compare
Choose a tag to compare
@igorwojda igorwojda released this 11 Mar 14:05
· 635 commits to main since this release

What's Changed

⚠️ We are changing the deprecation strategy. Initially we wanted to deprecated API in 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

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
ClassAClassBClassC

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

🐛 Bug Fixes

💡 Improvements

📕 Documentation

🏗️ CI

📦 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