From c70c35d9ed09667b4e390a3561112087257b9077 Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Fri, 26 Jan 2024 10:13:46 +0100 Subject: [PATCH] refactor(npm): Extract two constants Add documentation without polluting the function body with it. Signed-off-by: Frank Viernau --- .../node/src/main/kotlin/Npm.kt | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/plugins/package-managers/node/src/main/kotlin/Npm.kt b/plugins/package-managers/node/src/main/kotlin/Npm.kt index 7615b68021f8a..43e295f9ccb31 100644 --- a/plugins/package-managers/node/src/main/kotlin/Npm.kt +++ b/plugins/package-managers/node/src/main/kotlin/Npm.kt @@ -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() + private fun List.groupLines(marker: String): List { - val ignorableLinePrefixes = setOf( - "code ", - "deprecated ", - "errno ", - "path ", - "skipping integrity check for git dependency ", - "syscall " - ) - val singleLinePrefixes = emptySet() 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 @@ -668,7 +672,7 @@ private fun List.groupLines(marker: String): List { } } - 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