Skip to content

fix: S7780 — use String.raw for escaped strings (13 occurrences)#446

Merged
RobertLD merged 10 commits intomainfrom
fix/s7780-string-raw-439
Mar 19, 2026
Merged

fix: S7780 — use String.raw for escaped strings (13 occurrences)#446
RobertLD merged 10 commits intomainfrom
fix/s7780-string-raw-439

Conversation

@RobertLD
Copy link
Copy Markdown
Owner

Replace manually escaped strings with String.raw tagged templates where backslashes are literal characters.

SonarCloud Rule S7780: Use String.raw to avoid manual backslash escaping in strings

Changes:

  • src/core/parsers/csv.ts: CSV cell escaping (pipe and backslash)
  • src/core/search.ts: LIKE pattern escaping (%, _, [)
  • src/core/packs.ts: Glob pattern regex escaping
  • src/web/dashboard.ts: HTML onclick attribute string construction
  • tests/unit/search.test.ts: Test assertions for escape patterns
  • tests/unit/parsers.test.ts: Pipe escape test data
  • tests/unit/registry/publish.test.ts: Pack name test data with backslash

Implementation Note: Used // prettier-ignore comments to preserve String.raw where Prettier would otherwise revert template literals back to regular strings.

Testing: All affected tests pass (search, parsers, registry/publish).

Closes #439

🤖 Generated with Claude Code

RobertLD and others added 2 commits March 19, 2026 00:25
S7755: prefer .at() over bracket index (9 fixes)
S4325: remove unnecessary type assertions (7 fixes)
S3863: merge duplicate imports (6 fixes)
S7748: remove zero fractions (6 fixes)
S7778: combine consecutive push calls (5 fixes)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Replace manually escaped strings with String.raw tagged templates where
backslashes are literal characters, per SonarCloud S7780 rule.

Fixed in:
- src/core/parsers/csv.ts: replaceAll replacement strings
- src/core/search.ts: escapeLikePattern replace calls
- src/core/packs.ts: glob pattern regex replacement
- src/web/dashboard.ts: HTML onclick attribute construction
- tests/unit/search.test.ts: assertion strings (with prettier-ignore)
- tests/unit/parsers.test.ts: pipe escape test
- tests/unit/registry/publish.test.ts: pack name test data

Use prettier-ignore comments to preserve String.raw where Prettier
would otherwise convert template literals back to regular strings.

Closes #439

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
libscope Ignored Ignored Preview Mar 19, 2026 1:21am

RobertLD and others added 8 commits March 19, 2026 00:45
The dashboard.ts file is one large template literal exporting HTML+JS.
The \' escapes produce literal quotes in onclick handlers and cannot
be converted to String.raw or template literals without breaking the
nested quoting.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The `as ReadableStreamDefaultReader<Uint8Array>` cast is needed because
Node.js type definitions return `any` from getReader(). Removing it
introduces no-unsafe-assignment lint errors in CI.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The `as Stats` and `as ReturnType<typeof vi.fn>` casts are needed for
TypeScript type resolution under Node 22's stricter type definitions
in CI. Removing them causes cascading no-unsafe-call errors.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…earch

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…n density

The String.raw conversions in test assertions added prettier-ignore
comments that inflated SonarCloud's duplication density metric (18%
vs 3% threshold). The original escaped strings were already correct.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
# Conflicts:
#	src/core/packs.ts
#	src/core/parsers/csv.ts
@sonarqubecloud
Copy link
Copy Markdown

@RobertLD RobertLD merged commit 63975db into main Mar 19, 2026
10 checks passed
@RobertLD RobertLD deleted the fix/s7780-string-raw-439 branch March 19, 2026 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: S7780 — use String.raw for escaped strings (16 occurrences)

1 participant