Skip to content

fix(lint/noUselessEscapeInString): avoid false positive for $\{ escape in template literals#7624

Merged
ematipico merged 2 commits intobiomejs:mainfrom
lucasweng:fix/noUselessEscapeInString
Oct 2, 2025
Merged

fix(lint/noUselessEscapeInString): avoid false positive for $\{ escape in template literals#7624
ematipico merged 2 commits intobiomejs:mainfrom
lucasweng:fix/noUselessEscapeInString

Conversation

@lucasweng
Copy link
Copy Markdown
Contributor

Summary

Fixes #7595, which incorrectly flagged $\{ escapes in template literals.

Test Plan

  • Added valid test cases for $\{ escapes and additional invalid cases.
  • All existing tests pass.

Docs

  • Added a description for valid template literal escapes in the doc string.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Oct 1, 2025

🦋 Changeset detected

Latest commit: 1d52943

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Oct 1, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 1, 2025

Walkthrough

The noUselessEscapeInString rule was changed to correctly recognise escapes inside template literals: it treats \${ and $\\{ as valid escapes only when inside a backtick string (template literal) and when the $ precedes the {. Tests were added and adjusted to cover these template-literal cases. A changeset entry adds a patch release note for @biomejs/biome. No exported or public API changes.

Suggested labels

A-Diagnostic

Suggested reviewers

  • siketyan
  • ematipico
  • arendjr

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly identifies that the pull request fixes the noUselessEscapeInString lint rule to avoid false positives for the $\{ escape in template literals, directly reflecting the main change without extraneous detail.
Linked Issues Check ✅ Passed The changes implement the required behavior from issue #7595 by preserving valid escapes for both \${ and $\{ sequences inside template literals, updating the rule logic, adding corresponding tests, and enhancing documentation, thereby satisfying the linked issue’s objectives.
Out of Scope Changes Check ✅ Passed All modifications are focused on adjusting the noUselessEscapeInString rule, its tests, and documentation as specified by the linked issue, and there are no unrelated or extraneous changes in the pull request.
Description Check ✅ Passed The pull request description clearly states it fixes the specific issue with $\{ escapes, outlines the added tests and documentation updates, and corresponds directly to the changes made, making it a relevant description.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bf4c814 and 1d52943.

📒 Files selected for processing (1)
  • crates/biome_js_analyze/src/lint/suspicious/no_useless_escape_in_string.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/biome_js_analyze/src/lint/suspicious/no_useless_escape_in_string.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (24)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Documentation
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Check Dependencies
  • GitHub Check: Test Node.js API
  • GitHub Check: Bench (biome_package)
  • GitHub Check: Bench (biome_graphql_formatter)
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: Bench (biome_css_formatter)
  • GitHub Check: Bench (biome_graphql_parser)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_json_formatter)
  • GitHub Check: Bench (biome_html_formatter)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_html_parser)
  • GitHub Check: Bench (biome_module_graph)
  • GitHub Check: Bench (biome_css_analyze)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_css_parser)
  • GitHub Check: Bench (biome_json_parser)
  • GitHub Check: Bench (biome_json_analyze)
  • GitHub Check: autofix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
.changeset/real-comics-build.md (1)

1-5: Changeset follows guidelines well.

The entry correctly uses past tense, links to the issue, includes the rule documentation link, and ends with a full stop.

Consider adding a minimal code block to demonstrate the fix, as per the coding guidelines for changesets. For example:

+Fixed [#7595](https://github.com/biomejs/biome/issues/7595): [`noUselessEscapeInString`](https://biomejs.dev/linter/rules/no-useless-escape-in-string/) no longer reports `$\{` escape in template literals.
+
+```js
+// Now correctly recognised as valid:
+const s = `$\{var}`;
+```

As per coding guidelines.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fa4fcd3 and bf4c814.

⛔ Files ignored due to path filters (2)
  • crates/biome_js_analyze/tests/specs/suspicious/noUselessEscapeInString/invalid.js.snap is excluded by !**/*.snap and included by **
  • crates/biome_js_analyze/tests/specs/suspicious/noUselessEscapeInString/valid.js.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (4)
  • .changeset/real-comics-build.md (1 hunks)
  • crates/biome_js_analyze/src/lint/suspicious/no_useless_escape_in_string.rs (2 hunks)
  • crates/biome_js_analyze/tests/specs/suspicious/noUselessEscapeInString/invalid.js (1 hunks)
  • crates/biome_js_analyze/tests/specs/suspicious/noUselessEscapeInString/valid.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
crates/biome_*_{syntax,parser,formatter,analyze,factory,semantic}/**

📄 CodeRabbit inference engine (CLAUDE.md)

Maintain the per-language crate structure: biome_{lang}_{syntax,parser,formatter,analyze,factory,semantic}

Files:

  • crates/biome_js_analyze/tests/specs/suspicious/noUselessEscapeInString/invalid.js
  • crates/biome_js_analyze/src/lint/suspicious/no_useless_escape_in_string.rs
  • crates/biome_js_analyze/tests/specs/suspicious/noUselessEscapeInString/valid.js
crates/biome_*/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place core crates under /crates/biome_*/

Files:

  • crates/biome_js_analyze/tests/specs/suspicious/noUselessEscapeInString/invalid.js
  • crates/biome_js_analyze/src/lint/suspicious/no_useless_escape_in_string.rs
  • crates/biome_js_analyze/tests/specs/suspicious/noUselessEscapeInString/valid.js
**/tests/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place test files under a tests/ directory in each crate

Files:

  • crates/biome_js_analyze/tests/specs/suspicious/noUselessEscapeInString/invalid.js
  • crates/biome_js_analyze/tests/specs/suspicious/noUselessEscapeInString/valid.js
.changeset/*.md

📄 CodeRabbit inference engine (CONTRIBUTING.md)

.changeset/*.md: In changeset files, only use #### or ##### headers; avoid other header levels
Changeset descriptions should use past tense for what you did (e.g., "Added...")
Describe current Biome behavior in present tense within changesets (e.g., "Biome now supports...")
For bug fixes in changesets, start with a link to the issue (e.g., "Fixed #1234: ...")
When referencing rules or assists in changesets, include links to their documentation pages
Include a minimal code block in the changeset when applicable to demonstrate the change
End every sentence in the changeset description with a period

Files:

  • .changeset/real-comics-build.md
**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Format all Rust source files before committing (just f)

Files:

  • crates/biome_js_analyze/src/lint/suspicious/no_useless_escape_in_string.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (24)
  • GitHub Check: Bench (biome_html_formatter)
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: Bench (biome_package)
  • GitHub Check: Bench (biome_json_formatter)
  • GitHub Check: Bench (biome_json_analyze)
  • GitHub Check: Bench (biome_graphql_parser)
  • GitHub Check: Bench (biome_css_analyze)
  • GitHub Check: Bench (biome_graphql_formatter)
  • GitHub Check: Bench (biome_module_graph)
  • GitHub Check: Bench (biome_html_parser)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_json_parser)
  • GitHub Check: Bench (biome_css_formatter)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_css_parser)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Test Node.js API
  • GitHub Check: autofix
  • GitHub Check: Documentation
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Check Dependencies
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
🔇 Additional comments (3)
crates/biome_js_analyze/tests/specs/suspicious/noUselessEscapeInString/valid.js (1)

7-9: LGTM! Comprehensive test coverage for the fix.

The new test cases properly cover both $\{ (the primary issue from #7595) and $\{} (with content after the brace). The trailing comma addition maintains consistency.

crates/biome_js_analyze/src/lint/suspicious/no_useless_escape_in_string.rs (2)

43-47: Documentation updated appropriately.

The doc comment now correctly describes both \${ and $\{ as valid escapes in template literals.


182-187: Correct implementation for $\{ escape handling.

The logic properly checks that the backslash precedes { and that $ precedes the backslash. The index arithmetic is sound: i points to the backslash, so i-1 correctly identifies the preceding character.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Oct 1, 2025

CodSpeed Performance Report

Merging #7624 will not alter performance

Comparing lucasweng:fix/noUselessEscapeInString (1d52943) with main (fa4fcd3)

Summary

✅ 133 untouched

Comment thread crates/biome_js_analyze/src/lint/suspicious/no_useless_escape_in_string.rs Outdated
Copy link
Copy Markdown
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great fix!

@ematipico ematipico merged commit 309ae41 into biomejs:main Oct 2, 2025
30 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 2, 2025
ematipico pushed a commit that referenced this pull request Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💅 noUselessEscapeInString removes needed escape in template literal

3 participants