Skip to content
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

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

Open
4 tasks done
kirkwaiblinger opened this issue Mar 14, 2024 · 0 comments · May be fixed by #8688
Open
4 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working 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 maintainers 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 maintainers 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
2 participants