Skip to content

OrganizeImports drops backticks around Scala 3 soft keywords in shared sources #2480

Description

@iRevive

OrganizeImports in 0.14.7 can rewrite valid imports into code that no longer compiles when an import path contains a Scala 3 soft keyword, for example, a Java package segment named export.

Example:

-import io.opentelemetry.sdk.trace.`export`.SimpleSpanProcessor
-import io.opentelemetry.sdk.trace.`export`.SpanExporter
+import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor
+import io.opentelemetry.sdk.trace.export.SpanExporter

This happened in a shared src/main/scala source compiled with Scala 3.

Config:

rules = [
  OrganizeImports
]

OrganizeImports {
  importsOrder = SymbolsFirst
  importSelectorsOrder = SymbolsFirst
  removeUnused = false
}

Expected behavior: keep the escaped package segment:

import io.opentelemetry.sdk.trace.`export`.SimpleSpanProcessor

Actual behavior: backticks are removed:

import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor

I bisected this between 0.14.6 and 0.14.7. First bad commit:

0d232c9 : OrganizeImports: use scalameta to pretty-reprint

The issue seems tied to shared sources: with targetDialect = StandardLayout, src/main/scala is printed with the Scala 2 dialect, so Scala 3 soft keywords like export can be emitted unescaped.


See:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions