UNPKG

4.3 kBTypeScriptView Raw
1/// <reference types="node" />
2import * as minimatch from 'minimatch';
3import * as cspell from 'cspell-lib';
4import { TraceResult, CheckTextInfo } from 'cspell-lib';
5export { TraceResult, IncludeExcludeFlag } from 'cspell-lib';
6import { GlobMatcher } from 'cspell-glob';
7export interface CSpellApplicationOptions extends BaseOptions {
8 /**
9 * Display verbose information
10 */
11 verbose?: boolean;
12 /**
13 * Show extensive output.
14 */
15 debug?: boolean;
16 /**
17 * a glob to exclude files from being checked.
18 */
19 exclude?: string;
20 /**
21 * Only report the words, no line numbers or file names.
22 */
23 wordsOnly?: boolean;
24 /**
25 * unique errors per file only.
26 */
27 unique?: boolean;
28 /**
29 * root directory, defaults to `cwd`
30 */
31 root?: string;
32}
33export declare type TraceOptions = BaseOptions;
34export interface BaseOptions {
35 config?: string;
36 languageId?: string;
37 local?: string;
38}
39export declare type AppError = NodeJS.ErrnoException;
40export interface RunResult {
41 files: number;
42 filesWithIssues: Set<string>;
43 issues: number;
44 errors: number;
45}
46export declare type Issue = cspell.TextDocumentOffset;
47export interface GlobSrcInfo {
48 matcher: GlobMatcher;
49 source: string;
50}
51export declare type MessageType = 'Debug' | 'Info' | 'Progress';
52export declare type MessageTypeLookup = {
53 [key in MessageType]: key;
54};
55export declare const MessageTypes: MessageTypeLookup;
56export interface MessageEmitter {
57 (message: string, msgType: MessageType): void;
58}
59export interface DebugEmitter {
60 (message: string): void;
61}
62export interface ErrorEmitterVoid {
63 (message: string, error: Error): void;
64}
65export interface ErrorEmitterPromise {
66 (message: string, error: Error): Promise<void>;
67}
68declare type ErrorEmitter = ErrorEmitterVoid | ErrorEmitterPromise;
69export interface SpellingErrorEmitter {
70 (issue: Issue): void;
71}
72export interface Emitters {
73 issue: SpellingErrorEmitter;
74 info: MessageEmitter;
75 debug: DebugEmitter;
76 error: ErrorEmitter;
77}
78interface GlobOptions extends minimatch.IOptions {
79 cwd?: string;
80 root?: string;
81}
82export declare class CSpellApplicationConfiguration {
83 readonly files: string[];
84 readonly options: CSpellApplicationOptions;
85 readonly emitters: Emitters;
86 readonly info: MessageEmitter;
87 readonly debug: DebugEmitter;
88 readonly logIssue: SpellingErrorEmitter;
89 readonly uniqueFilter: (issue: Issue) => boolean;
90 readonly local: string;
91 readonly configFile: string | undefined;
92 readonly configGlob: string;
93 readonly configGlobOptions: minimatch.IOptions;
94 readonly excludes: GlobSrcInfo[];
95 readonly root: string;
96 constructor(files: string[], options: CSpellApplicationOptions, emitters: Emitters);
97}
98export declare function lint(files: string[], options: CSpellApplicationOptions, emitters: Emitters): Promise<RunResult>;
99export declare function trace(words: string[], options: TraceOptions): Promise<TraceResult[]>;
100export declare type CheckTextResult = CheckTextInfo;
101export declare function checkText(filename: string, options: BaseOptions): Promise<CheckTextResult>;
102export declare function createInit(_: CSpellApplicationOptions): Promise<void>;
103/**
104 * Looks for matching glob patterns or stdin
105 * @param globPatterns patterns or stdin
106 */
107declare function findFiles(globPatterns: string[], options: GlobOptions): Promise<string[]>;
108interface PatternRoot {
109 pattern: string;
110 root: string;
111}
112/**
113 * Attempt to normalize a pattern based upon the root.
114 * If the pattern is absolute, check to see if it exists and adjust the root, otherwise it is assumed to be based upon the current root.
115 * If the pattern starts with a relative path, adjust the root to match.
116 * The challenge is with the patterns that begin with `/`. Is is an absolute path or relative pattern?
117 * @param pat glob pattern
118 * @param root absolute path | empty
119 * @returns the adjusted root and pattern.
120 */
121declare function normalizePattern(pat: string, root: string): PatternRoot;
122declare function _globP(pattern: string, options: GlobOptions): Promise<string[]>;
123export declare const _testing_: {
124 _globP: typeof _globP;
125 findFiles: typeof findFiles;
126 normalizePattern: typeof normalizePattern;
127};