From 1e18dc9365f3055ba7f62701de06a12f804a97a4 Mon Sep 17 00:00:00 2001 From: Nils Haberkamp Date: Thu, 22 Jun 2023 10:52:02 +0200 Subject: [PATCH 1/2] test(eslint-plugin): add test for banning types when using intersections --- .../eslint-plugin/tests/rules/ban-types.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/eslint-plugin/tests/rules/ban-types.test.ts b/packages/eslint-plugin/tests/rules/ban-types.test.ts index 831d17a59a16..70ce6bf1f0c1 100644 --- a/packages/eslint-plugin/tests/rules/ban-types.test.ts +++ b/packages/eslint-plugin/tests/rules/ban-types.test.ts @@ -657,6 +657,21 @@ let baz: object = {}; }, ], }, + { + code: 'type Baz = 1 & Foo;', + errors: [ + { + messageId: 'bannedTypeMessage', + }, + ], + options: [ + { + types: { + Foo: { message: '' }, + }, + }, + ], + }, ...objectReduceKey( TYPE_KEYWORDS, (acc: TSESLint.InvalidTestCase[], key) => { From 59050af771e5a646bdf2cb70a4c6026dabc171ec Mon Sep 17 00:00:00 2001 From: Nils Haberkamp Date: Thu, 22 Jun 2023 11:00:08 +0200 Subject: [PATCH 2/2] feat(eslint-plugin): ban certain types to be extended from --- packages/eslint-plugin/src/rules/ban-types.ts | 6 ++ .../tests/rules/ban-types.test.ts | 60 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/packages/eslint-plugin/src/rules/ban-types.ts b/packages/eslint-plugin/src/rules/ban-types.ts index 9e7d9f69f4ba..21a1d1c1403d 100644 --- a/packages/eslint-plugin/src/rules/ban-types.ts +++ b/packages/eslint-plugin/src/rules/ban-types.ts @@ -260,6 +260,12 @@ export default util.createRule({ checkBannedTypes(node); } }, + TSInterfaceHeritage(node): void { + checkBannedTypes(node); + }, + TSClassImplements(node): void { + checkBannedTypes(node); + }, }; }, }); diff --git a/packages/eslint-plugin/tests/rules/ban-types.test.ts b/packages/eslint-plugin/tests/rules/ban-types.test.ts index 70ce6bf1f0c1..5f22d9e40814 100644 --- a/packages/eslint-plugin/tests/rules/ban-types.test.ts +++ b/packages/eslint-plugin/tests/rules/ban-types.test.ts @@ -672,6 +672,66 @@ let baz: object = {}; }, ], }, + { + code: 'interface Foo extends Bar {}', + errors: [ + { + messageId: 'bannedTypeMessage', + }, + ], + options: [ + { + types: { + Bar: { message: '' }, + }, + }, + ], + }, + { + code: 'interface Foo extends Bar, Baz {}', + errors: [ + { + messageId: 'bannedTypeMessage', + }, + ], + options: [ + { + types: { + Bar: { message: '' }, + }, + }, + ], + }, + { + code: 'class Foo implements Bar {}', + errors: [ + { + messageId: 'bannedTypeMessage', + }, + ], + options: [ + { + types: { + Bar: { message: '' }, + }, + }, + ], + }, + { + code: 'class Foo implements Bar, Baz {}', + errors: [ + { + messageId: 'bannedTypeMessage', + }, + ], + options: [ + { + types: { + Bar: { message: 'Bla' }, + }, + }, + ], + }, ...objectReduceKey( TYPE_KEYWORDS, (acc: TSESLint.InvalidTestCase[], key) => { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy