Comments (1)
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)
- Enforce whitespace between configuration sets HOT 4
- Using current directory abbreviation `.` will lead to empty `buildDotGradles`
- Warning messages are not printed to standard output
- Do not fail on modules with no build script HOT 2
- Support variantOf in add calls HOT 2
- Support string literal dependency notation for add calls HOT 2
- Allow a custom naming strategy
- Support `kotlin()` dependency syntax
- The suggestion to fixed non-sorted dependencies is wrong
- [Enhancement] Remove duplicate declarations while sorting
- Add dependency constraints sorting
- Version 0.7 not available? HOT 1
- Sort Dependencies Fails on `if` blocks
- Support IntelliJ Platform Dependency extension syntax
- sortDepenecncies fails on fileTree
- Make "check" and "sort" tasks cacheable
- 0.8 regression: IndexOutOfBoundsException when collecting dependencies
- Add support for build scripts that are renamed from build.gradle
- IllegalArgumentException: List has more than one element when BOM is included
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gradle-dependencies-sorter.