Skip to content

Commit

Permalink
Enable Ktlint if-else-wrapping rule (#5513)
Browse files Browse the repository at this point in the history
  • Loading branch information
FloEdelmann authored Mar 1, 2024
1 parent ddf70a2 commit 1e320c1
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 81 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ ktlint_standard_chain-wrapping = disabled
ktlint_standard_comment-wrapping = disabled
ktlint_standard_function-naming = disabled
ktlint_standard_function-signature = disabled
ktlint_standard_if-else-wrapping = disabled
ktlint_standard_indent = disabled
ktlint_standard_max-line-length = disabled
ktlint_standard_multiline-expression-wrapping = disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ class ElementEditsController(
/** Undo edit with the given id. If unsynced yet, will delete the edit if it is undoable. If
* already synced, will add a revert of that edit as a new edit, if possible */
fun undo(edit: ElementEdit): Boolean {
// already uploaded
if (edit.isSynced) {
// already uploaded
val action = edit.action
if (action !is IsActionRevertable) return false
// first create the revert action, as ElementIdProvider will be deleted when deleting the edit
Expand All @@ -115,9 +115,8 @@ class ElementEditsController(
delete(edit)
// ... and add a new revert to the queue
add(ElementEdit(0, edit.type, edit.originalGeometry, edit.source, nowAsEpochMilliseconds(), false, reverted, edit.isNearUserLocation))
}
// not uploaded yet
else {
} else {
// not uploaded yet
delete(edit)
}
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,11 @@ class MapDataWithEditsSource internal constructor(

for (element in updated) {
val key = element.key
// an element contained in the update that was deleted by an edit shall be deleted
if (deletedElements.contains(key)) {
// an element contained in the update that was deleted by an edit shall be deleted
modifiedDeleted.add(key)
}
// otherwise, update if it was modified at all
else {
} else {
// otherwise, update if it was modified at all
val modifiedElement = updatedElements[key] ?: element
val modifiedGeometry = updatedGeometries[key] ?: updated.getGeometry(key.type, key.id)
modifiedElements.add(Pair(modifiedElement, modifiedGeometry))
Expand All @@ -124,12 +123,11 @@ class MapDataWithEditsSource internal constructor(

for (key in deleted) {
val modifiedElement = updatedElements[key]
// en element that was deleted shall not be deleted but instead added to the updates if it was updated by an edit
if (modifiedElement != null) {
// an element that was deleted shall not be deleted but instead added to the updates if it was updated by an edit
modifiedElements.add(Pair(modifiedElement, updatedGeometries[key]))
}
// otherwise, pass it through
else {
} else {
// otherwise, pass it through
modifiedDeleted.add(key)
}
}
Expand Down Expand Up @@ -345,13 +343,12 @@ class MapDataWithEditsSource internal constructor(

for (element in updatedElements.values) {
if (element is Way) {
// if the updated version of a way contains the node, put/replace the updated way
if (element.nodeIds.contains(id)) {
// if the updated version of a way contains the node, put/replace the updated way
waysById[element.id] = element
}
// if the updated version does not contain the node (anymore), we need to remove it
// from the output set (=an edit removed that node) - if it was contained at all
else {
} else {
// if the updated version does not contain the node (anymore), we need to remove it
// from the output set (=an edit removed that node) - if it was contained at all
waysById.remove(element.id)
}
}
Expand Down Expand Up @@ -382,13 +379,12 @@ class MapDataWithEditsSource internal constructor(

for (element in updatedElements.values) {
if (element is Relation) {
// if the updated version of a relation contains the node, put/replace the updated relation
if (element.members.any { it.type == type && it.ref == id }) {
// if the updated version of a relation contains the node, put/replace the updated relation
relationsById[element.id] = element
}
// if the updated version does not contain the node (anymore), we need to remove it
// from the output set (=an edit removed that node) - if it was contained at all
else {
} else {
// if the updated version does not contain the node (anymore), we need to remove it
// from the output set (=an edit removed that node) - if it was contained at all
relationsById.remove(element.id)
}
}
Expand All @@ -410,16 +406,15 @@ class MapDataWithEditsSource internal constructor(
// we will deal with nodes at the end
if (key.type == NODE) continue

// add the modified data if it is in the bbox
if (geometry != null && geometry.getBounds().intersect(bbox)) {
// add the modified data if it is in the bbox
val element = updatedElements[key]
if (element != null) {
mapData.put(element, geometry)
if (element is Way) addWays.add(element)
}
}
// or otherwise remove if it is not (anymore)
else {
} else {
// or otherwise remove if it is not (anymore)
mapData.remove(key.type, key.id)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ data class DeletePoiNodeAction(
throw ConflictException("Element geometry changed substantially")
}

// delete free-floating node
return if (
mapDataRepository.getWaysForNode(currentNode.id).isEmpty()
&& mapDataRepository.getRelationsForNode(currentNode.id).isEmpty()
) {
val isInWayOrRelation =
mapDataRepository.getWaysForNode(currentNode.id).isNotEmpty()
|| mapDataRepository.getRelationsForNode(currentNode.id).isNotEmpty()

return if (!isInWayOrRelation) {
// delete free-floating node
MapDataChanges(deletions = listOf(currentNode))
}
// if it is a vertex in a way or has a role in a relation: just clear the tags then
else {
} else {
// if it is a vertex in a way or has a role in a relation: just clear the tags then
val emptyNode = currentNode.copy(
tags = emptyMap(),
timestampEdited = nowAsEpochMilliseconds()
Expand Down
25 changes: 12 additions & 13 deletions app/src/main/java/de/westnordost/streetcomplete/osm/RoadWidth.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,18 @@ fun hasDubiousRoadWidth(tags: Map<String, String>): Boolean? {
// all others should at least be broad enough to accommodate a truck
return usableWidth < 2.6f
}
}
/* one may assume that if the usable width of non-oneway roads is below double the above
widths, it is also implausible, however, this is actually sometimes the case, by design:
- on 2-1 roads (roads with no car lanes markings and advisory cycle lanes on both sides)
https://en.wikipedia.org/wiki/2-1_road
- certain residential streets with (partial) on-street parking that narrow them down so
much that drivers have to do a slalom around the parking cars and have to wait on each
other to pass them
Hence, to declare such common cases implausible is dubious.
However, if the total carriageway (ignoring street parking etc.) of a non-oneway is below
2x the above, then it is dubious
*/
else {
} else {
/* one may assume that if the usable width of non-oneway roads is below double the above
widths, it is also implausible, however, this is actually sometimes the case, by design:
- on 2-1 roads (roads with no car lanes markings and advisory cycle lanes on both sides)
https://en.wikipedia.org/wiki/2-1_road
- certain residential streets with (partial) on-street parking that narrow them down so
much that drivers have to do a slalom around the parking cars and have to wait on each
other to pass them
Hence, to declare such common cases implausible is dubious.
However, if the total carriageway (ignoring street parking etc.) of a non-oneway is below
2x the above, then it is dubious
*/
val width = estimateRoadwayWidth(tags) ?: return null
return width < 2 * 2.6f
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ fun parseHouseNumbers(string: String): HouseNumbers? {
val end = parseHouseNumberParts(range[1]) ?: return null
if (start < end) {
HouseNumbersPartsRange(start, end)
}
// reverse ranges are interpreted like sub-housenumbers, i.e. 4-2 is about the same as 4/2
else {
} else {
// reverse ranges are interpreted like sub-housenumbers, i.e. 4-2 is about the same as 4/2
SingleHouseNumbersPart(parseHouseNumberParts(part) ?: return null)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,35 +267,32 @@ private suspend fun createEditAction(
val wasVacant = element != null && element.isDisusedPlace()
val isVacant = newFeature.id == "shop/vacant"

val shouldNotReplaceShop =
// only a name was added (name was missing before; user wouldn't be able to answer
// if the place changed or not anyway, so rather keep previous information)
hasAddedNames && !hasChangedFeature
// previously: only the feature was changed, the non-empty name did not change
// - see #5195
// place has been added, nothing to replace
|| element == null
val shouldAlwaysReplaceShop =
// the feature is or was a brand feature (i.e. overwrites the name)
isFeatureWithName || wasFeatureWithName
// was vacant before but not anymore (-> cleans up any previous tags that may be
// associated with the old place)
|| wasVacant && hasChangedFeature
// it's vacant now
|| isVacant

val doReplaceShop =
// do not replace shop if:
if (
// only a name was added (name was missing before; user wouldn't be able to answer
// if the place changed or not anyway, so rather keep previous information)
hasAddedNames && !hasChangedFeature
// previously: only the feature was changed, the non-empty name did not change
// - see #5195
// place has been added, nothing to replace
|| element == null
) {
if (shouldNotReplaceShop) {
false
}
// always replace if:
else if (
// the feature is a brand feature or was a brand feature (i.e. overwrites the name)
isFeatureWithName || wasFeatureWithName
// was vacant before but not anymore (-> cleans up any previous tags that may be
// associated with the old place
|| wasVacant && hasChangedFeature
// it's vacant now
|| isVacant
) {
} else if (shouldAlwaysReplaceShop) {
true
}
// ask whether it is still the same shop if:
// + the name was changed
// + the feature was changed and the name was empty before
else {
} else {
// ask whether it is still the same shop if:
// + the name was changed
// + the feature was changed and the name was empty before
confirmReplaceShop()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ class AddHousenumberForm : AbstractOsmQuestForm<HouseNumberAnswer>() {
val isUnusual = number?.looksInvalid(countryInfo.additionalValidHousenumberRegex) == true
confirmHouseNumber(isUnusual) {
applyAnswer(AddressNumberOrName(number, numberOrNameInputCtrl.houseName))
if (number is HouseAndBlockNumber) { number.blockNumber.let { lastBlockNumber = it } }
if (number is HouseAndBlockNumber) {
number.blockNumber.let { lastBlockNumber = it }
}
lastBlock = (number as? HouseNumberAndBlock)?.block
number?.streetHouseNumber?.let { lastHouseNumber = it }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ class EditHistoryAdapter(
if (syncedItemIndex != -1) {
Collections.swap(rows, syncedItemIndex, editIndex)
notifyItemMoved(syncedItemIndex, editIndex)
}
// there is no "synced" item yet
else {
} else {
// there is no "synced" item yet
rows.add(editIndex, IsSyncedItem)
notifyItemInserted(editIndex)
}
Expand Down

0 comments on commit 1e320c1

Please sign in to comment.