Skip to content

Commit

Permalink
refactor(node): Rename parseNpmAuthors() to singular form
Browse files Browse the repository at this point in the history
The function just parses a single author instance.

Signed-off-by: Frank Viernau <frank_viernau@epam.com>
  • Loading branch information
fviernau committed Sep 11, 2024
1 parent 3382b5b commit 9ea65f9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions plugins/package-managers/node/src/main/kotlin/Npm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.NpmModuleInfo
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.expandNpmShortcutUrl
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.fixNpmDownloadUrl
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.mapNpmLicenses
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.parseNpmAuthors
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.parseNpmAuthor
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.parseNpmVcsInfo
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.splitNpmNamespaceAndName
import org.ossreviewtoolkit.utils.common.CommandLineTool
Expand Down Expand Up @@ -279,7 +279,7 @@ open class Npm(
val version = packageJson.version ?: NON_EXISTING_SEMVER

val declaredLicenses = packageJson.licenses.mapNpmLicenses()
val authors = parseNpmAuthors(packageJson.author)
val authors = parseNpmAuthor(packageJson.author)

var description = packageJson.description.orEmpty()
var homepageUrl = packageJson.homepage.orEmpty()
Expand Down Expand Up @@ -542,7 +542,7 @@ open class Npm(
}

val declaredLicenses = packageJson.licenses.mapNpmLicenses()
val authors = parseNpmAuthors(packageJson.author)
val authors = parseNpmAuthor(packageJson.author)
val homepageUrl = packageJson.homepage.orEmpty()
val projectDir = packageJsonFile.parentFile
val vcsFromPackage = parseNpmVcsInfo(packageJson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private val ARTIFACTORY_API_PATH_PATTERN = Regex("(.*artifactory.*)/api/npm/(.*)
* https://docs.npmjs.com/files/package.json#people-fields-author-contributors, there are two formats to
* specify the author of a package: An object with multiple properties or a single string.
*/
internal fun parseNpmAuthors(author: PackageJson.Author?): Set<String> =
internal fun parseNpmAuthor(author: PackageJson.Author?): Set<String> =
author?.let {
if (it.url == null && it.email == null) {
// The author might either originate from a textual node or from an object node. The former to
Expand Down
4 changes: 2 additions & 2 deletions plugins/package-managers/node/src/main/kotlin/yarn2/Yarn2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.NodePackageManage
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.NpmDetection
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.fixNpmDownloadUrl
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.mapNpmLicenses
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.parseNpmAuthors
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.parseNpmAuthor
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.parseNpmVcsInfo
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.splitNpmNamespaceAndName
import org.ossreviewtoolkit.utils.common.CommandLineTool
Expand Down Expand Up @@ -579,7 +579,7 @@ class Yarn2(
val description = packageJson.description.orEmpty()
val vcsFromPackage = parseNpmVcsInfo(packageJson)
val homepage = packageJson.homepage.orEmpty()
val author = parseNpmAuthors(packageJson.author)
val author = parseNpmAuthor(packageJson.author)
val downloadUrl = packageJson.dist?.tarball.orEmpty().fixNpmDownloadUrl()

val hash = Hash.create(packageJson.dist?.shasum.orEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ class NpmSupportTest : WordSpec({
}
}

"parseNpmAuthors()" should {
"parseNpmAuthor()" should {
"get authors from a text node" {
val author = Author(name = "Jane Doe <jane.doe@example.com>")

parseNpmAuthors(author) shouldBe setOf("Jane Doe")
parseNpmAuthor(author) shouldBe setOf("Jane Doe")
}

"get authors from an object node" {
val author = Author(name = "John Doe")

parseNpmAuthors(author) shouldBe setOf("John Doe")
parseNpmAuthor(author) shouldBe setOf("John Doe")
}
}

Expand Down

0 comments on commit 9ea65f9

Please sign in to comment.