From 5d8d353bd0e70b02bbeb1d747a53df44dc9a8522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Thu, 24 Sep 2020 09:49:46 +0200 Subject: [PATCH] fix all eslint errors --- packages/core/src/CommandManager.ts | 5 ++++- packages/core/src/Editor.ts | 8 ++++---- packages/core/src/utils/getAllMethodNames.ts | 12 +++--------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/packages/core/src/CommandManager.ts b/packages/core/src/CommandManager.ts index 91ee92c0..c9352af2 100644 --- a/packages/core/src/CommandManager.ts +++ b/packages/core/src/CommandManager.ts @@ -8,8 +8,11 @@ export default class CommandManager { commands: { [key: string]: any } = {} + methodNames: string[] = [] + constructor(editor: Editor) { this.editor = editor + this.methodNames = getAllMethodNames(this.editor) } /** @@ -23,7 +26,7 @@ export default class CommandManager { throw new Error(`tiptap: command '${name}' is already defined.`) } - if (getAllMethodNames(this.editor).includes(name)) { + if (this.methodNames.includes(name)) { throw new Error(`tiptap: '${name}' is a protected name.`) } diff --git a/packages/core/src/Editor.ts b/packages/core/src/Editor.ts index 2194a5d6..3e4b448e 100644 --- a/packages/core/src/Editor.ts +++ b/packages/core/src/Editor.ts @@ -40,14 +40,14 @@ export interface Commands {} export type CommandNames = Extract export type SingleCommands = { - [Command in keyof Commands]: Commands[Command] extends (...args: any[]) => any - ? (...args: Parameters) => boolean + [Item in keyof Commands]: Commands[Item] extends (...args: any[]) => any + ? (...args: Parameters) => boolean : never } export type ChainedCommands = { - [Command in keyof Commands]: Commands[Command] extends (...args: any[]) => any - ? (...args: Parameters) => ChainedCommands + [Item in keyof Commands]: Commands[Item] extends (...args: any[]) => any + ? (...args: Parameters) => ChainedCommands : never } & { run: () => boolean diff --git a/packages/core/src/utils/getAllMethodNames.ts b/packages/core/src/utils/getAllMethodNames.ts index f773df95..62081b6d 100644 --- a/packages/core/src/utils/getAllMethodNames.ts +++ b/packages/core/src/utils/getAllMethodNames.ts @@ -1,10 +1,4 @@ -export default function getAllMethodNames(obj: Object) { - const methods = new Set() - - while (obj = Reflect.getPrototypeOf(obj)) { - const keys = Reflect.ownKeys(obj) - keys.forEach(k => methods.add(k)) - } - - return Array.from(methods) +export default function getAllMethodNames(obj: Object): string[] { + return Reflect.ownKeys(Reflect.getPrototypeOf(obj)) + .map(name => name.toString()) }