pinterest / ktlint

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

[1.3.0] Constructor overloads are incorrectly formatted #2690

Closed Bencodes closed 4 days ago

Bencodes commented 3 weeks ago

Expected Behavior

KtLint should retain the top level constructor () when an overloaded constructor exists and calls this()

Observed Behavior

KtLint removes the default empty class level constructor when a secondary overloaded constructor exists.

Steps to Reproduce

Given:

class Foo() {
    constructor(foo: String) : this() {
        // N/A
    }
}

KtLint produces the following Kotlin class where the default class level constructor is removed which breaks the overloaded constructors ability to call this()

class Foo {
    constructor(foo: String) : this() {
        // N/A
    }
}

Your Environment

paul-dingemans commented 3 weeks ago

Nice find. An empty VALUE_PARAMETER_LIST should only be disallowed in case the class does not contain a secondary constructor.