Skip to content

Perform an overall code cleanup #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f8d9f5b
chore: bump Detekt max return count to 3
lppedd Apr 9, 2024
cab23dd
refactor: cleanup DiffRow
lppedd Apr 9, 2024
0dd6404
refactor: cleanup StringUtils
lppedd Apr 9, 2024
fdd1fe7
refactor: extract DiffException and cleanup PatchFailedException
lppedd Apr 9, 2024
d0dafbd
refactor: cleanup Patch
lppedd Apr 9, 2024
0b801c0
refactor: extract ConflictProducingConflictOutput and ExceptionProduc…
lppedd Apr 9, 2024
9263f60
refactor: extract Delta types
lppedd Apr 9, 2024
67e2498
refactor: cleanup Chunk
lppedd Apr 9, 2024
8b18c96
refactor: cleanup DiffAlgorithmListener
lppedd Apr 9, 2024
09f6722
refactor: cleanup DiffAlgorithm
lppedd Apr 9, 2024
9ec8eaf
refactor: cleanup Change
lppedd Apr 9, 2024
277c233
refactor: cleanup PathNode
lppedd Apr 9, 2024
8dc3387
refactor: cleanup MyersDiff
lppedd Apr 9, 2024
45b0c83
refactor: cleanup DiffUtils
lppedd Apr 9, 2024
ddb263a
refactor: replace nullable DiffAlgorithmListener with NoopAlgorithmLi…
lppedd Apr 9, 2024
8090357
tests: align test cases with the refactored code
lppedd Apr 9, 2024
c476089
refactor: remove explicit Throws
lppedd Apr 9, 2024
deac3c4
refactor: delegate checking VerifyChunk type to ConflictOutput implem…
lppedd Apr 9, 2024
78b34fa
chore: enable TrailingCommaOnDeclarationSite
lppedd Apr 10, 2024
581b6ef
chore: disable ForbiddenComment
lppedd Apr 10, 2024
473c3aa
refactor: address review comments
lppedd Apr 10, 2024
04efa7a
refactor: rework MyersDiff.buildRevision to avoid unnecessary non-nul…
lppedd Apr 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: remove explicit Throws
Explicit throws indicator are not idiomatic to Kotlin,
and they tend to become out of sync pretty fast with
the actual code that is *supposed* to throw.
  • Loading branch information
lppedd committed Apr 10, 2024
commit c476089849dd60531f7460b2b2b461075a1fd3d2
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ public fun diffInline(original: String, revised: String): Patch<String> {
* @return The revised text
* @throws PatchFailedException If the patch cannot be applied
*/
@Throws(PatchFailedException::class)
public fun <T> patch(original: List<T>, patch: Patch<T>): List<T> =
patch.applyTo(original)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@
package io.github.petertrr.diffutils.patch

public fun interface ConflictOutput<T> {
@Throws(PatchFailedException::class)
public fun processConflict(verifyChunk: VerifyChunk, delta: Delta<T>, result: MutableList<T>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ public sealed class Delta<T>(public val type: DeltaType) {
/**
* Verify the chunk of this delta, to fit the target.
*/
@Throws(PatchFailedException::class)
protected open fun verifyChunkToFitTarget(target: List<T>): VerifyChunk {
return source.verify(target)
}
protected open fun verifyChunkToFitTarget(target: List<T>): VerifyChunk =
source.verify(target)

@Throws(PatchFailedException::class)
public open fun verifyAndApplyTo(target: MutableList<T>): VerifyChunk {
val verify = verifyChunkToFitTarget(target)

Expand All @@ -44,7 +41,6 @@ public sealed class Delta<T>(public val type: DeltaType) {
return verify
}

@Throws(PatchFailedException::class)
protected abstract fun applyTo(target: MutableList<T>)

public abstract fun restore(target: MutableList<T>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ package io.github.petertrr.diffutils.patch

public class ExceptionProducingConflictOutput<T> : ConflictOutput<T> {
override fun processConflict(verifyChunk: VerifyChunk, delta: Delta<T>, result: MutableList<T>): Nothing =
throw PatchFailedException("Could not apply patch due to $verifyChunk")
throw PatchFailedException("Could not apply patch due to: $verifyChunk")
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public class Patch<T>(private var conflictOutput: ConflictOutput<T> = ExceptionP
* Apply this patch to the given target.
*
* @return The patched text
* @throws PatchFailedException If the patch cannot be applied
*/
@Throws(PatchFailedException::class)
public fun applyTo(target: List<T>): List<T> {
val result = target.toMutableList()
val it = deltas.listIterator(deltas.size)
Expand Down