Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added examples of using rule to Readme file #2

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading