For the complete documentation index, see llms.txt. This page is also available as Markdown.

Verify Interfaces

Konsist enables development teams to enforce structural rules for interfaces, ensuring code consistency across projects.

To verify interfaces start by querying all interfaces present in the project:

Konsist
.scopeFromProject()
.interfaces()
...

The above code selects all interfaces present in the project codebase. While this demonstrates Konsist's API capabilities, in practical scenarios you'll typically want to verify a specific subset of interfaces - such as those with a particular name suffix or interfaces within a given package. See Create The Scope and Declaration Filtering.

Konsist allows you to verify multiple aspects of interfaces. For the complete list of available APIs, explore KoInterfaceDeclaration in your IDE (code completion and KDoc).

Let's look at a few examples.

Verify Name

Interface names can be validated to ensure they follow project naming conventions and patterns.

Check if interface name ends with Repository:

...
.assertTrue {
   it.hasNameEndingWith("Repository")
}

Verify Modifiers

Interface modifiers can be validated to ensure proper encapsulation and access control.

Check if interface has internal modifier:

Verify Annotations

Interface-level and member annotations can be verified for presence, correct usage, and required attribute values.

Check if interface is annotated with Service annotation:

Verify Package

Package declarations can be validated to ensure interfaces are located in the correct package structure according to architectural guidelines.

Check if interface has model package or sub-packages (.. means include sub-packages):

Verify Methods

Methods can be validated for their signatures, modifiers, annotations, naming patterns, return types, and parameter structures.

Check if methods (functions defined inside interface) have name starting with Local:

See Verify Functions.

Verify Properties

Properties can be checked for proper access modifiers, type declarations, and initialization patterns.

Check if all properties (defined inside interface) have val modifier:

See Verify Properties.

Verify Generic Type Parameters

Generic type parameters and constraints can be checked for correct usage and bounds declarations.

Check if interface has no type parameters:

Verify Generic Type Arguments

Generic type arguments can be checked for correct usage.

Check if parent has no type arguments:

Verify Parents

Inheritance hierarchies, interface implementations, and superclass relationships can be validated.

Check if interface extends CrudRepository:

Verify Companion Objects

Companion object declarations, their contents, and usage patterns can be verified for compliance.

Check if interface has companion object:

Verify Members Order

The sequential arrangement of interface members can be enforced according to defined organizational rules.

Check if interface properties are defined before functions:

Last updated