CLI-216 fix: use String.raw to avoid escaping backslashes in unix-agent-hook-templates from #136#137
Conversation
Commit 1 of SonarQube suggestions Fully fixed issues: - [typescript:S7780] AZ02uYv8wdmNkoppS__H: `String.raw` should be used to avoid escaping `\`. Generated by SonarQube Agent
SummarySingle-file refactor using What reviewers should knowWhere to focus: Only the
|
|
| @@ -53,11 +53,7 @@ function sqaaHookOutputJsonEscapeAwk(): string { | |||
| const tab = '\t'; | |||
| const cr = '\r'; | |||
| // Split gsub(/"/, ...) so we avoid unnecessary `\"` escapes (typescript:S6535); keep same awk source as legacy template literals. | |||
There was a problem hiding this comment.
The comment says "Split gsub(/"/,...) so we avoid unnecessary \" escapes" and describes the string-concatenation trick, but that trick no longer exists — String.raw handles it directly. The comment now describes removed code and will mislead future readers.
| // Split gsub(/"/, ...) so we avoid unnecessary `\"` escapes (typescript:S6535); keep same awk source as legacy template literals. | |
| // String.raw avoids double-escaping backslashes and the `\"` issue (typescript:S6535, S7780); ${tab}/${cr} interpolation still works normally. |
- Mark as noise
|
is broken at the first gsub — it would produce an invalid awk script. |



Addresses quality gate issues from #136.
Replaced concatenated template literal with String.raw to eliminate unnecessary backslash escaping in the unix-agent-hook-templates.ts file. This improves code readability and reduces error-prone double-escaping while resolving the SonarQube code smell.
View Project in SonarCloud
Fixed Issues
typescript:S7780 - `String.raw` should be used to avoid escaping `\`. • MINOR • View issue
Location:
src/cli/commands/integrate/_common/unix-agent-hook-templates.ts:59What changed
This hunk replaces a concatenated template literal containing multiple escaped backslashes (e.g.,
\\,\",\t,\r,\n) with a singleString.rawtemplate literal. By usingString.raw, backslashes are treated literally and no longer need to be double-escaped, which directly resolves the code smell about usingString.rawto avoid escaping\in the fileunix-agent-hook-templates.ts. The resulting code is more readable and less error-prone, as the awk script content is now expressed with single backslashes matching the intended output, and the awkward string concatenation trick (splitting the string to include a literal double-quote) is also eliminated.SonarQube Remediation Agent uses AI. Check for mistakes.
DISCLAIMER: Remediation Agent will not be triggered again on this (self authored) PR