Skip to content

Commit

Permalink
diktatFix + fixed relativePath when different roots
Browse files Browse the repository at this point in the history
  • Loading branch information
nulls committed Dec 12, 2023
1 parent f3e4dde commit f1c89ba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ private fun Path.walkByGlob(glob: String): Sequence<Path> = if (glob.startsWith(
}
}

private fun String.findRoot(): Path = substring(0, indexOf('*'))
.let { withoutAsterisks ->
withoutAsterisks.substring(0, withoutAsterisks.lastIndexOfAny(charArrayOf('\\', '/')))
}
.let { Path(it) }

/**
* @param candidate
* @param currentDirectory
Expand All @@ -92,9 +98,3 @@ private fun getAbsoluteGlobAndRoot(glob: String, currentFolder: Path): Pair<Stri
roots.any { glob.startsWith(it, true) } -> glob to glob.findRoot()
else -> "${currentFolder.absolutePathString()}${File.separatorChar}$glob" to currentFolder
}

private fun String.findRoot(): Path = substring(0, indexOf('*'))
.let { withoutAsterisks ->
withoutAsterisks.substring(0, withoutAsterisks.lastIndexOfAny(charArrayOf('\\', '/')))
}
.let { Path(it) }
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import java.io.PrintStream
import java.nio.file.Path

import kotlin.io.path.invariantSeparatorsPathString
import kotlin.io.path.relativeTo
import kotlin.io.path.relativeToOrSelf

private const val CANNOT_BE_AUTOCORRECTED_SUFFIX = " (cannot be auto-corrected)"

Expand Down Expand Up @@ -92,7 +92,7 @@ fun String.correctErrorDetail(canBeAutoCorrected: Boolean): String = if (canBeAu
* @param sourceRootDir
* @return relative path to [sourceRootDir] as [String]
*/
fun Path.relativePathStringTo(sourceRootDir: Path?): String = (sourceRootDir?.let { relativeTo(it) } ?: this).invariantSeparatorsPathString
fun Path.relativePathStringTo(sourceRootDir: Path?): String = (sourceRootDir?.let { relativeToOrSelf(it) } ?: this).invariantSeparatorsPathString

/**
* @param out [OutputStream] for [ReporterV2]
Expand Down

0 comments on commit f1c89ba

Please sign in to comment.