From 922ec069e312bd399ecc08432d29e9ce32fc8d73 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Sun, 10 May 2020 17:44:06 -0700 Subject: [PATCH] feat(eslint-plugin): [restrict-template-expressions] rename `allowNullable` to `allowNullish` --- .../rules/restrict-template-expressions.md | 8 ++++---- .../src/rules/restrict-template-expressions.ts | 6 +++--- .../restrict-template-expressions.test.ts | 18 +++++++++--------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/restrict-template-expressions.md b/packages/eslint-plugin/docs/rules/restrict-template-expressions.md index 260a8eb188d..0ee7427ddac 100644 --- a/packages/eslint-plugin/docs/rules/restrict-template-expressions.md +++ b/packages/eslint-plugin/docs/rules/restrict-template-expressions.md @@ -34,14 +34,14 @@ type Options = { // if true, also allow any in template expressions allowAny?: boolean; // if true, also allow null and undefined in template expressions - allowNullable?: boolean; + allowNullish?: boolean; }; const defaults = { allowNumber: true, allowBoolean: false, allowAny: false, - allowNullable: false, + allowNullish: false, }; ``` @@ -75,9 +75,9 @@ const msg1 = `arg = ${user.name}`; const msg2 = `arg = ${user.name || 'the user with no name'}`; ``` -### `allowNullable` +### `allowNullish` -Examples of additional **correct** code for this rule with `{ allowNullable: true }`: +Examples of additional **correct** code for this rule with `{ allowNullish: true }`: ```ts const arg = condition ? 'ok' : null; diff --git a/packages/eslint-plugin/src/rules/restrict-template-expressions.ts b/packages/eslint-plugin/src/rules/restrict-template-expressions.ts index 191eb0efe64..28b2de155ee 100644 --- a/packages/eslint-plugin/src/rules/restrict-template-expressions.ts +++ b/packages/eslint-plugin/src/rules/restrict-template-expressions.ts @@ -10,7 +10,7 @@ type Options = [ allowNumber?: boolean; allowBoolean?: boolean; allowAny?: boolean; - allowNullable?: boolean; + allowNullish?: boolean; }, ]; @@ -36,7 +36,7 @@ export default util.createRule({ allowNumber: { type: 'boolean' }, allowBoolean: { type: 'boolean' }, allowAny: { type: 'boolean' }, - allowNullable: { type: 'boolean' }, + allowNullish: { type: 'boolean' }, }, }, ], @@ -77,7 +77,7 @@ export default util.createRule({ } if ( - options.allowNullable && + options.allowNullish && util.isTypeFlagSet(type, ts.TypeFlags.Null | ts.TypeFlags.Undefined) ) { return true; diff --git a/packages/eslint-plugin/tests/rules/restrict-template-expressions.test.ts b/packages/eslint-plugin/tests/rules/restrict-template-expressions.test.ts index d3328bded56..a1c3134e0d5 100644 --- a/packages/eslint-plugin/tests/rules/restrict-template-expressions.test.ts +++ b/packages/eslint-plugin/tests/rules/restrict-template-expressions.test.ts @@ -166,23 +166,23 @@ ruleTester.run('restrict-template-expressions', rule, { } `, }, - // allowNullable + // allowNullish { - options: [{ allowNullable: true }], + options: [{ allowNullish: true }], code: ` const arg = null; const msg = \`arg = \${arg}\`; `, }, { - options: [{ allowNullable: true }], + options: [{ allowNullish: true }], code: ` declare const arg: string | null | undefined; const msg = \`arg = \${arg}\`; `, }, { - options: [{ allowNullable: true }], + options: [{ allowNullish: true }], code: ` function test(arg: T) { return \`arg = \${arg}\`; @@ -190,7 +190,7 @@ ruleTester.run('restrict-template-expressions', rule, { `, }, { - options: [{ allowNullable: true }], + options: [{ allowNullish: true }], code: ` function test(arg: T) { return \`arg = \${arg}\`; @@ -199,7 +199,7 @@ ruleTester.run('restrict-template-expressions', rule, { }, // allow ALL { - options: [{ allowNumber: true, allowBoolean: true, allowNullable: true }], + options: [{ allowNumber: true, allowBoolean: true, allowNullish: true }], code: ` type All = string | number | boolean | null | undefined; function test(arg: T) { @@ -245,7 +245,7 @@ ruleTester.run('restrict-template-expressions', rule, { errors: [{ messageId: 'invalidType', line: 3, column: 30 }], }, { - options: [{ allowNumber: true, allowBoolean: true, allowNullable: true }], + options: [{ allowNumber: true, allowBoolean: true, allowNullish: true }], code: ` const arg = {}; const msg = \`arg = \${arg}\`; @@ -260,7 +260,7 @@ ruleTester.run('restrict-template-expressions', rule, { errors: [{ messageId: 'invalidType', line: 3, column: 30 }], }, { - options: [{ allowNumber: true, allowBoolean: true, allowNullable: true }], + options: [{ allowNumber: true, allowBoolean: true, allowNullish: true }], code: ` function test(arg: T) { return \`arg = \${arg}\`; @@ -269,7 +269,7 @@ ruleTester.run('restrict-template-expressions', rule, { errors: [{ messageId: 'invalidType', line: 3, column: 27 }], }, { - options: [{ allowNumber: true, allowBoolean: true, allowNullable: true }], + options: [{ allowNumber: true, allowBoolean: true, allowNullish: true }], code: ` function test(arg: any) { return \`arg = \${arg}\`;