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

Missing whitespace before function body is inserted in wrong place in AST #2130

Closed
paul-dingemans opened this issue Jul 15, 2023 · 0 comments · Fixed by #2132
Closed

Missing whitespace before function body is inserted in wrong place in AST #2130

paul-dingemans opened this issue Jul 15, 2023 · 0 comments · Fixed by #2132
Assignees
Milestone

Comments

@paul-dingemans
Copy link
Collaborator

Given code below:

class UampNotificationManager(
    private val context: Context,
    sessionToken: MediaSessionCompat.Token,
    notificationListener: PlayerNotificationManager.NotificationListener,
) {
    fun showNotificationForPlayer(player: Player){
        notificationManager.setPlayer(player)
    }
}

and .editorconfig:

root = true

[**/*.{kt,kts}]
ktlint_code_style = ktlint_official
ktlint_experimental = enabled
ktlint_standard = enabled

then ktlint 0.50.0 is not able to format the code correctly in 3 runs.

When linting the original code, the following is reported:

src/main/kotlin/UampNotificationManager.kt:6:50: Missing spacing before "{" (standard:curly-spacing)
src/main/kotlin/UampNotificationManager.kt:6:50: Expected a single white space before start of function body (standard:function-start-of-body-spacing)
src/main/kotlin/UampNotificationManager.kt:6:50: Expected a single space before body block (standard:function-signature)
12:11:35.739 [main] WARN com.pinterest.ktlint.cli.internal.KtlintCommandLine - Lint has found errors than can be autocorrected using 'ktlint --format'

So three different rules are reporting the same error.

When running format, the output is:

12:12:49.476 [pool-1-thread-1] WARN com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine - Format was not able to resolve all violations which (theoretically) can be autocorrected in file .../src/main/kotlin/UampNotificationManager.kt in 3 consecutive runs of format.

Also, the file is formatted correctly and no more errors remain despite that formatting reports that not all problems were solved.

The problem is caused by inserting the whitespace element in the wrong position in the AST. If ktlint is restarted, the file is parsed again and the whitespace is in the expected place in the AST and no more error is to be fixed.

@paul-dingemans paul-dingemans self-assigned this Jul 15, 2023
@paul-dingemans paul-dingemans added this to the 1.0 (Yeah!) milestone Jul 15, 2023
paul-dingemans added a commit that referenced this issue Jul 15, 2023
…unction body block exceeds the maximum line length. Fix upsert of whitespace into composite nodes.

Closes #2130
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

Successfully merging a pull request may close this issue.

1 participant