Skip to content

Commit

Permalink
Review: Remove side-effects from calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jckoenen committed Jan 10, 2024
1 parent e47f283 commit 86e6ab6
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions sarif/src/main/java/com/jetbrains/qodana/sarif/baseline/Baseline.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,23 @@ internal fun applyBaseline(report: Run, baseline: Run, options: Options): DiffSt
}
.toCollection(IdentitySet(report.results?.size ?: 0))

val undecidedFromBaseline = baseline.results.noNulls()
.filterNot { it.baselineState == BaselineState.ABSENT }
.onEach { result -> baselineCounter.increment(ResultKey(result)) }
.filter { result ->
val foundInReport = result.equalIndicators
.flatMap(reportIndex::getOrEmpty)
.filter(undecidedFromReport::remove)
.onEach { state.put(it, BaselineState.UNCHANGED) }
.firstOrNull() != null

if (foundInReport) {
return@filter false
}
if (!options.wasChecked.apply(result)) {
state.put(result, BaselineState.UNCHANGED)
return@filter false
val undecidedFromBaseline = buildList {
baseline.results.noNulls()
.filterNot { it.baselineState == BaselineState.ABSENT }
.onEach { result -> baselineCounter.increment(ResultKey(result)) }
.forEach { result ->
val removedFromReport = result.equalIndicators
.flatMap(reportIndex::getOrEmpty)
.any(undecidedFromReport::remove)

if (removedFromReport || !options.wasChecked.apply(result)) {
state.put(result, BaselineState.UNCHANGED)
} else {
add(result)
}
}
true
}
.toMutableList()
}


undecidedFromReport.forEach { result ->
val key = ResultKey(result)
Expand All @@ -90,9 +87,12 @@ internal fun applyBaseline(report: Run, baseline: Run, options: Options): DiffSt
undecidedFromBaseline
.asSequence()
.filter { baselineCounter.decrement(ResultKey(it)) >= 0 }
.filter { state.put(it, BaselineState.ABSENT) }
.filter { reportDescriptors.findById(it.ruleId) == null }
.forEach { baselineDescriptors.findById(it.ruleId)?.addTo(report) }
.forEach { result ->
val added = state.put(result, BaselineState.ABSENT)
if (added && reportDescriptors.findById(result.ruleId) == null) {
baselineDescriptors.findById(result.ruleId)?.addTo(report)
}
}

report.withResults(state.results)

Expand Down

0 comments on commit 86e6ab6

Please sign in to comment.