Skip to content

Bug: [no-unnecessary-template-expression] Inconsistent handling of escapes and quotes in autofixes. #8677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
kirkwaiblinger opened this issue Mar 14, 2024 · 2 comments · Fixed by #8688
Closed
4 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@kirkwaiblinger
Copy link
Member

kirkwaiblinger commented Mar 14, 2024

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

click here

Repro Code

`${"\u00E5"}`;
// autofixes to 
// "\u00E5";

` ${"\u00E5"} `;
// autofixes to 
// ` å `;

ESLint Config

module.exports = {
  "rules": {
    "@typescript-eslint/no-useless-template-literals": "error",
    "no-useless-escape": "error"
  }
}

tsconfig

{
  "compilerOptions": {
    // ...
  }
}

Expected Result

I expect that the autofixed strings should preserve the string type and the escaped characters as the author wrote them.
So, we should have

`${"\u00E5"}`;
// autofixes to 
// `\u00E5`;

` ${"\u00E5"} `;
// autofixes to 
// ` \u00E5 `;

Actual Result

actual autofix results change user's input regarding template and and escaped characters.

Additional Info

This can also result in multiline template literals instead of single line literals that include a \n.

It doesn't impact correctness at runtime, but it isn't the purview of this rule to make these stylistic changes (with the caveat, of course, that obviously $s and backticks still need to be escaped in order to incorporate a string literal into a template string)

@kirkwaiblinger kirkwaiblinger added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Mar 14, 2024
@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Mar 15, 2024
@JoshuaKGoldberg JoshuaKGoldberg changed the title Bug: [no-useless-template-literal] Inconsistent handling of escapes and quotes in autofixes. Bug: [no-useless-template-expression] Inconsistent handling of escapes and quotes in autofixes. Jun 2, 2024
@Josh-Cena Josh-Cena changed the title Bug: [no-useless-template-expression] Inconsistent handling of escapes and quotes in autofixes. Bug: [no-unnecessary-template-expression] Inconsistent handling of escapes and quotes in autofixes. Jun 4, 2024
@JoshuaKGoldberg
Copy link
Member

Fixed by #8688

Copy link

Closed by #8688.

@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Jul 28, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
3 participants