[prefer-template] Add "allow-single-concat" option
See original GitHub issueWhat 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:
- Created 4 years ago
- Reactions:1
- Comments:17 (10 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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!
What do you think about a
"allowStringConversions"
option (which suppresses errors in the form ofx + ""
and"" + x
, see https://github.com/eslint/eslint/issues/12042#issuecomment-517039518)?If you like it I could try to prepare a PR.