Skip to content

Commit

Permalink
Merge pull request #2 from Kiolk/dev
Browse files Browse the repository at this point in the history
Added examples of using rule to Readme file
  • Loading branch information
Kiolk authored Jul 8, 2024
2 parents be52983 + 3bf57de commit 1a76b9d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 22 deletions.
1 change: 0 additions & 1 deletion .github/workflows/create_github_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ jobs:
- name: Generate jar
run: |
./gradlew jar
echo ${{ needs.check_version.outputs.versionName }}
- uses: ncipollo/release-action@v1
with:
tag: ${{ needs.check_version.outputs.versionName }}
Expand Down
94 changes: 74 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
[![](https://jitpack.io/v/Kiolk/Detekt-rules.svg)](https://jitpack.io/#Kiolk/Detekt-rules) ![Maven Central Version](https://img.shields.io/maven-central/v/io.github.kiolk/kiolk-detekt-rules) ![GitHub Release](https://img.shields.io/github/v/release/kiolk/detekt-rules?color=yellow)

[![](https://jitpack.io/v/Kiolk/Detekt-rules.svg)](https://jitpack.io/#Kiolk/Detekt-rules) ![Maven Central Version](https://img.shields.io/maven-central/v/io.github.kiolk/kiolk-detekt-rules) ![GitHub Release](https://img.shields.io/github/v/release/kiolk/detekt-rules?color=yellow) ![Create Github Release](https://github.com/Kiolk/Detekt-rules/actions/workflows/create_github_release.yml/badge.svg) ![Publish to Maven Central Repository](https://github.com/Kiolk/Detekt-rules/actions/workflows/publish_to_maven_central.yml/badge.svg)
# kiolk-detekt-rules

---
Hello folks. This repository contains my own Detekt rules that born in result my work how developer. I am planning to add new rules in the future. You are welcome to contribute!

Hello folks. This repository contains my own Detekt rules that born in result my work how developer. I am planning to
add new rules in the future. You are welcome to contribute!

# How add to the project

---
You have different options how you can add this set of rules to your project. 
You have different options how you can add this set of rules to your project.

## Maven
To use Maven Central repository, you should add link on `mavenCentral()` in repositories block in `build.gradle.kt` file

```kotlin
repositories {
mavenCentral()
}
mavenCentral()
}
```
In `dependencies` block in `build.gradle.kt` of module where you will use detekt add reference on library that points on the latest version

In `dependencies` block in `build.gradle.kt` of module where you will use detekt add reference on library that points on
the latest version

```kotlin
detektPlugins("io.github.kiolk:kiolk-detekt-rules:1.0.4")
```
Expand All @@ -29,30 +27,86 @@ To use Jitpack, you should add link on jitpack in repositories block in `build.g

```kotlin
repositories {
maven { url 'https://jitpack.io' }
}
maven { url 'https://jitpack.io' }
}
```
In `dependencies` block in `build.gradle.kt` of module where you will use detekt add reference on library that points on the latest version

In `dependencies` block in `build.gradle.kt` of module where you will use detekt add reference on library that points on
the latest version

```kotlin
detektPlugins("com.github.Kiolk:Detekt-rules:v1.0.4")
```

## Local artifacts
If you want to use only locally, you should add path to `jar` file on your local machine. Latest artifacts you can find in [release section](https://github.com/Kiolk/Detekt-rules/releases) of repository.
If you want to use only locally, you should add path to `jar` file on your local machine. Latest artifacts you can find
in [release section](https://github.com/Kiolk/Detekt-rules/releases) of repository.

```kotlin
detektPlugins(files("local_path_to_artifact.jar"))

```

# Configuration
You can add this configuration of rule set to root `detekt.yml` file for more custom configuration.

---

# Rules:
```yaml
kiolk-detekt-rules:
active: true
UseInvokeForOperator:
active: true
autoCorrect: true #is false by default

---
```

# Rules:
## UseInvokeForOperator
### Motivation
If the class defines a function with name invoke and with keyword operator, it can execute this function by directly
call with round brackets. This simplification makes code more readable. This rule detekt such cases and can replace it
on direct call. It is applicable and for lambda functions.

### Cases
When class defines operator invoke
```kotlin
fun someFunction() {
val classWithMethodeInvoke = ClassWithMethodeInvoke()
classWithMethodeInvoke.invoke()
}
```
When lambda expression execute
```kotlin
fun methodeWithNotNullableLambda(notNullableLambda: (() -> Unit)) {
notNullableLambda.invoke()
}
```

It does not trigger for nullable variable, because is not possible to call invoke without safety check

```kotlin
fun methodeWithNullableLambda(nullableLambda: (() -> Unit)?) {
nullableLambda?.invoke()
}
```
But triggers, if safety check is not necessary
```kotlin
fun methodeWithNotNullableLambdaButWithSaveCall(notNullableLambda: (() -> Unit)) {
notNullableLambda?.invoke()
}
```

### AutoCorrection
Replaces `invoke` on direct call.

Before
```kotlin
fun methodeWithNotNullableLambda(callback: (Int, String) -> Unit) {
callback.invoke(3, "string")
}
```
After
```kotlin
fun methodeWithNotNullableLambda(callback: (Int, String) -> Unit) {
callback(3, "string")
}
```
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
kotlin.code.style=official

versionName=1.0.4
versionName=1.0.5
pomGroupId=io.github.kiolk
pomDescription=Detekt rules
pomUrl=https://github.com/Kiolk/Detekt-rules
Expand Down

0 comments on commit 1a76b9d

Please sign in to comment.