-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
indent
rule wants to add trailing newlines/whitespaces to multi-line raw string literals
#1375
Comments
I think that's what my concern was exactly about #1262 (comment), but somehow it got ignored. We shouldn't change contents of raw strings if they are not followed by |
Not even then. You can safely increase or decrease the indent/margin of existing lines if one of those extensions is used, but adding a new line like this would still result in a change to the string's value. |
I can now see what your concerns were. In this case it indeed is wrong to align the closing quotes when not followed by trim indent/trimmargin. As documented on https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/trim-indent.html this method (same for trimmargin) do remove the trailing and pending newlines. Of course this does not happen for a raw string without them. |
@RBusarow Is your problem just an abstraction for a real problem in production code or just a semantic discussion about how you want to write unit tests? Semantically, you are still right, that this is unwanted behavior.
If above would be used in some production code like:
then this message would not not contain a newline at the beginning but also the indentation before the text See unit tests below, which clearly identifies the behavior between the approaches:
So is it really likely that this causes problems in production code? |
@paul-dingemans That's just an abstraction. My real-world example of 0.44.0's changes is here: https://github.com/RBusarow/ModuleCheck/pull/393/files. This project parses Java, Kotlin, Groovy, and XML files, and performs auto-corrections in Groovy and Kotlin Gradle files. It's important that whitespaces are handled correctly in tests, as well as in the changes being made to the Gradle files. The changes to this rule do not affect production code, but they affect my ability to test the production code. |
I'm having the same problem. 3.9.0 broke a bunch of tests that were working previously due to modifying raw string templates. It broke both tests, and the production code itself. I'd vote for reverting this behavior, or at least putting it behind a feature flag to let maintainers catch up to this change. (NB: I'm using the |
@RBusarow @gchallen I am gonna fix this in the next release. Meanwhile you can have a look at the IndentationRuleTest in ktlint. For example in Line 1272 in e1674f8
|
…mIndent() or trimMargin() Closes pinterest#1375
I saw this error in some code as well after updating. In this scenario the string literals (they were format templates) were defined as const and were relying on the specific whitespace formatting because the trimIndent() call couldn't be added without making them non-const. |
…mIndent() or trimMargin() Closes pinterest#1375
Expected Behavior
The
indent
rule should not change the values of raw strings.Observed Behavior
Since
0.44.0
(specifically from PR #1262), theindent
rule changes the position of the closing quotes of any multi-line raw string literal so that they're aligned. This isn't just a formatting change, since the added spaces and/or newline are added to the value of the actual string.Steps to Reproduce
Given this top-level (top level because the indent matters) property:
Formatting will change it to:
Your Environment
0.44.0
The text was updated successfully, but these errors were encountered: