UNPKG

2.9 kBTypeScriptView Raw
1import * as CodeMirror from "../../";
2
3export interface BaseLintStateOptions<T> {
4 /** debounce delay before linting onChange */
5 delay?: number | undefined;
6
7 /** callback to modify an annotation before display */
8 formatAnnotation?: ((annotation: Annotation) => Annotation) | undefined;
9
10 /** whether to lint onChange event */
11 lintOnChange?: boolean | undefined;
12
13 selfContain?: boolean | undefined;
14
15 /** callback after linter completes */
16 onUpdateLinting?(
17 annotationsNotSorted: Annotation[],
18 annotations: Annotation[],
19 codeMirror: CodeMirror.Editor,
20 ): void;
21
22 /**
23 * Passing rules in `options` property prevents JSHint (and other linters) from complaining
24 * about unrecognized rules like `onUpdateLinting`, `delay`, `lintOnChange`, etc.
25 */
26 options?: T | undefined;
27
28 /** controls display of lint tooltips */
29 tooltips?: boolean | "gutter" | undefined;
30}
31
32export interface SyncLintStateOptions<T> extends BaseLintStateOptions<T> {
33 async?: false | undefined;
34 getAnnotations?: Linter<T> | undefined;
35}
36
37export interface AsyncLintStateOptions<T> extends BaseLintStateOptions<T> {
38 /** specifies that the lint process runs asynchronously */
39 async: true;
40 getAnnotations?: AsyncLinter<T> | undefined;
41}
42
43export type LintStateOptions<T> = SyncLintStateOptions<T> | AsyncLintStateOptions<T>;
44
45/**
46 * A function that return errors found during the linting process.
47 */
48export interface Linter<T> {
49 (content: string, options: T, codeMirror: CodeMirror.Editor):
50 | Annotation[]
51 | PromiseLike<Annotation[]>;
52}
53
54/**
55 * A function that calls the updateLintingCallback with any errors found during the linting process.
56 */
57export interface AsyncLinter<T> {
58 (
59 content: string,
60 updateLintingCallback: UpdateLintingCallback,
61 options: T,
62 codeMirror: CodeMirror.Editor,
63 ): void;
64}
65
66/**
67 * A function that, given an array of annotations, updates the CodeMirror linting GUI with those annotations
68 */
69export interface UpdateLintingCallback {
70 (annotations: Annotation[]): void;
71 (codeMirror: CodeMirror.Editor, annotations: Annotation[]): void;
72}
73
74/**
75 * An annotation contains a description of a lint error, detailing the location of the error within the code, the severity of the error,
76 * and an explaination as to why the error was thrown.
77 */
78export interface Annotation {
79 from: CodeMirror.Position;
80 message?: string | undefined;
81 severity?: string | undefined;
82 to?: CodeMirror.Position | undefined;
83}
84
85declare module "../../" {
86 interface Editor {
87 performLint: () => void;
88 }
89
90 interface EditorConfiguration {
91 /** Optional lint configuration to be used in conjunction with CodeMirror's linter addon. */
92 lint?: boolean | LintStateOptions<any> | Linter<any> | undefined;
93 }
94
95 namespace lint {}
96}