feat: add linter and linterGutter (#2237)

Signed-off-by: Philip Molares <philip.molares@udo.edu>
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>

Co-authored-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Philip Molares 2022-07-31 18:25:03 +02:00 committed by GitHub
parent 57cc08739d
commit 1bd18cc0ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 471 additions and 182 deletions

View file

@ -0,0 +1,30 @@
/*
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import type { Diagnostic } from '@codemirror/lint'
import { linter } from '@codemirror/lint'
import { useMemo } from 'react'
import type { Extension } from '@codemirror/state'
import type { EditorView } from '@codemirror/view'
/**
* The Linter interface.
*
* This should be implemented by each linter we want to use.
*/
export interface Linter {
lint(view: EditorView): Diagnostic[]
}
/**
* The hook to create a single codemirror linter from all our linters.
*
* @param linters The {@link Linter linters} to use for the codemirror linter.
* @return The build codemirror linter
*/
export const useLinter = (linters: Linter[]): Extension => {
return useMemo(() => linter((view) => linters.flatMap((aLinter) => aLinter.lint(view))), [linters])
}