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.

[prefer-template] Add "allow-single-concat" option

See original GitHub issue

What rule do you want to change? prefer-template

Does this change cause the rule to produce more or fewer warnings? fewer

How will the change be implemented? (New option, new default behavior, etc.)? New option “allow-single-concat”

Please provide some example code that this change will affect:

const str = someVal + "";            // valid (with enabled option)
const str = "Val: " + someVal + "";  // invalid

What does the rule currently do for this code? Error

What will the rule do after it’s changed? No error for “single” concat

Background info I’m coming from TSLint, which offers this option. See https://palantir.github.io/tslint/rules/prefer-template/.

Are you willing to submit a pull request to implement this change? Yes

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
kaicataldocommented, Dec 14, 2019

In this case, it doesn’t look like there was enough interest from the team. If someone would like to advocate for a change related to this, please feel free to create a new proposal!

3reactions
ulrichbcommented, Nov 7, 2019

What do you think about a "allowStringConversions" option (which suppresses errors in the form of x + "" and "" + x, see https://github.com/eslint/eslint/issues/12042#issuecomment-517039518)?

If you like it I could try to prepare a PR.

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 >
prefer-template - Rule
Prefer a template expression over string literal concatenation. Config. If allow-single-concat is specified, then a single concatenation ( x + y ) is...
Read more >
Unexpected string concatenation - Stack Overflow
Try using a template literal. ie. const ANR = 'Animal Friend,ANR,ANP,$30' const specialityPlates = [ { cName: 'Environmental / Wildlife', ...
Read more >
4 Ways to Combine Strings in JavaScript | SamanthaMing.com
1. Template Strings. Problem of Missing space in String concatenation; Resolved with Template Strings ; 2. join(). Customize Separator ; 3. concat(). Combining ......
Read more >
Template literals (Template strings) - JavaScript | MDN
Tags allow you to parse template literals with a function. ... raw strings just like the default template function and string concatenation ......
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