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

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

Closed rsmith20 closed 5 months ago

rsmith20 commented 6 months ago

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

Work Around

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

paul-dingemans commented 6 months ago

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"