> For the complete documentation index, see [llms.txt](https://docs.konsist.lemonappdev.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.konsist.lemonappdev.com/verifying-codebase/verify-functions.md).

# Verify Functions

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

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

```kotlin
Konsist
.scopeFromProject()
.functions()
...
```

In practical scenarios you'll typically want to verify a specific subset of functions - such as those defined inside classes:

```kotlin
Konsist
.scopeFromProject()
.classes()
.functions()
...
```

Local functions are included by default. To exclude them, set `includeLocal = false`:

```kotlin
Konsist
.scopeFromProject()
.classes()
.functions(includeLocal = false)
...
```

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

Let's look at a few examples.

## Verify Name

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

Check if function name starts with `get`:

```kotlin
...
.assertTrue {
   it.hasNameStartingWith("get")
}
```

## Verify Modifiers

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

Check if function has `public` or default (also `public`) modifier:

```kotlin
...
.assertTrue {
   it.hasPublicOrDefaultModifier
}
```

## Verify Annotations

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

Check if function is annotated with `Binding` annotation:

```kotlin
...
.assertTrue {
   it.hasAnnotationOf(Binding::class)
}
```

## **Verify Body Type**

Functions with block bodies (using curly braces) can be validated to ensure compliance with code structure requirements:

<pre class="language-kotlin"><code class="lang-kotlin">...
<strong>.assertTrue { 
</strong>    it.hasBlockBody 
}
</code></pre>

Expression body functions (using single-expression syntax) can be verified to maintain consistent style across the codebase:

```kotlin
...
.assertTrue { 
    it.hasExpressionBody 
}
```

## **Verify Parameters**

Function parameters can be validated for their types, names, modifiers, and annotations to ensure consistent parameter usage.

Check if function has parameter of type `String`:

```kotlin
...
.assertTrue { 
    it.hasParameter { parameter  -> parameter.hasTypeOf(String::class) }
}
```

## **Verify Return Type**

Return types can be checked to ensure functions follow expected return type patterns and contracts.

Check if function return type is a Kotlin collection type:

```kotlin
...
.assertTrue { 
    it.returnType?.sourceDeclaration?.isKotlinCollectionType
}
```

## **Verify Generic Parameters**

Generic type parameters can be validated to ensure proper generic type usage and constraints.

Check if function has type parameters:

```kotlin
...
.assertTrue { 
    it.hasTypeParameters()
}
```

## Verify Generic Type Arguments

Generic type arguments can be checked for correct usage.

Check if return type has no type arguments:

```kotlin
...
.assertFalse {
    it.returnType?.hasTypeArguments()
}
```

## **Verify Top Level**

Top-level functions (functions not declared inside a class) can be specifically queried and validated:

```kotlin
...
.assertTrue { 
    it.isTopLevel
}
```

This helps ensure top-level functions follow project conventions, such as limiting their usage or enforcing specific naming patterns.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.konsist.lemonappdev.com/verifying-codebase/verify-functions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
