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

Import incorrectly dropped when correcting string template expression with redundant braces #2615

Closed
rsmith20 opened this issue Mar 22, 2024 · 1 comment · Fixed by #2617
Closed
Milestone

Comments

@rsmith20
Copy link
Contributor

Expected Behavior

Given

import java.io.File.separator

val s = "${separator} is a file separator"

upon formatting it should be

import java.io.File.separator

val s = "$separator is a file separator"

Observed Behavior

Instead, the import is deleted

val s = "$separator is a file separator"

Your Environment

  • Version of ktlint used: 1.2.1
  • Relevant parts of the .editorconfig settings: ktlint_code_style = intellij_idea
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): repros with CLI ktlint as well as intelliJ plugin.

Work Around

Manually re-add imports or fix redundant braces before formatting.

@paul-dingemans
Copy link
Collaborator

Tnx for reporting. The problem seems to be related to using ${separator}. With code below the problem does not occur:

import java.io.File.separator

val s = "$separator is a file separator"

@paul-dingemans paul-dingemans added this to the 1.2.2 milestone Mar 23, 2024
@rsmith20 rsmith20 changed the title Import incorrectly dropped when correcting string template expression with redundant parentheses Import incorrectly dropped when correcting string template expression with redundant braces Mar 27, 2024
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.

2 participants