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

Rule proposal: Disallow implicit string conversion in template literals #818

Closed
ark120202 opened this issue Aug 7, 2019 · 2 comments · Fixed by #850
Closed

Rule proposal: Disallow implicit string conversion in template literals #818

ark120202 opened this issue Aug 7, 2019 · 2 comments · Fixed by #850
Labels
enhancement: new plugin rule New rule request for eslint-plugin has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@ark120202
Copy link

TypeScript allows usage of any types in interpolations, which can lead to unexpected results:

const func = () => 'text';
`${func}` // => "() => 'text'"

const object = { foo: 'bar' };
`${object}` // => "[object Object]"

let value: string | undefined;
`${value}` // => "undefined"

This rule should disallow usage of any types, except primitives that are converted to expected values (strings, numbers and booleans).

There is the same proposal to tslint that also includes plus operands, but I'm not sure if there's need to include it in this rule, since it appears to be covered by restrict-plus-operands.

@ark120202 ark120202 added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Aug 7, 2019
@bradzacher bradzacher added enhancement: new plugin rule New rule request for eslint-plugin and removed triage Waiting for maintainers to take a look labels Aug 7, 2019
@ColCh
Copy link

ColCh commented Aug 12, 2019

Do you want me to help here?

@bradzacher
Copy link
Member

You can if you'd like. We love all contributors!

This is a pretty advanced rule to implement as your first.
There'll be a lot of pieces you'll have to figure out all at once (this codebase, eslint, and the typescript compiler API).
Feel free to dive right in to it if you'd like, as we don't have any plans to implement this ourselves in the short term.

@bradzacher bradzacher added the has pr there is a PR raised to close this label Nov 12, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: new plugin rule New rule request for eslint-plugin has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants