question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule proposal: No useless template string, or prefer String()

See original GitHub issue

Please describe what the rule should do: Disallow useless template strings, such as ${x}. The thing is this can be used as a way to cast a variable to string, which means the rule could instead be “prefer String()” or “prefer .toString()”.

What category of rule is this? (place an “X” next to just one item)

[ ] Warns about a potential error (problem) [X] Suggests an alternate way of doing something (suggestion) [ ] Enforces code style (layout) [ ] Other (please specify:)

Provide 2-3 code examples that this rule will warn about:

const x = "soomething";
callAFunction(123, "mamamia", `${x}`);
const x = 19
callAFunction(123, "mamamia", `${x}`);

Why should this rule be included in ESLint (instead of a plugin)?

Because eslint already had tons of no-useless-something rules, so this one would fit very well with the rest.

Are you willing to submit a pull request to implement this rule? No unless you point me to the right resources and ask nicely and I have enough free time this week

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
ljharbcommented, Oct 30, 2020

This should be reopened since there’s an active PR for it.

3reactions
mdjermanoviccommented, Feb 2, 2020

Hi @marcospgp , thanks for the rule proposal!

This might as well be a new option in no-implicit-coercion?

Read more comments on GitHub >

github_iconTop Results From Across the Web

prefer-template - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
eslint-plugin-unicorn
Name Description 💼 🚫 🔧 💡 consistent‑destructuring Use destructured variables over properties. ✓ 🔧 💡 custom‑error‑definition Enforce correct Error subclassing. ✓ 🔧 empty‑brace‑spaces Enforce no spaces...
Read more >
eslint-plugin-unicorn - npm Package Health Analysis
More than 100 powerful ESLint rules For more information about how to use this ... prefer-string-replace-all, Prefer String#replaceAll() over regex searches ...
Read more >
Changelog
We're finally able to offer a pre-release of ESLint 8 based standard 17! ... Relax rule: Allow tagged template string expressions (no-unused-expressions) # ......
Read more >
javascript - Unexpected string concatenation
... an error because your linter rules have been configured to prefer template strings over string concatenation. The no-useless-concat rule ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found