From c48f9c717cec0fde40417d9099dc8f572b5af4d0 Mon Sep 17 00:00:00 2001 From: Josh Feinberg Date: Thu, 27 Feb 2020 21:41:38 -0600 Subject: [PATCH] Make baseline platform agnostic --- .../pinterest/ktlint/reporter/baseline/BaselineReporter.kt | 2 +- .../kotlin/com/pinterest/ktlint/internal/BaselineUtils.kt | 3 ++- ktlint/src/test/resources/test-baseline.xml | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ktlint-reporter-baseline/src/main/kotlin/com/pinterest/ktlint/reporter/baseline/BaselineReporter.kt b/ktlint-reporter-baseline/src/main/kotlin/com/pinterest/ktlint/reporter/baseline/BaselineReporter.kt index d8f8cc5bdf..c9b6b6dd28 100644 --- a/ktlint-reporter-baseline/src/main/kotlin/com/pinterest/ktlint/reporter/baseline/BaselineReporter.kt +++ b/ktlint-reporter-baseline/src/main/kotlin/com/pinterest/ktlint/reporter/baseline/BaselineReporter.kt @@ -23,7 +23,7 @@ class BaselineReporter(val out: PrintStream) : Reporter { out.println("""""") for ((file, errList) in acc.entries.sortedBy { it.key }) { val fileName = try { - Paths.get("").toAbsolutePath().relativize(File(file).toPath()).toString() + Paths.get("").toAbsolutePath().relativize(File(file).toPath()).toString().replace('\\', '/') } catch (e: IllegalArgumentException) { file } diff --git a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/BaselineUtils.kt b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/BaselineUtils.kt index d10a005bfb..efbfacb529 100644 --- a/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/BaselineUtils.kt +++ b/ktlint/src/main/kotlin/com/pinterest/ktlint/internal/BaselineUtils.kt @@ -110,6 +110,7 @@ internal fun List.containsLintError(error: LintError): Boolean { /** * Gets the relative route of the file for baselines + * Also adjusts the slashes for uniformity between file systems */ internal val File.relativeRoute: String - get() = Paths.get("").toAbsolutePath().relativize(this.toPath()).toString() + get() = Paths.get("").toAbsolutePath().relativize(this.toPath()).toString().replace('\\', '/') diff --git a/ktlint/src/test/resources/test-baseline.xml b/ktlint/src/test/resources/test-baseline.xml index bdb9298f89..e4eff23900 100644 --- a/ktlint/src/test/resources/test-baseline.xml +++ b/ktlint/src/test/resources/test-baseline.xml @@ -1,10 +1,10 @@ - + - +