From 264b017c11c2ab132fcbad18b42a9a0fe639386e Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Sun, 10 May 2020 17:54:56 -0700 Subject: [PATCH] feat(eslint-plugin): [restrict-template-expressions] rename `allowNullable` to `allowNullish` (#2006) --- .../rules/restrict-template-expressions.md | 8 ++++---- .../rules/restrict-template-expressions.ts | 6 +++--- .../restrict-template-expressions.test.ts | 20 +++++++++---------- 3 files changed, 17 insertions(+), 17 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 dd030cf5bc0..a3cbb0b6f3b 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 2d1a7422183..df5d5aefb25 100644 --- a/packages/eslint-plugin/tests/rules/restrict-template-expressions.test.ts +++ b/packages/eslint-plugin/tests/rules/restrict-template-expressions.test.ts @@ -158,23 +158,23 @@ ruleTester.run('restrict-template-expressions', rule, { const msg = \`arg = \${user.name || 'the user with no name'}\`; `, }, - // 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}\`; @@ -182,7 +182,7 @@ ruleTester.run('restrict-template-expressions', rule, { `, }, { - options: [{ allowNullable: true }], + options: [{ allowNullish: true }], code: ` function test(arg: T) { return \`arg = \${arg}\`; @@ -191,7 +191,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) { @@ -272,7 +272,7 @@ ruleTester.run('restrict-template-expressions', rule, { ], }, { - options: [{ allowNumber: true, allowBoolean: true, allowNullable: true }], + options: [{ allowNumber: true, allowBoolean: true, allowNullish: true }], code: ` const arg = {}; const msg = \`arg = \${arg}\`; @@ -296,7 +296,7 @@ ruleTester.run('restrict-template-expressions', rule, { ], }, { - options: [{ allowNumber: true, allowBoolean: true, allowNullable: true }], + options: [{ allowNumber: true, allowBoolean: true, allowNullish: true }], code: ` function test(arg: T) { return \`arg = \${arg}\`; @@ -307,7 +307,7 @@ ruleTester.run('restrict-template-expressions', rule, { ], }, { - options: [{ allowNumber: true, allowBoolean: true, allowNullable: true }], + options: [{ allowNumber: true, allowBoolean: true, allowNullish: true }], code: ` function test(arg: T) { return \`arg = \${arg}\`; @@ -323,7 +323,7 @@ ruleTester.run('restrict-template-expressions', rule, { ], }, { - options: [{ allowNumber: true, allowBoolean: true, allowNullable: true }], + options: [{ allowNumber: true, allowBoolean: true, allowNullish: true }], code: ` function test(arg: any) { return \`arg = \${arg}\`;