Repository: detekt/detekt (kotlin)

Issue:
`MaxLineLength` `excludeRawStrings` false negative
<!-- The bug you're experiencing might have already be reported! -->
<!-- Please search in the [issues](https://github.com/detekt/detekt/issues) before creating one. -->

## Expected Behavior
<!-- Tell us what should happen -->
After setting `excludeRawStrings` on `true` in `MaxLineLength` linter should ignore raw strings.

## Observed Behavior
<!-- Tell us what happens instead of the expected behavior -->
As shown [here](https://github.com/GrzegorzBobryk/ViewBindingDelegate/pull/20/files). If we create raw string that is single line detekt will see error in it. Moving only closing quote signs to new line is making it pass lint check.

Logs [here](https://github.com/GrzegorzBobryk/ViewBindingDelegate/actions/runs/10442354185/job/28914579007?pr=20).
```shell
/home/runner/work/ViewBindingDelegate/ViewBindingDelegate/sample/src/main/kotlin/pl/beavercoding/viewbindingdelegate/ExampleFragment3.kt:30:1: Exceeded max line length (120) [MaximumLineLength]
/home/runner/work/ViewBindingDelegate/ViewBindingDelegate/sample/src/main/kotlin/pl/beavercoding/viewbindingdelegate/ExampleFragment3.kt:30:1: Line detected, which is longer than the defined maximum line length in the code style. [MaxLineLength]
```

## Steps to Reproduce
<!-- Provide a link to a live example, or an unambiguous set of steps to -->
<!-- reproduce this bug. Include code to reproduce, if relevant -->
- Set `excludeRawStrings: true` in `MaxLineLength`;
- Add some long raw single line string that should brake linter if it was a normal line. For example:
`"""C:\Repository\test\test\test\test\test\test\test\test\test\test\test\test\test\test\test\test\test\test\test\test\test\some_file.pdf"""`
![obraz](https://github.com/user-attachments/assets/534cac43-e88b-4a15-b7c6-b74c0e6eb71b)
- Run detekt;

## Context
<!-- How has this issue affected you? What are you trying to accomplish? -->
<!-- Providing context helps us come up with a solution that is most useful in the real world -->
I want to ignore all raw strings. I can create one with special characters that do not need to be escaped. For example very long path to file.

## Your Environment
<!-- Include as many relevant details about the environment you experienced the bug in -->
* Version of detekt used: 1.23.6
* Version of Gradle used (if applicable): 8.7
* Gradle scan link (add `--scan` option when running the gradle task):
* Operating System and version: Windows 11
* Link to your project (if it's a public repository): included above
 [pr with bug example](https://github.com/GrzegorzBobryk/ViewBindingDelegate/pull/20/files)
 [logs from CI/CD](https://github.com/GrzegorzBobryk/ViewBindingDelegate/actions/runs/10442354185/job/28914579007?pr=20)

Pull request:
Fixes: https://github.com/detekt/detekt/issues/7555

Patch:
diff --git a/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/MaxLineLength.kt b/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/MaxLineLength.kt
index 61307b23dedd..862b6f5138a9 100644
--- a/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/MaxLineLength.kt
+++ b/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/MaxLineLength.kt
@@ -90,7 +90,10 @@ class MaxLineLength(config: Config) : Rule(
     private fun containsIgnoredRawString(file: KtFile, offset: Int, line: String): Boolean {
         if (!excludeRawStrings) return false
 
-        return findKtElementInParents(file, offset, line).lastOrNull()?.isInsideRawString() == true
+        return findKtElementInParents(file, offset, line)
+            .sortedBy { it.textOffset }
+            .lastOrNull()
+            ?.isInsideRawString() == true
     }
 
     private fun containsIgnoredPackageStatement(line: String): Boolean {


Test patch:
diff --git a/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/MaxLineLengthSpec.kt b/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/MaxLineLengthSpec.kt
index 7f26ece9f901..df1289ed4b26 100644
--- a/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/MaxLineLengthSpec.kt
+++ b/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/MaxLineLengthSpec.kt
@@ -113,6 +113,38 @@ class MaxLineLengthSpec {
             val locations = findings.map { it.entity.signature.substringAfterLast('$') }
             doAssert(locations).allSatisfy { doAssert(it).isNotBlank() }
         }
+
+        @Test
+        fun `should not report raw string with spaces - #7555`() {
+            val rule = MaxLineLength(TestConfig())
+            val code = """
+                class MaxLineLength {
+                    val longSingleLineRawString1 =
+                        ${TQ}This is first yet another very very very very very very very very very very very very very very very very very very very very very very very very very very very very$TQ
+
+                    val longSingleLineRawString2 =
+                        $TQ
+                            This is second yet another very very very very very very very very very very very very very very very very very very very very very very very very very very very very$TQ
+
+                    val longSingleLineRawString3 =
+
+                        $TQ
+                            This is third yet another very very very very very very very very very very very very very very very very very very very very very very very very very very very$TQ
+
+                    val longSingleLineRawString4 =
+
+                        $TQ
+
+                            This is third yet another very very very very very very very very very very very very very very very very very very very very very very very very very very very$TQ
+
+                    val longSingleLineRawString2WithTrimIndent =
+                        $TQ
+                            This is second yet another very very very very very very very very very very very very very very very very very very very very very very very very very very very very$TQ
+                        .trimIndent()
+                }
+            """.trimIndent()
+            assertThat(rule.compileAndLint(code)).isEmpty()
+        }
     }
 
     @Nested