chore(purity): eliminate suppressions

This commit is contained in:
yairm210 2025-07-29 18:12:09 +03:00
parent ba6b20925e
commit 5cda15ff3c
4 changed files with 15 additions and 13 deletions

View File

@ -473,7 +473,7 @@ class Civilization : IsPartOfGameInfoSerialization {
* Returns a dictionary of ALL resource names, and the amount that the civ has of each * Returns a dictionary of ALL resource names, and the amount that the civ has of each
* Stockpiled resources return the stockpiled amount * Stockpiled resources return the stockpiled amount
*/ */
@Readonly @Suppress("purity") // component1, component2 @Readonly
fun getCivResourcesByName(): HashMap<String, Int> { fun getCivResourcesByName(): HashMap<String, Int> {
@LocalState @LocalState
val hashMap = HashMap<String, Int>(gameInfo.ruleset.tileResources.size) val hashMap = HashMap<String, Int>(gameInfo.ruleset.tileResources.size)

View File

@ -26,6 +26,7 @@ import com.unciv.models.ruleset.unit.BaseUnit
import com.unciv.models.ruleset.unit.UnitType import com.unciv.models.ruleset.unit.UnitType
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import com.unciv.ui.components.UnitMovementMemoryType import com.unciv.ui.components.UnitMovementMemoryType
import yairm210.purity.annotations.Cache
import yairm210.purity.annotations.LocalState import yairm210.purity.annotations.LocalState
import yairm210.purity.annotations.Readonly import yairm210.purity.annotations.Readonly
import java.text.DecimalFormat import java.text.DecimalFormat
@ -67,7 +68,7 @@ class MapUnit : IsPartOfGameInfoSerialization {
var automated: Boolean = false var automated: Boolean = false
// We can infer who we are escorting based on our tile // We can infer who we are escorting based on our tile
var escorting: Boolean = false @Cache private var escorting: Boolean = false
var automatedRoadConnectionDestination: Vector2? = null var automatedRoadConnectionDestination: Vector2? = null
// Temp disable, since this data broke saves // Temp disable, since this data broke saves

View File

@ -258,7 +258,7 @@ enum class Countables(
open val noPlaceholders = !text.contains('[') open val noPlaceholders = !text.contains('[')
// Leave these in place only for the really simple cases // Leave these in place only for the really simple cases
open fun matches(parameterText: String) = if (noPlaceholders) parameterText == text @Readonly open fun matches(parameterText: String) = if (noPlaceholders) parameterText == text
else parameterText.equalsPlaceholderText(placeholderText) else parameterText.equalsPlaceholderText(placeholderText)
/** Needs to return the ENTIRE countable, not just parameters. */ /** Needs to return the ENTIRE countable, not just parameters. */
@ -267,7 +267,7 @@ enum class Countables(
/** This indicates whether a parameter *is of this countable type*, not *whether its parameters are correct* /** This indicates whether a parameter *is of this countable type*, not *whether its parameters are correct*
* E.g. "[fakeBuilding] Buildings" is obviously a countable of type "[buildingFilter] Buildings", therefore matches will return true. * E.g. "[fakeBuilding] Buildings" is obviously a countable of type "[buildingFilter] Buildings", therefore matches will return true.
* But it has another problem, which is that the building filter is bad, so its getErrorSeverity will return "ruleset specific" */ * But it has another problem, which is that the building filter is bad, so its getErrorSeverity will return "ruleset specific" */
open fun matches(parameterText: String, ruleset: Ruleset): Boolean = false @Readonly open fun matches(parameterText: String, ruleset: Ruleset): Boolean = false
@Readonly @Suppress("purity") abstract fun eval(parameterText: String, gameContext: GameContext): Int? @Readonly @Suppress("purity") abstract fun eval(parameterText: String, gameContext: GameContext): Int?
open val documentationHeader get() = open val documentationHeader get() =
@ -290,7 +290,7 @@ enum class Countables(
getErrorSeverity(parameterText.getPlaceholderParameters().first(), ruleset) getErrorSeverity(parameterText.getPlaceholderParameters().first(), ruleset)
companion object { companion object {
@Readonly @Suppress("purity") @Readonly
fun getMatching(parameterText: String, ruleset: Ruleset?) = Countables.entries fun getMatching(parameterText: String, ruleset: Ruleset?) = Countables.entries
.firstOrNull { .firstOrNull {
if (it.matchesWithRuleset) if (it.matchesWithRuleset)

View File

@ -476,17 +476,17 @@ private fun String.translateIndividualWord(language: String, hideIcons: Boolean,
* For example, a string like 'The city of [New [York]]' will return ['New [York]'], * For example, a string like 'The city of [New [York]]' will return ['New [York]'],
* allowing us to have nested translations! * allowing us to have nested translations!
*/ */
@Readonly @Pure @Suppress("purity") // IntRange.forEach should be recognized as pure
fun String.getPlaceholderParameters(): List<String> { fun String.getPlaceholderParameters(): List<String> {
if (!this.contains('[')) return emptyList() if (!this.contains('[')) return emptyList()
val stringToParse = this.removeConditionals() val stringToParse = this.removeConditionals()
@LocalState @LocalState val parameters = ArrayList<String>()
val parameters = ArrayList<String>()
var depthOfBraces = 0 var depthOfBraces = 0
var startOfCurrentParameter = -1 var startOfCurrentParameter = -1
for (i in stringToParse.indices) { val stringIndices = stringToParse.indices
stringIndices.forEach { i ->
if (stringToParse[i] == '[') { if (stringToParse[i] == '[') {
if (depthOfBraces == 0) startOfCurrentParameter = i+1 if (depthOfBraces == 0) startOfCurrentParameter = i+1
depthOfBraces++ depthOfBraces++
@ -499,16 +499,17 @@ fun String.getPlaceholderParameters(): List<String> {
return parameters return parameters
} }
@Readonly @Pure
fun String.getPlaceholderText(): String { fun String.getPlaceholderText(): String {
var stringToReturn = this.removeConditionals() var stringToReturn = this.removeConditionals()
val placeholderParameters = stringToReturn.getPlaceholderParameters() @LocalState val placeholderParameters = stringToReturn.getPlaceholderParameters()
for (placeholderParameter in placeholderParameters) placeholderParameters.forEach { placeholderParameter ->
stringToReturn = stringToReturn.replaceFirst("[$placeholderParameter]", "[]") stringToReturn = stringToReturn.replaceFirst("[$placeholderParameter]", "[]")
}
return stringToReturn return stringToReturn
} }
@Readonly @Pure
fun String.equalsPlaceholderText(str: String): Boolean { fun String.equalsPlaceholderText(str: String): Boolean {
if (isEmpty()) return str.isEmpty() if (isEmpty()) return str.isEmpty()
if (str.isEmpty()) return false // Empty strings have no .first() if (str.isEmpty()) return false // Empty strings have no .first()