1 | import * as CodeMirror from "../../";
|
2 |
|
3 | export interface BaseLintStateOptions<T> {
|
4 |
|
5 | delay?: number | undefined;
|
6 |
|
7 |
|
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 |
|
32 | export interface SyncLintStateOptions<T> extends BaseLintStateOptions<T> {
|
33 | async?: false | undefined;
|
34 | getAnnotations?: Linter<T> | undefined;
|
35 | }
|
36 |
|
37 | export interface AsyncLintStateOptions<T> extends BaseLintStateOptions<T> {
|
38 | /** specifies that the lint process runs asynchronously */
|
39 | async: true;
|
40 | getAnnotations?: AsyncLinter<T> | undefined;
|
41 | }
|
42 |
|
43 | export type LintStateOptions<T> = SyncLintStateOptions<T> | AsyncLintStateOptions<T>;
|
44 |
|
45 | /**
|
46 | * A function that return errors found during the linting process.
|
47 | */
|
48 | export 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 | */
|
57 | export 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 | */
|
69 | export 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 | */
|
78 | export interface Annotation {
|
79 | from: CodeMirror.Position;
|
80 | message?: string | undefined;
|
81 | severity?: string | undefined;
|
82 | to?: CodeMirror.Position | undefined;
|
83 | }
|
84 |
|
85 | declare module "../../" {
|
86 | interface Editor {
|
87 | performLint: () => void;
|
88 | }
|
89 |
|
90 | interface EditorConfiguration {
|
91 |
|
92 | lint?: boolean | LintStateOptions<any> | Linter<any> | undefined;
|
93 | }
|
94 |
|
95 | namespace lint {}
|
96 | }
|