GithubHelp home page GithubHelp logo

Comments (1)

nebulon42 avatar nebulon42 commented on August 23, 2024

Maybe the issue is not detected in the tests because of the use of trimmedLinesOf which seems to strip the whitespace away.

A quick fix would be to transform the newline chars that are added by the StringBuilder to the system newline characters and additionally trim away trailing carriage returns (if present) from the tokenization.

Index: sort/src/main/kotlin/com/squareup/sort/kotlin/KotlinSorter.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/sort/src/main/kotlin/com/squareup/sort/kotlin/KotlinSorter.kt b/sort/src/main/kotlin/com/squareup/sort/kotlin/KotlinSorter.kt
--- a/sort/src/main/kotlin/com/squareup/sort/kotlin/KotlinSorter.kt	(revision 7496c0a0281bcc61aac8c84db2c80de982efbe20)
+++ b/sort/src/main/kotlin/com/squareup/sort/kotlin/KotlinSorter.kt	(date 1723210091951)
@@ -87,7 +87,7 @@
 
   override fun exitNamedBlock(ctx: NamedBlockContext) {
     if (ctx.isDependencies) {
-      rewriter.replace(ctx.start, ctx.stop, dependenciesBlock())
+      rewriter.replace(ctx.start, ctx.stop, dependenciesBlock().replace("\n", System.lineSeparator()))
 
       // Whenever we exit a dependencies block, clear this map. Each block will be treated separately.
       mutableDependencies.clear()
@@ -148,10 +148,10 @@
             newOrder += declaration
 
             // Write preceding comments if there are any
-            if (texts.comment != null) appendLine(texts.comment)
+            if (texts.comment != null) appendLine(texts.comment.replace("\r", ""))
 
             append(indent.repeat(level))
-            appendLine(texts.declarationText)
+            appendLine(texts.declarationText.replace("\r", ""))
           }
       }
 

I have tried this out in a snapshot JAR and it fixes the problem for me (in Kotlin syntax, do not have Groovy available). It feels a bit ugly that is why I didn't open a PR for it yet. Since I lack the deeper knowledge about the library I'm unsure if there is a better solution.

from gradle-dependencies-sorter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.