Skip to content

Commit

Permalink
fix(eslint-plugin): [no-base-to-string] soft remove `ignoreTaggedTemp…
Browse files Browse the repository at this point in the history
…lateExpressions` option (#1916)
  • Loading branch information
LinusU committed Apr 20, 2020
1 parent cc70e4f commit 369978e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 45 deletions.
26 changes: 0 additions & 26 deletions packages/eslint-plugin/docs/rules/no-base-to-string.md
Expand Up @@ -52,32 +52,6 @@ const literalWithToString = {
`Value: ${literalWithToString}`;
```

## Options

The rule accepts an options object with the following properties:

```ts
type Options = {
// if true, interpolated expressions in tagged templates will not be checked
ignoreTaggedTemplateExpressions?: boolean;
};

const defaults = {
ignoreTaggedTemplateExpressions: false,
};
```

### `ignoreTaggedTemplateExpressions`

This allows to skip checking tagged templates, for cases where the tags do not necessarily stringify interpolated values.

Examples of additional **correct** code for this rule with `{ ignoreTaggedTemplateExpressions: true }`:

```ts
function tag() {}
tag`${{}}`;
```

## When Not To Use It

If you don't mind `"[object Object]"` in your strings, then you will not need this rule.
Expand Down
8 changes: 4 additions & 4 deletions packages/eslint-plugin/src/rules/no-base-to-string.ts
Expand Up @@ -14,6 +14,7 @@ enum Usefulness {

type Options = [
{
/** @deprecated This option is now ignored and treated as always true, it will be removed in 3.0 */
ignoreTaggedTemplateExpressions?: boolean;
},
];
Expand All @@ -39,16 +40,16 @@ export default util.createRule<Options, MessageIds>({
properties: {
ignoreTaggedTemplateExpressions: {
type: 'boolean',
default: false,
default: true,
},
},
additionalProperties: false,
},
],
type: 'suggestion',
},
defaultOptions: [{ ignoreTaggedTemplateExpressions: false }],
create(context, [options]) {
defaultOptions: [{ ignoreTaggedTemplateExpressions: true }],
create(context) {
const parserServices = util.getParserServices(context);
const typeChecker = parserServices.program.getTypeChecker();

Expand Down Expand Up @@ -130,7 +131,6 @@ export default util.createRule<Options, MessageIds>({
},
TemplateLiteral(node: TSESTree.TemplateLiteral): void {
if (
options.ignoreTaggedTemplateExpressions &&
node.parent &&
node.parent.type === AST_NODE_TYPES.TaggedTemplateExpression
) {
Expand Down
19 changes: 4 additions & 15 deletions packages/eslint-plugin/tests/rules/no-base-to-string.test.ts
Expand Up @@ -70,6 +70,10 @@ const literalWithToString = {
'let _ = {} ^ {};',
'let _ = {} << {};',
'let _ = {} >> {};',
`
function tag() {}
tag\`\${{}}\`;
`,
{
code: `
function tag() {}
Expand All @@ -95,21 +99,6 @@ const literalWithToString = {
},
],
},
{
code: `
function tag() {}
tag\`\${{}}\`;
`,
errors: [
{
data: {
certainty: 'will',
name: '{}',
},
messageId: 'baseToString',
},
],
},
{
code: '({}.toString());',
errors: [
Expand Down

0 comments on commit 369978e

Please sign in to comment.