Skip to content

Commit

Permalink
feat: add isChanged() to avoid rewriting unchanged files.
Browse files Browse the repository at this point in the history
This is important because the rewritten() method will trim whitespace even if it does nothing else, which we want to avoid.
  • Loading branch information
autonomousapps committed Dec 4, 2024
1 parent 69a25da commit aa2fa86
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ public class DependenciesSimplifier private constructor(
private val terminalNewlines = Whitespace.countTerminalNewlines(tokens)
private val dependencyExtractor = DependencyExtractor(input, tokens, indent)

private var changes = false
private var isInBuildscriptBlock = false

public fun isChanged(): Boolean = changes

@Throws(KotlinParseException::class)
public fun rewritten(): String {
errorListener.getErrorMessages().ifNotEmpty {
Expand Down Expand Up @@ -76,6 +79,7 @@ public class DependenciesSimplifier private constructor(
val newText = simplify(declaration)

if (newText != null) {
changes = true
rewriter.replace(elementCtx.start, getStop(elementCtx), newText)
}
}
Expand Down

0 comments on commit aa2fa86

Please sign in to comment.