Skip to content
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

TrimMultilineRawString support for alternate trimming methods #5415

Closed
samuelneff opened this issue Oct 14, 2022 · 3 comments · Fixed by #6063
Closed

TrimMultilineRawString support for alternate trimming methods #5415

samuelneff opened this issue Oct 14, 2022 · 3 comments · Fixed by #6063

Comments

@samuelneff
Copy link

The TrimMultilineRawString (#5051) rule can be helpfully extended to allow custom trimming functions and chained functions.

Expected Behavior

Here is an example from our codebase:

fun String.collapseWhitespace(text: String) =
    trim().replace(Regex("\\s\\s+"), " ")

val blockWithoutAnyExtraWhitespace = """
    This is some text.

    Here is another line; spaced apart.
""".collapseWhitespace()

println(blockWithoutAnyExtraWhitespace)
// Prints: This is some text. Here is another line; spaced apart.

Current Behavior

Currently the rule requires trimIndent() or trimMargin() be called and nothing else is considered valid.

Context

See above example from our codebase that fails this rule but we would like to be able to pass.
Configuration with this change would include an additional option:

TrimMultilineRawString:
  additionalTrimmingMethods:
    - collapseWhitespace

Note: I'm working on another rule now for Hacktoberfest. If I actually get one done, I'll look into implementing this as well. Looks straightforward. Thanks for this great new rule!

@BraisGabin
Copy link
Member

Good idea! But instead of additionalTrimmimgMethods I would call it trimmingMethods and add the two default ones.

Do you want me to assign this issue to you?

@samuelneff
Copy link
Author

trimmingMethods

👍

assign this issue to you

hesitant 👍 😄

@BraisGabin
Copy link
Member

Hahaha, no pressure ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants