Skip to content

Commit 74d10fb

Browse files
authored
Merge pull request #133 from xuwei-k/return
avoid `return`
2 parents 425fcae + 5c55005 commit 74d10fb

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/main/scala/sbtlicensereport/license/LicenseReport.scala

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,20 +147,23 @@ object LicenseReport {
147147
// Even though the url is optional this field seems to always exist
148148
val licensesWithUrls = licenses.collect { case (name, Some(url)) => (name, url) }
149149
if (licensesWithUrls.isEmpty) {
150-
return LicenseInfo(LicenseCategory.NoneSpecified, "", "")
151-
}
152-
// We look for a license matching the category in the order they are defined.
153-
// i.e. the user selects the licenses they prefer to use, in order, if an artifact is dual-licensed (or more)
154-
for (category <- categories) {
155-
for (license <- licensesWithUrls) {
156-
val (name, url) = license
157-
if (category.unapply(name)) {
158-
return LicenseInfo(category, name, url)
150+
LicenseInfo(LicenseCategory.NoneSpecified, "", "")
151+
} else {
152+
// We look for a license matching the category in the order they are defined.
153+
// i.e. the user selects the licenses they prefer to use, in order, if an artifact is dual-licensed (or more)
154+
categories
155+
.flatMap(category =>
156+
licensesWithUrls.collectFirst {
157+
case (name, url) if category.unapply(name) =>
158+
LicenseInfo(category, name, url)
159+
}
160+
)
161+
.headOption
162+
.getOrElse {
163+
val license = licensesWithUrls(0)
164+
LicenseInfo(LicenseCategory.Unrecognized, license._1, license._2)
159165
}
160-
}
161166
}
162-
val license = licensesWithUrls(0)
163-
LicenseInfo(LicenseCategory.Unrecognized, license._1, license._2)
164167
}
165168

166169
/** Picks a single license (or none) for this dependency. */

0 commit comments

Comments
 (0)