def selectNext()

in modules/core/src/main/scala/org/scalasteward/core/data/Version.scala [39:86]


  def selectNext(versions: List[Version], allowPreReleases: Boolean = false): Option[Version] = {
    val cutoff = alnumComponentsWithoutPreRelease.length - 1
    val newerVersionsByCommonPrefix =
      if (this.isPreRelease && allowPreReleases) {
        versions.groupBy(_ => List.empty)
      } else {
        versions
          .filter(_ > this)
          .groupBy(_.alnumComponents.zip(alnumComponents).take(cutoff).takeWhile { case (c1, c2) =>
            c1 === c2
          })
      }

    newerVersionsByCommonPrefix.toList
      .sortBy { case (commonPrefix, _) => commonPrefix.length }
      .flatMap { case (commonPrefix, vs) =>
        val sameSeries = cutoff === commonPrefix.length

        val preReleasesFilter: Version => Boolean = v =>
          // Do not select snapshots if we are not already on snapshot
          v.isSnapshot && !isSnapshot

        val releasesFilter: Version => Boolean = v =>
          // Do not select pre-releases of different series.
          (v.isPreRelease && !sameSeries) ||
            // Do not select pre-releases of the same series if this is not a pre-release.
            (v.isPreRelease && !isPreRelease && sameSeries) ||
            // Do not select versions with pre-release identifiers whose order is smaller
            // than the order of possible pre-release identifiers in this version. This,
            // for example, prevents updates from 2.1.4.0-RC17 to 2.1.4.0-RC17+1-307f2f6c-SNAPSHOT.
            (v.minAlphaOrder < minAlphaOrder) ||
            // Do not select a version with hash if this version contains no hash.
            (v.containsHash && !containsHash)

        val commonFilter: Version => Boolean = v =>
          // Do not select versions that are identical up to the hashes.
          v.alnumComponents === alnumComponents ||
            // Don't select "versions" like %5BWARNING%5D.
            !v.startsWithLetterOrDigit

        vs.filterNot { v =>
          commonFilter(v) ||
          (!allowPreReleases && releasesFilter(v)) ||
          (allowPreReleases && preReleasesFilter(v))
        }.sorted
      }
      .lastOption
  }