From 4350ec13faabb4945a481dfd2c49c28d5de97778 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Mon, 17 Aug 2020 21:46:33 +0200 Subject: [PATCH 01/11] Update: Add templateString option in no-implicit-coercion (fixes #12866) This adds the `templateString` option to `no-implicit-coercion`. This makes the rule report the following code: ```js `${foo}` ``` For backwards compatibility, this was added as a separate option instead of as default behaviour. --- docs/rules/no-implicit-coercion.md | 27 +++++++++++++++++---- lib/rules/no-implicit-coercion.js | 32 +++++++++++++++++++++++++ tests/lib/rules/no-implicit-coercion.js | 11 +++++++++ 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/docs/rules/no-implicit-coercion.md b/docs/rules/no-implicit-coercion.md index f78e40c66c2..6d33aa93923 100644 --- a/docs/rules/no-implicit-coercion.md +++ b/docs/rules/no-implicit-coercion.md @@ -33,10 +33,11 @@ This rule is aimed to flag shorter notations for the type conversion, then sugge This rule has three main options and one override option to allow some coercions as required. -* `"boolean"` (`true` by default) - When this is `true`, this rule warns shorter type conversions for `boolean` type. -* `"number"` (`true` by default) - When this is `true`, this rule warns shorter type conversions for `number` type. -* `"string"` (`true` by default) - When this is `true`, this rule warns shorter type conversions for `string` type. -* `"allow"` (`empty` by default) - Each entry in this array can be one of `~`, `!!`, `+` or `*` that are to be allowed. +- `"boolean"` (`true` by default) - When this is `true`, this rule warns shorter type conversions for `boolean` type. +- `"number"` (`true` by default) - When this is `true`, this rule warns shorter type conversions for `number` type. +- `"string"` (`true` by default) - When this is `true`, this rule warns shorter type conversions for `string` type. +- `"templateString"` (`false` by default) - When this is `true`, this rule warns shorter type conversions using template strings. +- `"allow"` (`empty` by default) - Each entry in this array can be one of `~`, `!!`, `+` or `*` that are to be allowed. Note that operator `+` in `allow` list would allow `+foo` (number coercion) as well as `"" + foo` (string coercion). @@ -106,6 +107,24 @@ var s = String(foo); foo = String(foo); ``` +### templateString + +Examples of **incorrect** code for the default `{ "templateString": true }` option: + +```js +/*eslint no-implicit-coercion: "error"*/ + +`${foo}`; +``` + +Examples of **correct** code for the default `{ "templateString": false }` option: + +```js +/*eslint no-implicit-coercion: "error"*/ + +`${foo}`; +``` + ### allow Using `allow` list, we can override and allow specific operators. diff --git a/lib/rules/no-implicit-coercion.js b/lib/rules/no-implicit-coercion.js index a639711ecea..058f3cc8c03 100644 --- a/lib/rules/no-implicit-coercion.js +++ b/lib/rules/no-implicit-coercion.js @@ -24,6 +24,7 @@ function parseOptions(options) { boolean: "boolean" in options ? options.boolean : true, number: "number" in options ? options.number : true, string: "string" in options ? options.string : true, + templateString: "templateString" in options ? options.templateString : false, allow: options.allow || [] }; } @@ -180,6 +181,10 @@ module.exports = { type: "boolean", default: true }, + templateString: { + type: "boolean", + default: false + }, allow: { type: "array", items: { @@ -299,6 +304,33 @@ module.exports = { report(node, recommendation, true); } + }, + + TemplateLiteral(node) { + if (!options.templateString) { + return; + } + + // `` or `${foo}${bar}` + if (node.expressions.length !== 1) { + return; + } + + + // `prefix${foo}` + if (node.quasis[0].value.raw !== "") { + return; + } + + // `${foo}postfix` + if (node.quasis[1].value.raw !== "") { + return; + } + + const code = sourceCode.getText(node.expressions[0]); + const recommendation = `String(${code})`; + + report(node, recommendation, true); } }; } diff --git a/tests/lib/rules/no-implicit-coercion.js b/tests/lib/rules/no-implicit-coercion.js index fa2b68b4975..f0048707d55 100644 --- a/tests/lib/rules/no-implicit-coercion.js +++ b/tests/lib/rules/no-implicit-coercion.js @@ -248,6 +248,17 @@ ruleTester.run("no-implicit-coercion", rule, { type: "BinaryExpression" }] }, + { + code: "`${foo}`", + output: "String(foo)", + options: [{ templateString: true }], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + messageId: "useRecommendation", + data: { recommendation: "String(foo)" }, + type: "TemplateLiteral" + }] + }, { code: "foo += \"\"", output: "foo = String(foo)", From bdfe13e7780ce14b4e6bbe55fc555e2027b70227 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Mon, 5 Apr 2021 10:42:00 +0200 Subject: [PATCH 02/11] Fix no-implicit-coercion templateString examples --- docs/rules/no-implicit-coercion.md | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/docs/rules/no-implicit-coercion.md b/docs/rules/no-implicit-coercion.md index 6d33aa93923..e00d46731af 100644 --- a/docs/rules/no-implicit-coercion.md +++ b/docs/rules/no-implicit-coercion.md @@ -109,20 +109,34 @@ foo = String(foo); ### templateString -Examples of **incorrect** code for the default `{ "templateString": true }` option: +Examples of **incorrect** code for the `{ "templateString": true }` option: ```js -/*eslint no-implicit-coercion: "error"*/ +/*eslint no-implicit-coercion: ["error", { "templateString": true }]*/ -`${foo}`; +var s = `${foo}`; +``` + +Examples of **correct** code for the `{ "templateString": true }` option: + +```js +/*eslint no-implicit-coercion: ["error", { "templateString": true }]*/ + +var s = String(foo); + +var s = `a${foo}`; + +var s = `${foo}b`; + +var s = `${foo}${bar}`; ``` Examples of **correct** code for the default `{ "templateString": false }` option: ```js -/*eslint no-implicit-coercion: "error"*/ +/*eslint no-implicit-coercion: ["error", { "templateString": false }]*/ -`${foo}`; +var s = `${foo}`; ``` ### allow From bd6f9b4ba1339bd84f9892eeb8d76edd6b39b9a1 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Mon, 5 Apr 2021 11:00:31 +0200 Subject: [PATCH 03/11] Skip tagged template strings in no-implicit-coercion --- lib/rules/no-implicit-coercion.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/rules/no-implicit-coercion.js b/lib/rules/no-implicit-coercion.js index 058f3cc8c03..2a38a919a4e 100644 --- a/lib/rules/no-implicit-coercion.js +++ b/lib/rules/no-implicit-coercion.js @@ -311,6 +311,11 @@ module.exports = { return; } + // tag`${foo}` + if (node.parent.type === "TaggedTemplateExpression") { + return; + } + // `` or `${foo}${bar}` if (node.expressions.length !== 1) { return; From afe180574daf443e798b20ed576a0637fa989d1d Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Mon, 5 Apr 2021 11:01:08 +0200 Subject: [PATCH 04/11] Add missing tests for no-implicit-coercion --- tests/lib/rules/no-implicit-coercion.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/lib/rules/no-implicit-coercion.js b/tests/lib/rules/no-implicit-coercion.js index f0048707d55..e88480a0769 100644 --- a/tests/lib/rules/no-implicit-coercion.js +++ b/tests/lib/rules/no-implicit-coercion.js @@ -88,6 +88,10 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "`${foo}` + ''", parserOptions: { ecmaVersion: 6 } }, "foo += 'bar'", { code: "foo += `${bar}`", parserOptions: { ecmaVersion: 6 } }, + { code: "`a${foo}`", options: [{ templateString: true }], parserOptions: { ecmaVersion: 6 } }, + { code: "`${foo}b`", options: [{ templateString: true }], parserOptions: { ecmaVersion: 6 } }, + { code: "`${foo}${bar}`", options: [{ templateString: true }], parserOptions: { ecmaVersion: 6 } }, + { code: "tag`${foo}`", options: [{ templateString: true }], parserOptions: { ecmaVersion: 6 } }, "+42" ], invalid: [ From 07d1b9f4af1a9daf8593c186c2c94633a984ad7d Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Mon, 5 Apr 2021 11:14:49 +0200 Subject: [PATCH 05/11] Used cooked template string values --- lib/rules/no-implicit-coercion.js | 4 ++-- tests/lib/rules/no-implicit-coercion.js | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/rules/no-implicit-coercion.js b/lib/rules/no-implicit-coercion.js index 2a38a919a4e..0e41ce34292 100644 --- a/lib/rules/no-implicit-coercion.js +++ b/lib/rules/no-implicit-coercion.js @@ -323,12 +323,12 @@ module.exports = { // `prefix${foo}` - if (node.quasis[0].value.raw !== "") { + if (node.quasis[0].value.cooked !== "") { return; } // `${foo}postfix` - if (node.quasis[1].value.raw !== "") { + if (node.quasis[1].value.cooked !== "") { return; } diff --git a/tests/lib/rules/no-implicit-coercion.js b/tests/lib/rules/no-implicit-coercion.js index e88480a0769..6beab28eb32 100644 --- a/tests/lib/rules/no-implicit-coercion.js +++ b/tests/lib/rules/no-implicit-coercion.js @@ -263,6 +263,28 @@ ruleTester.run("no-implicit-coercion", rule, { type: "TemplateLiteral" }] }, + { + code: "`\\\n${foo}`", + output: "String(foo)", + options: [{ templateString: true }], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + messageId: "useRecommendation", + data: { recommendation: "String(foo)" }, + type: "TemplateLiteral" + }] + }, + { + code: "`${foo}\\\n`", + output: "String(foo)", + options: [{ templateString: true }], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + messageId: "useRecommendation", + data: { recommendation: "String(foo)" }, + type: "TemplateLiteral" + }] + }, { code: "foo += \"\"", output: "foo = String(foo)", From ce1d62b15c753b981cdb9bcfdb8165717af056b0 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Mon, 5 Apr 2021 11:16:26 +0200 Subject: [PATCH 06/11] Add missing documentation for no-implicit-coercion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note that the `templateString` option isn’t affected by the `string` option. --- docs/rules/no-implicit-coercion.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/rules/no-implicit-coercion.md b/docs/rules/no-implicit-coercion.md index e00d46731af..ce315303c0d 100644 --- a/docs/rules/no-implicit-coercion.md +++ b/docs/rules/no-implicit-coercion.md @@ -109,6 +109,8 @@ foo = String(foo); ### templateString +This option is **not** affected by the `string` option. + Examples of **incorrect** code for the `{ "templateString": true }` option: ```js From 05f3ceaca78861a45dc93348c91cbda42283f552 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Mon, 5 Apr 2021 16:24:46 +0200 Subject: [PATCH 07/11] Add missing tests for no-implicit-coercion templateString --- tests/lib/rules/no-implicit-coercion.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/lib/rules/no-implicit-coercion.js b/tests/lib/rules/no-implicit-coercion.js index 6beab28eb32..9a15615b3e9 100644 --- a/tests/lib/rules/no-implicit-coercion.js +++ b/tests/lib/rules/no-implicit-coercion.js @@ -92,6 +92,9 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "`${foo}b`", options: [{ templateString: true }], parserOptions: { ecmaVersion: 6 } }, { code: "`${foo}${bar}`", options: [{ templateString: true }], parserOptions: { ecmaVersion: 6 } }, { code: "tag`${foo}`", options: [{ templateString: true }], parserOptions: { ecmaVersion: 6 } }, + { code: "`${foo}`", parserOptions: { ecmaVersion: 6 } }, + { code: "`${foo}`", options: [{ }], parserOptions: { ecmaVersion: 6 } }, + { code: "`${foo}`", options: [{ templateString: false }], parserOptions: { ecmaVersion: 6 } }, "+42" ], invalid: [ From e52cab61ac16f79a1715b83b9c022b8dd4f8793e Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Mon, 5 Apr 2021 16:28:15 +0200 Subject: [PATCH 08/11] Rename templateString to disallowTemplateString --- docs/rules/no-implicit-coercion.md | 16 ++++++++-------- lib/rules/no-implicit-coercion.js | 6 +++--- tests/lib/rules/no-implicit-coercion.js | 16 ++++++++-------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/rules/no-implicit-coercion.md b/docs/rules/no-implicit-coercion.md index ce315303c0d..a18984c507c 100644 --- a/docs/rules/no-implicit-coercion.md +++ b/docs/rules/no-implicit-coercion.md @@ -36,7 +36,7 @@ This rule has three main options and one override option to allow some coercions - `"boolean"` (`true` by default) - When this is `true`, this rule warns shorter type conversions for `boolean` type. - `"number"` (`true` by default) - When this is `true`, this rule warns shorter type conversions for `number` type. - `"string"` (`true` by default) - When this is `true`, this rule warns shorter type conversions for `string` type. -- `"templateString"` (`false` by default) - When this is `true`, this rule warns shorter type conversions using template strings. +- `"disallowTemplateString"` (`false` by default) - When this is `true`, this rule warns shorter type conversions using template strings. - `"allow"` (`empty` by default) - Each entry in this array can be one of `~`, `!!`, `+` or `*` that are to be allowed. Note that operator `+` in `allow` list would allow `+foo` (number coercion) as well as `"" + foo` (string coercion). @@ -107,22 +107,22 @@ var s = String(foo); foo = String(foo); ``` -### templateString +### disallowTemplateString This option is **not** affected by the `string` option. -Examples of **incorrect** code for the `{ "templateString": true }` option: +Examples of **incorrect** code for the `{ "disallowTemplateString": true }` option: ```js -/*eslint no-implicit-coercion: ["error", { "templateString": true }]*/ +/*eslint no-implicit-coercion: ["error", { "disallowTemplateString": true }]*/ var s = `${foo}`; ``` -Examples of **correct** code for the `{ "templateString": true }` option: +Examples of **correct** code for the `{ "disallowTemplateString": true }` option: ```js -/*eslint no-implicit-coercion: ["error", { "templateString": true }]*/ +/*eslint no-implicit-coercion: ["error", { "disallowTemplateString": true }]*/ var s = String(foo); @@ -133,10 +133,10 @@ var s = `${foo}b`; var s = `${foo}${bar}`; ``` -Examples of **correct** code for the default `{ "templateString": false }` option: +Examples of **correct** code for the default `{ "disallowTemplateString": false }` option: ```js -/*eslint no-implicit-coercion: ["error", { "templateString": false }]*/ +/*eslint no-implicit-coercion: ["error", { "disallowTemplateString": false }]*/ var s = `${foo}`; ``` diff --git a/lib/rules/no-implicit-coercion.js b/lib/rules/no-implicit-coercion.js index 0e41ce34292..b9bb4548986 100644 --- a/lib/rules/no-implicit-coercion.js +++ b/lib/rules/no-implicit-coercion.js @@ -24,7 +24,7 @@ function parseOptions(options) { boolean: "boolean" in options ? options.boolean : true, number: "number" in options ? options.number : true, string: "string" in options ? options.string : true, - templateString: "templateString" in options ? options.templateString : false, + disallowTemplateShorthand: "disallowTemplateShorthand" in options ? options.disallowTemplateShorthand : false, allow: options.allow || [] }; } @@ -181,7 +181,7 @@ module.exports = { type: "boolean", default: true }, - templateString: { + disallowTemplateShorthand: { type: "boolean", default: false }, @@ -307,7 +307,7 @@ module.exports = { }, TemplateLiteral(node) { - if (!options.templateString) { + if (!options.disallowTemplateShorthand) { return; } diff --git a/tests/lib/rules/no-implicit-coercion.js b/tests/lib/rules/no-implicit-coercion.js index 9a15615b3e9..fa0a63824bb 100644 --- a/tests/lib/rules/no-implicit-coercion.js +++ b/tests/lib/rules/no-implicit-coercion.js @@ -88,13 +88,13 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "`${foo}` + ''", parserOptions: { ecmaVersion: 6 } }, "foo += 'bar'", { code: "foo += `${bar}`", parserOptions: { ecmaVersion: 6 } }, - { code: "`a${foo}`", options: [{ templateString: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`${foo}b`", options: [{ templateString: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "`${foo}${bar}`", options: [{ templateString: true }], parserOptions: { ecmaVersion: 6 } }, - { code: "tag`${foo}`", options: [{ templateString: true }], parserOptions: { ecmaVersion: 6 } }, + { code: "`a${foo}`", options: [{ disallowTemplateShorthand: true }], parserOptions: { ecmaVersion: 6 } }, + { code: "`${foo}b`", options: [{ disallowTemplateShorthand: true }], parserOptions: { ecmaVersion: 6 } }, + { code: "`${foo}${bar}`", options: [{ disallowTemplateShorthand: true }], parserOptions: { ecmaVersion: 6 } }, + { code: "tag`${foo}`", options: [{ disallowTemplateShorthand: true }], parserOptions: { ecmaVersion: 6 } }, { code: "`${foo}`", parserOptions: { ecmaVersion: 6 } }, { code: "`${foo}`", options: [{ }], parserOptions: { ecmaVersion: 6 } }, - { code: "`${foo}`", options: [{ templateString: false }], parserOptions: { ecmaVersion: 6 } }, + { code: "`${foo}`", options: [{ disallowTemplateShorthand: false }], parserOptions: { ecmaVersion: 6 } }, "+42" ], invalid: [ @@ -258,7 +258,7 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "`${foo}`", output: "String(foo)", - options: [{ templateString: true }], + options: [{ disallowTemplateShorthand: true }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", @@ -269,7 +269,7 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "`\\\n${foo}`", output: "String(foo)", - options: [{ templateString: true }], + options: [{ disallowTemplateShorthand: true }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", @@ -280,7 +280,7 @@ ruleTester.run("no-implicit-coercion", rule, { { code: "`${foo}\\\n`", output: "String(foo)", - options: [{ templateString: true }], + options: [{ disallowTemplateShorthand: true }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "useRecommendation", From 3592c58e7a3a50e2991c1accf56a74ff46d2a448 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Mon, 5 Apr 2021 21:04:30 +0200 Subject: [PATCH 09/11] Fix typo in no-implicit-coercion docs --- docs/rules/no-implicit-coercion.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/rules/no-implicit-coercion.md b/docs/rules/no-implicit-coercion.md index a18984c507c..97a6696a67f 100644 --- a/docs/rules/no-implicit-coercion.md +++ b/docs/rules/no-implicit-coercion.md @@ -36,7 +36,7 @@ This rule has three main options and one override option to allow some coercions - `"boolean"` (`true` by default) - When this is `true`, this rule warns shorter type conversions for `boolean` type. - `"number"` (`true` by default) - When this is `true`, this rule warns shorter type conversions for `number` type. - `"string"` (`true` by default) - When this is `true`, this rule warns shorter type conversions for `string` type. -- `"disallowTemplateString"` (`false` by default) - When this is `true`, this rule warns shorter type conversions using template strings. +- `"disallowTemplateShorthand"` (`false` by default) - When this is `true`, this rule warns shorter type conversions using template strings. - `"allow"` (`empty` by default) - Each entry in this array can be one of `~`, `!!`, `+` or `*` that are to be allowed. Note that operator `+` in `allow` list would allow `+foo` (number coercion) as well as `"" + foo` (string coercion). @@ -107,22 +107,22 @@ var s = String(foo); foo = String(foo); ``` -### disallowTemplateString +### disallowTemplateShorthand This option is **not** affected by the `string` option. -Examples of **incorrect** code for the `{ "disallowTemplateString": true }` option: +Examples of **incorrect** code for the `{ "disallowTemplateShorthand": true }` option: ```js -/*eslint no-implicit-coercion: ["error", { "disallowTemplateString": true }]*/ +/*eslint no-implicit-coercion: ["error", { "disallowTemplateShorthand": true }]*/ var s = `${foo}`; ``` -Examples of **correct** code for the `{ "disallowTemplateString": true }` option: +Examples of **correct** code for the `{ "disallowTemplateShorthand": true }` option: ```js -/*eslint no-implicit-coercion: ["error", { "disallowTemplateString": true }]*/ +/*eslint no-implicit-coercion: ["error", { "disallowTemplateShorthand": true }]*/ var s = String(foo); @@ -133,10 +133,10 @@ var s = `${foo}b`; var s = `${foo}${bar}`; ``` -Examples of **correct** code for the default `{ "disallowTemplateString": false }` option: +Examples of **correct** code for the default `{ "disallowTemplateShorthand": false }` option: ```js -/*eslint no-implicit-coercion: ["error", { "disallowTemplateString": false }]*/ +/*eslint no-implicit-coercion: ["error", { "disallowTemplateShorthand": false }]*/ var s = `${foo}`; ``` From 4dcf42d05645eee5448df00205baab3f0e8c4bd1 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Tue, 6 Apr 2021 17:18:50 +0200 Subject: [PATCH 10/11] Add tagged template string example for no-implicit-coercion --- docs/rules/no-implicit-coercion.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/rules/no-implicit-coercion.md b/docs/rules/no-implicit-coercion.md index 97a6696a67f..9cf83414694 100644 --- a/docs/rules/no-implicit-coercion.md +++ b/docs/rules/no-implicit-coercion.md @@ -131,6 +131,8 @@ var s = `a${foo}`; var s = `${foo}b`; var s = `${foo}${bar}`; + +var s = tag`${foo}`; ``` Examples of **correct** code for the default `{ "disallowTemplateShorthand": false }` option: From a23054fd2dbb2d376c5398c33ff1d9dc41f805da Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Tue, 6 Apr 2021 17:20:27 +0200 Subject: [PATCH 11/11] Update docs/rules/no-implicit-coercion.md Co-authored-by: Milos Djermanovic --- docs/rules/no-implicit-coercion.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rules/no-implicit-coercion.md b/docs/rules/no-implicit-coercion.md index 9cf83414694..8ccee339f05 100644 --- a/docs/rules/no-implicit-coercion.md +++ b/docs/rules/no-implicit-coercion.md @@ -36,7 +36,7 @@ This rule has three main options and one override option to allow some coercions - `"boolean"` (`true` by default) - When this is `true`, this rule warns shorter type conversions for `boolean` type. - `"number"` (`true` by default) - When this is `true`, this rule warns shorter type conversions for `number` type. - `"string"` (`true` by default) - When this is `true`, this rule warns shorter type conversions for `string` type. -- `"disallowTemplateShorthand"` (`false` by default) - When this is `true`, this rule warns shorter type conversions using template strings. +- `"disallowTemplateShorthand"` (`false` by default) - When this is `true`, this rule warns `string` type conversions using `${expression}` form. - `"allow"` (`empty` by default) - Each entry in this array can be one of `~`, `!!`, `+` or `*` that are to be allowed. Note that operator `+` in `allow` list would allow `+foo` (number coercion) as well as `"" + foo` (string coercion).