Skip to content

Remove unnecessary String.raw tags from template literals - #7731

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260809-050251-a0bb7324
Open

Remove unnecessary String.raw tags from template literals#7731
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260809-050251-a0bb7324

Conversation

@sonarqube-agent

Copy link
Copy Markdown
Contributor

This PR was automatically created by the Remediation Agent's Scheduled backlog remediation feature.

Why these issues? All issues share the same rule (typescript:S7780) with deterministic, localized fixes—removal of unnecessary String.raw calls. Prioritized the single file (locations.ts) containing all 5 occurrences to maximize coherence and efficiency, despite MINOR severity, as the automated fix is straightforward and risk-free.

Fixed 5 SonarQube code smells in locations.ts by removing unnecessary String.raw tags from template literals that don't contain backslash characters. String.raw is only needed when a string contains literal backslashes that require escaping, so removing it from these regex pattern strings simplifies the code without changing behavior.

View Project in SonarCloud


Fixed Issues

typescript:S7780 - Using `String.raw` is unnecessary as the string does not contain any `\`. • MINORView issue

Location: packages/analysis/tests/jsts/tools/testers/comment-based/helpers/locations.ts:28

Why is this an issue?

String literals with escaped backslashes can be difficult to read and maintain. Each backslash character must be escaped with another backslash, creating sequences like \\ that are hard to interpret at a glance.

What changed

Removes the unnecessary String.raw tag from the template literal *(?: on line 33. This string contains no backslash characters, so String.raw is not needed. Replacing it with a regular string fixes the code smell.

--- a/packages/analysis/tests/jsts/tools/testers/comment-based/helpers/locations.ts
+++ b/packages/analysis/tests/jsts/tools/testers/comment-based/helpers/locations.ts
@@ -33,1 +33,1 @@ const LOCATION_PATTERN = new RegExp(
-    String.raw` *(?:` +
+    ` *(?:` +
typescript:S7780 - Using `String.raw` is unnecessary as the string does not contain any `\`. • MINORView issue

Location: packages/analysis/tests/jsts/tools/testers/comment-based/helpers/locations.ts:33

Why is this an issue?

String literals with escaped backslashes can be difficult to read and maintain. Each backslash character must be escaped with another backslash, creating sequences like \\ that are hard to interpret at a glance.

What changed

Removes the unnecessary String.raw tag from the template literal | on line 35. Since the pipe character does not involve any backslash escaping, String.raw is unnecessary here. Using a plain string resolves the warning.

--- a/packages/analysis/tests/jsts/tools/testers/comment-based/helpers/locations.ts
+++ b/packages/analysis/tests/jsts/tools/testers/comment-based/helpers/locations.ts
@@ -35,1 +35,1 @@ const LOCATION_PATTERN = new RegExp(
-    String.raw`|` +
+    `|` +
typescript:S7780 - Using `String.raw` is unnecessary as the string does not contain any `\`. • MINORView issue

Location: packages/analysis/tests/jsts/tools/testers/comment-based/helpers/locations.ts:35

Why is this an issue?

String literals with escaped backslashes can be difficult to read and maintain. Each backslash character must be escaped with another backslash, creating sequences like \\ that are hard to interpret at a glance.

What changed

Removes the unnecessary String.raw tag from the template literal )? on line 37. This string has no backslash characters, making String.raw redundant. Switching to a regular string eliminates the code smell.

--- a/packages/analysis/tests/jsts/tools/testers/comment-based/helpers/locations.ts
+++ b/packages/analysis/tests/jsts/tools/testers/comment-based/helpers/locations.ts
@@ -37,1 +37,1 @@ const LOCATION_PATTERN = new RegExp(
-    String.raw`)?` +
+    `)?` +
typescript:S7780 - Using `String.raw` is unnecessary as the string does not contain any `\`. • MINORView issue 1
typescript:S7780 - Using `String.raw` is unnecessary as the string does not contain any `\`. • MINORView issue 2

Location: packages/analysis/tests/jsts/tools/testers/comment-based/helpers/locations.ts:37

Why is this an issue?

String literals with escaped backslashes can be difficult to read and maintain. Each backslash character must be escaped with another backslash, creating sequences like \\ that are hard to interpret at a glance.

What changed

Removes the unnecessary String.raw tag from the template literal (?<message>${MESSAGE_CONTENT}) on line 40. This string contains no literal backslash characters — the ${MESSAGE_CONTENT} is a template interpolation, not an escape sequence. Using String.raw here is unnecessary and flagged as a code smell. Additionally, this fixes the related warning about the unnecessary String.raw usage with (?< on the same line, since the named capture group syntax (?<message>...) does not contain backslashes either. Switching to a plain template literal resolves both warnings.

--- a/packages/analysis/tests/jsts/tools/testers/comment-based/helpers/locations.ts
+++ b/packages/analysis/tests/jsts/tools/testers/comment-based/helpers/locations.ts
@@ -40,1 +40,1 @@ const LOCATION_PATTERN = new RegExp(
-    String.raw`(?<message>${MESSAGE_CONTENT})` +
+    `(?<message>${MESSAGE_CONTENT})` +

Have a suggestion or found an issue? Share your feedback here.


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZ7yEvPohshm9reY56At for typescript:S7780 rule
- AZ7yEvPohshm9reY56Au for typescript:S7780 rule
- AZ7yEvPohshm9reY56Av for typescript:S7780 rule
- AZ7yEvPohshm9reY56Aw for typescript:S7780 rule
- AZ7yEvPohshm9reY56Ax for typescript:S7780 rule

Generated by SonarQube Agent (task: e426fe3a-df44-48de-aa61-bf796dee5842)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant