Skip to content

Scala: accept .sbt files and add sbt() test helper#7793

Merged
timtebeek merged 3 commits into
mainfrom
tim/sbt-file-support-plan
May 27, 2026
Merged

Scala: accept .sbt files and add sbt() test helper#7793
timtebeek merged 3 commits into
mainfrom
tim/sbt-file-support-plan

Conversation

@timtebeek
Copy link
Copy Markdown
Member

Summary

  • ScalaParser.accept now recognizes .sbt in addition to .scala/.sc, and derivedRelativePath emits a .sbt extension for source strings with no package or class/object/trait declaration so synthesized paths round-trip through accept().
  • Adds Assertions.sbt(...) overloads mirroring scala(...) that set the source path to build.sbt, plus a SbtFileTest covering common sbt DSL (name := …, libraryDependencies += …).

Test plan

  • ./gradlew :rewrite-scala:test --tests "org.openrewrite.scala.SbtFileTest"

Copy link
Copy Markdown
Contributor

@greg-at-moderne greg-at-moderne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff.

@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite May 27, 2026
Dotty silently drops top-level expressions at file level, so .sbt
content like `name := "x"` or `import sbt._\nlibraryDependencies += ...`
was either lost or fell back to J.Unknown. Wrap such content in
`object __SbtScript__ { ... }` before parsing, then lift the wrapper
body back out in the converter. Also fix a latent double-adjustment
in `buildQualidFromTree` (pre-subtracted offsetAdjustment then called
updateCursor which subtracts again) — invisible at offset 0 but
exposed by the new wrap.
@timtebeek timtebeek merged commit 925bf07 into main May 27, 2026
1 check passed
@timtebeek timtebeek deleted the tim/sbt-file-support-plan branch May 27, 2026 09:29
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants