pinterest / ktlint

An anti-bikeshedding Kotlin linter with built-in formatter
https://pinterest.github.io/ktlint/
MIT License
6.19k stars 505 forks source link

KtLint ignores missing spaces after fun keyword with generic #2566

Closed metalichesky closed 7 months ago

metalichesky commented 7 months ago

Expected Behavior

Type arguments must be wrapped with whitespaces:

fun <T> runSomething(input: T) {}

Kotlin codestyle proof: https://kotlinlang.org/docs/coding-conventions.html#type-arguments

When you do auto-formatting in IntelliJ or Android Studio, it wraps your type arguments with whitespaces.

Observed Behavior

But fun-keyword-spacing rule ignores it and allows you to write code without spacings at all:

fun<T>runSomething(input: T) {}

It only emit error on multiple spaces after fun.

Steps to Reproduce

Run ktlint check on code like this:

fun<T>runSomething(input: T) {}

Your Environment

ktlint version 1.1.1 ktlint-gradle 12.1.0 gradle 8.2.0

paul-dingemans commented 7 months ago

It expect that you have disabled the type-parameter-list-spacing which is reponsible for adding the white spaces around type parameters:

$ ktlint-1.1.1 --stdin
09:18:49.975 [main] INFO com.pinterest.ktlint.cli.internal.KtlintCommandLine -- Enable default patterns [**/*.kt, **/*.kts]

fun<T>runSomething(input: T) {}

<stdin>:2:4: Expected a single space (standard:type-parameter-list-spacing)
<stdin>:2:7: Expected a single space (standard:type-parameter-list-spacing)
<stdin>:4:1: Needless blank line(s) (standard:no-consecutive-blank-lines)

Summary error count (descending) by rule:
  standard:type-parameter-list-spacing: 2
  standard:no-consecutive-blank-lines: 1