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

Using ktlint - f remove wrong semi colon #281

Closed
Mathieu-Heuzey opened this issue Sep 18, 2018 · 5 comments
Closed

Using ktlint - f remove wrong semi colon #281

Mathieu-Heuzey opened this issue Sep 18, 2018 · 5 comments

Comments

@Mathieu-Heuzey
Copy link

Hello guys, i had an issue using the command "ktlint -f".

I have a kotlin class declaring a companion object like this "companion object;", I needed it to add more properties as extension function outside of it .

but when i use the command "ktlint -f" the semi colon is removed, and the my project does not compile because the companion object is not found anymore.

@shyiko
Copy link
Collaborator

shyiko commented Sep 18, 2018

Hi @Mathieu-Heuzey. Any chance you can provide a complete example? Thanks.

@Mathieu-Heuzey
Copy link
Author

Mathieu-Heuzey commented Sep 18, 2018

Here is my first class with my companion object

class FirstClass(private val param: String) {

    // Needed to add more properties as extension function outside of it
    companion object;

private var toto : Boolean = false

}

Here is my extension function

fun FirstClass.Companion.create(c: Context) {
            return;
}

Then, when i run "ktlint -F", my semicolon after my companion object will be removed, and without it it does not compile. Is that clear for you or you need more than an example ?

@shyiko
Copy link
Collaborator

shyiko commented Sep 18, 2018

Thank you. That's all I need.

I'll have a fix shortly. As temporary workaround please use:

	companion object; // ktlint-disable no-semi

(for future reference (looks like kotlin compiler bug)):

$ cat FirstClass.kt
class FirstClass(private val param: String) {

    // Needed to add more properties as extension function outside of it
    companion object;

    private var toto: Boolean = false
}

fun FirstClass.Companion.create(c: Context) {
    return
}

class Context

$ ktlint FirstClass.kt 
/tmp/FirstClass.kt:4:21: Unnecessary semicolon

$ kotlinc FirstClass.kt 

$ ktlint -F FirstClass.kt 

$ kotlinc FirstClass.kt 
FirstClass.kt:9:16: error: unresolved reference: Companion
fun FirstClass.Companion.create(c: Context) {
               ^

@Mathieu-Heuzey
Copy link
Author

thanks i will try the fix !

@shyiko
Copy link
Collaborator

shyiko commented Oct 2, 2018

Fixed in 0.29.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants