Skip to content

Migrate PerCharacterEscaper from JVM-only to multiplatform #3

Closed
@nedtwigg

Description

@nedtwigg

Inside the snapshot-lib project you will see these folders:

  • commonMain - compiles for all platforms
  • jvmMain - compiles only on the JVM
  • jsMain - compiles only to JS
  • commonTest - these tests run on all platforms
  • jvmTest - these tests only run on JVM
  • etc.

Good example

We want as much code as possible to live in common. A good example of multiplatform is this:

  • a simple internal expect fun to wrap a platform-specific API
  • all the logic of ArrayMap lives in common

https://github.com/diffplug/spotless-snapshot/blob/f63192a84390901a3d3543066d095ea23bf81d21/snapshot-lib/src/commonMain/kotlin/com/diffplug/snapshot/ArrayMap.kt#L22-L115

Then we implement the "expect" for both jvm and js with "actual"

Work to be done.

In this case, we have JVM-only code. It should be pretty easy to move it into common, but there are a few tricky parts, which I don't want to deal with right now. So I move only the public API into common.

https://github.com/diffplug/spotless-snapshot/blob/f63192a84390901a3d3543066d095ea23bf81d21/snapshot-lib/src/commonMain/kotlin/com/diffplug/snapshot/PerCharacterEscaper.kt#L18-L21

Leave the implementation as jvm only, and the js just throws TODO exceptions for now

To implement this I would

  • move PerCharacterEscaperTest out of jvmTest and into commonTest
    • gradlew jvmTest will still be passing, but gradlew jsTest will now be failing
  • remove the expect actual stuff and just put the whole JVM implementation into common
  • fix compile errors with as little platform-specific code as possible

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions