fix all eslint errors

This commit is contained in:
Philipp Kühn
2020-09-24 09:49:46 +02:00
parent 0b40a0db0f
commit 5d8d353bd0
3 changed files with 11 additions and 14 deletions

View File

@@ -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.`)
}

View File

@@ -40,14 +40,14 @@ export interface Commands {}
export type CommandNames = Extract<keyof Commands, string>
export type SingleCommands = {
[Command in keyof Commands]: Commands[Command] extends (...args: any[]) => any
? (...args: Parameters<Commands[Command]>) => boolean
[Item in keyof Commands]: Commands[Item] extends (...args: any[]) => any
? (...args: Parameters<Commands[Item]>) => boolean
: never
}
export type ChainedCommands = {
[Command in keyof Commands]: Commands[Command] extends (...args: any[]) => any
? (...args: Parameters<Commands[Command]>) => ChainedCommands
[Item in keyof Commands]: Commands[Item] extends (...args: any[]) => any
? (...args: Parameters<Commands[Item]>) => ChainedCommands
: never
} & {
run: () => boolean

View File

@@ -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())
}