Skip to content

Commit

Permalink
refactor(npm): Extract two constants
Browse files Browse the repository at this point in the history
Add documentation without polluting the function body with it.

Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed Jan 26, 2024
1 parent 8653468 commit c70c35d
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions plugins/package-managers/node/src/main/kotlin/Npm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -633,20 +633,24 @@ private fun nodeModulesDirForPackageJson(packageJson: File): File? {
return modulesDir.takeIf { it.name == "node_modules" }
}

// Prefixes of std.err lines which can be ignored.
private val IGNORABLE_LINE_PREFIXES = setOf(
"code ",
"deprecated ",
"errno ",
"path ",
"skipping integrity check for git dependency ",
"syscall "
)

// Prefixes of std.err lines which imply that a line with that prefix is not a multi-line output.
private val SINGLE_LINE_PREFIXES = emptySet<String>()

private fun List<String>.groupLines(marker: String): List<String> {
val ignorableLinePrefixes = setOf(
"code ",
"deprecated ",
"errno ",
"path ",
"skipping integrity check for git dependency ",
"syscall "
)
val singleLinePrefixes = emptySet<String>()
val minCommonPrefixLength = 5

val issueLines = mapNotNull { line ->
line.withoutPrefix(marker)?.takeUnless { ignorableLinePrefixes.any { prefix -> it.startsWith(prefix) } }
line.withoutPrefix(marker)?.takeUnless { IGNORABLE_LINE_PREFIXES.any { prefix -> it.startsWith(prefix) } }
}

var commonPrefix: String
Expand All @@ -668,7 +672,7 @@ private fun List<String>.groupLines(marker: String): List<String> {
}
}

if (commonPrefix !in singleLinePrefixes && commonPrefix.length >= minCommonPrefixLength) {
if (commonPrefix !in SINGLE_LINE_PREFIXES && commonPrefix.length >= minCommonPrefixLength) {
// Do not drop the whole prefix but keep the space when concatenating lines.
messages[messages.size - 1] += line.drop(commonPrefix.length - 1).trimEnd()
previousPrefix = commonPrefix
Expand Down

0 comments on commit c70c35d

Please sign in to comment.