Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

restrict-plus-operands should apply to template strings #3670

Closed
buu700 opened this issue Jan 23, 2018 · 2 comments
Closed

restrict-plus-operands should apply to template strings #3670

buu700 opened this issue Jan 23, 2018 · 2 comments

Comments

@buu700
Copy link
Contributor

buu700 commented Jan 23, 2018

Bug Report

  • TSLint version: 5.9.1
  • TypeScript version: 2.6.2
  • Running TSLint via: CLI

TypeScript code being linted

const foo = {balls: 'balls'};

// Accidentally referenced foo instead of foo.balls
const bar = `bar-${foo}`;

with tslint.json configuration:

{
	"rules": {
		"restrict-plus-operands": true
	}
}

Actual behavior

No error is detected, so bar gets set to "bar-[object Object]" instead of the intended "bar-balls".

Expected behavior

Given that the equivalent const bar = 'bar-' + foo; would have been flagged by this rule, it seems logical that the example should be too.

If not by default, it would be nice to have this use case covered either by an optional parameter or by a separate rule.

@OliverJAsh
Copy link
Contributor

I also just ran into this. Would love to see this rule extended to template strings!

@buu700
Copy link
Contributor Author

buu700 commented Sep 7, 2019

Thanks @ColCh (#4807)! This problem was pretty painful.

@buu700 buu700 closed this as completed Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants