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