mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-22 03:05:19 -04:00
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:
parent
57cc08739d
commit
1bd18cc0ee
33 changed files with 471 additions and 182 deletions
30
src/components/editor-page/editor-pane/linter/linter.ts
Normal file
30
src/components/editor-page/editor-pane/linter/linter.ts
Normal 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])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue