Skip to content

💅 noUselessEscapeInString removes needed escape in template literal #7595

@stefanlew-tractive

Description

@stefanlew-tractive

Environment information

❯ biome rage --linter
CLI:
  Version:                      2.2.4
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           linux

Environment:
  BIOME_LOG_PATH:               unset
  BIOME_LOG_PREFIX_NAME:        unset
  BIOME_CONFIG_PATH:            unset
  BIOME_THREADS:                unset
  NO_COLOR:                     unset
  TERM:                         xterm-256color
  JS_RUNTIME_VERSION:           v22.20.0
  JS_RUNTIME_NAME:              node
  NODE_PACKAGE_MANAGER:         unset

Biome Configuration:
  Status:                       Not set
  Path:                         unset

Workspace:
  Open Documents:               0

Rule name

noUselessEscapeInString

Playground link

https://biomejs.dev/playground/?lintRules=noUselessEscapeInString&code=YwBvAG4AcwB0ACAAYgAgAD0AIAAiAGIAIgA7AAoACgBjAG8AbgBzAG8AbABlAC4AbABvAGcAKABgAGEAJAB7AGIAfQBjAGAAKQA7AAoALwAvACAAYQBiAGMACgAKAGMAbwBuAHMAbwBsAGUALgBsAG8AZwAoAGAAYQBcACQAewBiAH0AYwBgACkAOwAKAC8ALwAgAGEAJAB7AGIAfQBjAAoACgBjAG8AbgBzAG8AbABlAC4AbABvAGcAKABgAGEAJABcAHsAYgB9AGMAYAApADsACgAvAC8AIABhACQAewBiAH0AYwAgACAAIQAhAAoA

Expected result

\${var} and $\{var} both disable substitutions but Biome strips the \ for the second one

❯ cat test.ts 
const b = "b";

console.log(`a${b}c`);
console.log(`a\${b}c`);  
console.log(`a$\{b}c`);   

❯ tsx test.ts 
abc
a${b}c
a${b}c

❯ biome lint --write test.ts 
Checked 1 file in 7ms. Fixed 1 file.

❯ cat test.ts 
const b = "b";

console.log(`a${b}c`);
console.log(`a\${b}c`);  
console.log(`a${b}c`);   

❯ tsx test.ts 
abc
a${b}c
abc

Code of Conduct

  • I agree to follow Biome's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LinterArea: linterL-JavaScriptLanguage: JavaScript and super languagesS-Bug-confirmedStatus: report has been confirmed as a valid bug

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions