Skip to content

Commit

Permalink
Merge pull request #637 from cashapp/veyndan/2022-08-09/spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
veyndan authored May 12, 2023
2 parents 0f779bd + a88527f commit 0925968
Show file tree
Hide file tree
Showing 153 changed files with 1,217 additions and 866 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ trim_trailing_whitespace = true
insert_final_newline = true

[*.{kt, kts}]
kotlin_imports_layout = ascii
ij_kotlin_imports_layout = *
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Run './gradlew spotlessApply'
782fd524b15c8de7952ed6dc944d83484d075082
16 changes: 16 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import com.android.build.gradle.BaseExtension
import com.diffplug.gradle.spotless.SpotlessExtension
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost
import java.net.URI
Expand Down Expand Up @@ -30,6 +31,7 @@ buildscript {

plugins {
id("com.github.gmazzo.buildconfig") version "3.1.0" apply false
alias(libs.plugins.spotless)
}

apply(plugin = "org.jetbrains.dokka")
Expand All @@ -40,6 +42,20 @@ tasks.named("dokkaHtmlMultiModule", DokkaMultiModuleTask::class.java).configure

apply(plugin = "com.vanniktech.maven.publish.base")

configure<SpotlessExtension> {
kotlin {
target("**/*.kt")
ktlint()
.editorConfigOverride(
mapOf(
"ktlint_standard_comment-spacing" to "disabled", // TODO Re-enable
"ktlint_standard_filename" to "disabled",
"ktlint_standard_indent" to "disabled", // TODO Re-enable
)
)
}
}

allprojects {
group = "app.cash.zipline"
version = project.property("VERSION_NAME") as String
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ truth = { module = "com.google.truth:truth", version = "1.1.3" }
downloadTask-gradle-plugin = { module = "de.undercouch:gradle-download-task", version = "5.4.0" }

[plugins]
spotless = { id = "com.diffplug.spotless", version = "6.18.0" }
zipline-kotlin = { id = "app.cash.zipline.kotlin" }
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class RealTriviaService : TriviaService {
override fun result(answer: String) = when {
answer.trim().equals("Eclipse", ignoreCase = true) -> AnswerResult(
correct = true,
message = "Yep! Next they'll need to block out an Oracle."
message = "Yep! Next they'll need to block out an Oracle.",
)
else -> AnswerResult(
correct = false,
message = "Nope! The stars aren't in alignment for you."
message = "Nope! The stars aren't in alignment for you.",
)
}
},
Expand All @@ -41,19 +41,18 @@ class RealTriviaService : TriviaService {
override fun result(answer: String) = when {
answer.matches(Regex("vim?", option = RegexOption.IGNORE_CASE)) -> AnswerResult(
correct = true,
message = "You got it! :wq while you're ahead!"
message = "You got it! :wq while you're ahead!",
)
else -> AnswerResult(
correct = false,
message = "Not that! Are you taking your VItamins?"
message = "Not that! Are you taking your VItamins?",
)
}
},
),
)
),
)


override fun games() = gameWithAnswersList.map { it.game }

override fun answer(gameId: Int, questionId: Int, answer: String) =
Expand All @@ -68,7 +67,7 @@ interface QuestionAndAnswer {
class GameWithAnswers(
private val id: Int,
private val name: String,
val questionList: List<QuestionAndAnswer>
val questionList: List<QuestionAndAnswer>,
) {
val game: TriviaGame
get() = TriviaGame(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import app.cash.zipline.loader.ZiplineLoader
import java.util.concurrent.Executors
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.flowOf
import okhttp3.OkHttpClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package app.cash.zipline.samples.worldclock

import app.cash.zipline.loader.ManifestVerifier.Companion.NO_SIGNATURE_CHECKS
import app.cash.zipline.loader.ZiplineHttpClient
import app.cash.zipline.loader.ZiplineLoader
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ fun main() {
val worldClockHost = zipline.take<WorldClockHost>("WorldClockHost")
zipline.bind<WorldClockPresenter>(
name = "WorldClockPresenter",
instance = RealWorldClockPresenter(worldClockHost)
instance = RealWorldClockPresenter(worldClockHost),
)
}

class RealWorldClockPresenter(
private val host: WorldClockHost
private val host: WorldClockHost,
) : WorldClockPresenter {
override fun models(
events: Flow<WorldClockEvent>
events: Flow<WorldClockEvent>,
): Flow<WorldClockModel> {
return flow {
while (true) {
emit(
WorldClockModel(
label = TimeFormatter().formatLocalTime()
)
label = TimeFormatter().formatLocalTime(),
),
)
delay(16)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class JsObjectReader(
closureVars = closureVars,
bytecode = bytecode,
constantPool = constantPool,
debug = debug
debug = debug,
)
}

Expand Down Expand Up @@ -180,7 +180,7 @@ class JsObjectReader(
return Debug(
fileName = fileName.string,
lineNumber = lineNumber,
pc2Line = pc2line
pc2Line = pc2line,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import okio.Closeable
*/
class JsObjectWriter(
private val atoms: AtomSet,
private val sink: BufferedSink
private val sink: BufferedSink,
) : Closeable by sink {
private var used: Boolean = false

Expand Down Expand Up @@ -134,7 +134,7 @@ class JsObjectWriter(
value.kind or
value.isConst.toBit(4) or
value.isLexical.toBit(5) or
value.isCaptured.toBit(6)
value.isCaptured.toBit(6),
)
}

Expand All @@ -146,7 +146,7 @@ class JsObjectWriter(
value.isArg.toBit(1) or
value.isConst.toBit(2) or
value.isLexical.toBit(3) or
(value.kind shl 4)
(value.kind shl 4),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fun applySourceMapToBytecode(
val atoms = jsReader.atoms.toMutableAtomSet()
val rewriter = SourceMapBytecodeRewriter(
sourceMap = sourceMap,
atoms = atoms
atoms = atoms,
)

val ktObject = with(rewriter) {
Expand All @@ -59,7 +59,7 @@ private class SourceMapBytecodeRewriter(
is JsFunctionBytecode -> {
copy(
debug = debug?.jsToKt(),
constantPool = constantPool.map { it.jsToKt() }
constantPool = constantPool.map { it.jsToKt() },
)
}
else -> this
Expand All @@ -71,7 +71,7 @@ private class SourceMapBytecodeRewriter(

val jsReader = LineNumberReader(
functionLineNumber = lineNumber,
source = Buffer().write(pc2Line)
source = Buffer().write(pc2Line),
)

var ktFileName: String? = null
Expand Down
30 changes: 15 additions & 15 deletions zipline-bytecode/src/main/kotlin/app/cash/zipline/bytecode/atoms.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface AtomSet {
}

class MutableAtomSet(
strings: List<JsString>
strings: List<JsString>,
) : AtomSet {
private val _strings = strings.toMutableList()
private val stringToId = mutableMapOf<JsString, Int>()
Expand Down Expand Up @@ -270,18 +270,18 @@ private val BUILT_IN_ATOMS: List<JsString> = listOf(
"TypeError",
"URIError",
"InternalError",
"<brand>", // Symbols
"Symbol.toPrimitive", // Symbols
"Symbol.iterator", // Symbols
"Symbol.match", // Symbols
"Symbol.matchAll", // Symbols
"Symbol.replace", // Symbols
"Symbol.search", // Symbols
"Symbol.split", // Symbols
"Symbol.toStringTag", // Symbols
"Symbol.isConcatSpreadable", // Symbols
"Symbol.hasInstance", // Symbols
"Symbol.species", // Symbols
"Symbol.unscopables", // Symbols
"Symbol.asyncIterator", // Symbols
"<brand>", // Symbols
"Symbol.toPrimitive", // Symbols
"Symbol.iterator", // Symbols
"Symbol.match", // Symbols
"Symbol.matchAll", // Symbols
"Symbol.replace", // Symbols
"Symbol.search", // Symbols
"Symbol.split", // Symbols
"Symbol.toStringTag", // Symbols
"Symbol.isConcatSpreadable", // Symbols
"Symbol.hasInstance", // Symbols
"Symbol.species", // Symbols
"Symbol.unscopables", // Symbols
"Symbol.asyncIterator", // Symbols
).map { it.toJsString() }
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ import org.junit.Test
class ApplySourceMapToBytecodeTest {
private val quickJs = QuickJs.create()

private val emptySourceMap = SourceMap.parse("""
private val emptySourceMap = SourceMap.parse(
"""
|{
| "version": 3,
| "sources": [],
| "sourcesContent": [],
| "names": [],
| "mappings": ";;"
|}
""".trimMargin())
""".trimMargin(),
)

@Before
fun setUp() {
Expand Down Expand Up @@ -117,14 +119,17 @@ class ApplySourceMapToBytecodeTest {
val exception = assertFailsWith<Exception> {
quickJs.evaluate("require('demo').sayHello()")
}
assertThat(exception.stackTraceToString()).startsWith("""
assertThat(exception.stackTraceToString()).startsWith(
"""
|app.cash.zipline.QuickJsException: boom!
| at JavaScript.goBoom1(throwException.kt)
| at JavaScript.goBoom2(throwException.kt:9)
| at JavaScript.goBoom3(throwException.kt:6)
| at JavaScript.sayHello(throwException.kt:3)
| at JavaScript.<eval>(?)
|""".trimMargin())
|
""".trimMargin(),
)
}

@Test fun removeLeadingDotDotsInSourceMap() {
Expand Down Expand Up @@ -167,21 +172,25 @@ class ApplySourceMapToBytecodeTest {
val exception = assertFailsWith<Exception> {
quickJs.evaluate("require('goBoom').app.cash.zipline.testing.goBoom(3)")
}
assertThat(exception.stackTraceToString().replace("\t", " ")).startsWith("""
assertThat(exception.stackTraceToString().replace("\t", " ")).startsWith(
"""
|app.cash.zipline.QuickJsException: boom
| at JavaScript.<anonymous>(go-boom/src/jsMain/kotlin/app/cash/zipline/testing/goBoom.kt:4)
| at JavaScript.<anonymous>(go-boom/src/jsMain/kotlin/app/cash/zipline/testing/goBoom.kt:10)
| at JavaScript.<anonymous>(go-boom/src/jsMain/kotlin/app/cash/zipline/testing/goBoom.kt:10)
| at JavaScript.<anonymous>(go-boom/src/jsMain/kotlin/app/cash/zipline/testing/goBoom.kt:10)
| at JavaScript.<eval>(?)
|""".trimMargin())
|
""".trimMargin(),
)
}

@Test fun functionWithNoInstructions() {
val js = """
|function doNothing() {
|}
|""".trimMargin()
|
""".trimMargin()

// Just confirm the empty function can be transformed successfully.
val bytecode = quickJs.compile(js, "demo.js")
Expand All @@ -203,7 +212,8 @@ class ApplySourceMapToBytecodeTest {
| : b + c + d + Array(e-d.length+1).join(0);
| });
|}
|""".trimMargin()
|
""".trimMargin()

val bytecode = quickJs.compile(js, "demo.js")
val bytecodeWithSourceMap = applySourceMapToBytecode(bytecode, emptySourceMap)
Expand Down
Loading

0 comments on commit 0925968

Please sign in to comment.