1 | import 'reflect-metadata';
|
2 | import * as ts from 'typescript';
|
3 | import { WrappedAst, BooleanCompilerOptions } from 'tsutils';
|
4 | export declare class ConfigurationError extends Error {
|
5 | }
|
6 | export declare abstract class GlobalOptions {
|
7 | readonly [key: string]: {} | null | undefined;
|
8 | }
|
9 | export declare type LintResult = Iterable<[string, FileSummary]>;
|
10 | export declare type FileSummary = LintAndFixFileResult;
|
11 | export interface LintAndFixFileResult {
|
12 | content: string;
|
13 | findings: ReadonlyArray<Finding>;
|
14 | fixes: number;
|
15 | }
|
16 | export interface Replacement {
|
17 | readonly start: number;
|
18 | readonly end: number;
|
19 | readonly text: string;
|
20 | }
|
21 | export declare const Replacement: {
|
22 | replace(start: number, end: number, text: string): Replacement;
|
23 | append(pos: number, text: string): Replacement;
|
24 | delete(start: number, end: number): Replacement;
|
25 | };
|
26 | export interface Fix {
|
27 | readonly replacements: ReadonlyArray<Replacement>;
|
28 | }
|
29 | export interface Finding {
|
30 | readonly start: FindingPosition;
|
31 | readonly end: FindingPosition;
|
32 | readonly message: string;
|
33 | readonly ruleName: string;
|
34 | readonly severity: Severity;
|
35 | readonly fix: Fix | undefined;
|
36 | }
|
37 | export declare const Finding: {
|
38 |
|
39 | compare(a: Finding, b: Finding): number;
|
40 | };
|
41 | export interface FindingPosition {
|
42 | readonly line: number;
|
43 | readonly character: number;
|
44 | readonly position: number;
|
45 | }
|
46 | export declare type Severity = 'error' | 'warning' | 'suggestion';
|
47 | export interface RuleConstructor<T extends RuleContext = RuleContext> {
|
48 | readonly requiresTypeInformation: boolean;
|
49 | readonly deprecated?: boolean | string;
|
50 | supports?: RulePredicate;
|
51 | new (context: T): AbstractRule;
|
52 | }
|
53 | export interface RulePredicateContext {
|
54 | readonly program?: ts.Program;
|
55 | readonly compilerOptions?: ts.CompilerOptions;
|
56 | readonly settings: Settings;
|
57 | readonly options: {} | null | undefined;
|
58 | }
|
59 | export interface RuleContext extends RulePredicateContext {
|
60 | readonly sourceFile: ts.SourceFile;
|
61 | addFinding(start: number, end: number, message: string, fix?: Replacement | ReadonlyArray<Replacement>): void;
|
62 | getFlatAst(): ReadonlyArray<ts.Node>;
|
63 | getWrappedAst(): WrappedAst;
|
64 | }
|
65 | export interface TypedRuleContext extends RuleContext {
|
66 | readonly program: ts.Program;
|
67 | readonly compilerOptions: ts.CompilerOptions;
|
68 | }
|
69 | export declare type Settings = ReadonlyMap<string, {} | null | undefined>;
|
70 | export declare function predicate(check: RulePredicate): (target: typeof AbstractRule) => void;
|
71 | export declare function typescriptOnly(target: typeof AbstractRule): void;
|
72 | export declare function excludeDeclarationFiles(target: typeof AbstractRule): void;
|
73 | export declare function requireLibraryFile(fileName: string): (target: typeof TypedRule) => void;
|
74 | export declare function requiresCompilerOption(option: BooleanCompilerOptions): (target: typeof TypedRule) => void;
|
75 |
|
76 | export declare type RulePredicate = (sourceFile: ts.SourceFile, context: RulePredicateContext) => boolean | string;
|
77 | export declare abstract class AbstractRule {
|
78 | readonly context: RuleContext;
|
79 | static readonly requiresTypeInformation: boolean;
|
80 | static deprecated: boolean | string;
|
81 | static supports?: RulePredicate;
|
82 | static validateConfig?(config: any): string[] | string | undefined;
|
83 | readonly sourceFile: ts.SourceFile;
|
84 | get program(): ts.Program | undefined;
|
85 | constructor(context: RuleContext);
|
86 | abstract apply(): void;
|
87 | addFinding(start: number, end: number, message: string, fix?: Replacement | ReadonlyArray<Replacement>): void;
|
88 | addFindingAtNode(node: ts.Node, message: string, fix?: Replacement | ReadonlyArray<Replacement>): void;
|
89 | }
|
90 | export declare abstract class ConfigurableRule<T> extends AbstractRule {
|
91 | options: T;
|
92 | constructor(context: RuleContext);
|
93 | protected abstract parseOptions(options: {} | null | undefined): T;
|
94 | }
|
95 | export declare abstract class TypedRule extends AbstractRule {
|
96 | static readonly requiresTypeInformation = true;
|
97 | readonly context: TypedRuleContext;
|
98 | get program(): ts.Program;
|
99 |
|
100 | get checker(): ts.TypeChecker;
|
101 | constructor(context: TypedRuleContext);
|
102 | }
|
103 | export declare abstract class ConfigurableTypedRule<T> extends TypedRule {
|
104 | options: T;
|
105 | constructor(context: TypedRuleContext);
|
106 | protected abstract parseOptions(options: {} | null | undefined): T;
|
107 | }
|
108 | export declare abstract class AbstractFormatter {
|
109 | prefix?: string;
|
110 | abstract format(filename: string, summary: FileSummary): string | undefined;
|
111 | flush?(): string | undefined;
|
112 | }
|
113 | export interface FormatterConstructor {
|
114 | new (): AbstractFormatter;
|
115 | }
|
116 | export interface Configuration {
|
117 | readonly aliases?: ReadonlyMap<string, Configuration.Alias>;
|
118 | readonly rules?: ReadonlyMap<string, Configuration.RuleConfig>;
|
119 | readonly settings?: Settings;
|
120 | readonly filename: string;
|
121 | readonly overrides?: ReadonlyArray<Configuration.Override>;
|
122 | readonly extends: ReadonlyArray<Configuration>;
|
123 | readonly rulesDirectories?: Configuration.RulesDirectoryMap;
|
124 | readonly processor?: string | null | false;
|
125 | readonly exclude?: ReadonlyArray<string>;
|
126 | }
|
127 | export declare namespace Configuration {
|
128 | type RulesDirectoryMap = ReadonlyMap<string, ReadonlyArray<string>>;
|
129 | type RuleSeverity = 'off' | 'warning' | 'error' | 'suggestion';
|
130 | interface RuleConfig {
|
131 | readonly severity?: RuleSeverity;
|
132 | readonly options?: any;
|
133 | readonly rulesDirectories: ReadonlyArray<string> | undefined;
|
134 | readonly rule: string;
|
135 | }
|
136 | interface Override {
|
137 | readonly rules?: ReadonlyMap<string, RuleConfig>;
|
138 | readonly settings?: ReadonlyMap<string, any>;
|
139 | readonly files: ReadonlyArray<string>;
|
140 | readonly processor?: string | null | false;
|
141 | }
|
142 | interface Alias {
|
143 | readonly rule: string;
|
144 | readonly options?: any;
|
145 | readonly rulesDirectories: ReadonlyArray<string> | undefined;
|
146 | }
|
147 | }
|
148 | export interface EffectiveConfiguration {
|
149 | rules: Map<string, EffectiveConfiguration.RuleConfig>;
|
150 | settings: Map<string, any>;
|
151 | }
|
152 | export declare namespace EffectiveConfiguration {
|
153 | interface RuleConfig {
|
154 | severity: Configuration.RuleSeverity;
|
155 | options: any;
|
156 | rulesDirectories: ReadonlyArray<string> | undefined;
|
157 | rule: string;
|
158 | }
|
159 | }
|
160 | export interface ReducedConfiguration extends EffectiveConfiguration {
|
161 | processor: string | undefined;
|
162 | }
|
163 | export interface ConfigurationProvider {
|
164 | find(fileToLint: string): string | undefined;
|
165 | resolve(name: string, basedir: string): string;
|
166 | load(fileName: string, context: LoadConfigurationContext): Configuration;
|
167 | }
|
168 | export declare abstract class ConfigurationProvider {
|
169 | }
|
170 | export interface LoadConfigurationContext {
|
171 | readonly stack: ReadonlyArray<string>;
|
172 | |
173 |
|
174 |
|
175 |
|
176 | load(name: string): Configuration;
|
177 | }
|
178 | export declare enum Format {
|
179 | Yaml = "yaml",
|
180 | Json = "json",
|
181 | Json5 = "json5"
|
182 | }
|
183 | export interface ProcessorConstructor {
|
184 | getSuffixForFile(context: ProcessorSuffixContext): string;
|
185 | new (context: ProcessorContext): AbstractProcessor;
|
186 | }
|
187 | export interface ProcessorSuffixContext {
|
188 | fileName: string;
|
189 | getSettings(): Settings;
|
190 | readFile(): string;
|
191 | }
|
192 | export interface ProcessorContext {
|
193 | source: string;
|
194 | sourceFileName: string;
|
195 | targetFileName: string;
|
196 | settings: Settings;
|
197 | }
|
198 | export interface ProcessorUpdateResult {
|
199 | transformed: string;
|
200 | changeRange?: ts.TextChangeRange;
|
201 | }
|
202 | export declare abstract class AbstractProcessor {
|
203 | |
204 |
|
205 |
|
206 |
|
207 | static getSuffixForFile(_context: ProcessorSuffixContext): string;
|
208 | protected source: string;
|
209 | protected sourceFileName: string;
|
210 | protected targetFileName: string;
|
211 | protected settings: Settings;
|
212 | constructor(context: ProcessorContext);
|
213 | abstract preprocess(): string;
|
214 | abstract postprocess(findings: ReadonlyArray<Finding>): ReadonlyArray<Finding>;
|
215 | abstract updateSource(newSource: string, changeRange: ts.TextChangeRange): ProcessorUpdateResult;
|
216 | }
|
217 | export interface MessageHandler {
|
218 | log(message: string): void;
|
219 | warn(message: string): void;
|
220 | error(e: Error): void;
|
221 | }
|
222 | export declare abstract class MessageHandler {
|
223 | }
|
224 | export interface DeprecationHandler {
|
225 | handle(target: DeprecationTarget, name: string, text?: string): void;
|
226 | }
|
227 | export declare abstract class DeprecationHandler {
|
228 | }
|
229 | export declare enum DeprecationTarget {
|
230 | Rule = "rule",
|
231 | Processor = "processor",
|
232 | Formatter = "formatter"
|
233 | }
|
234 |
|
235 |
|
236 |
|
237 | export interface FileSystem {
|
238 |
|
239 | normalizePath(path: string): string;
|
240 |
|
241 | readFile(file: string): string;
|
242 |
|
243 | readDirectory(dir: string): Array<string | Dirent>;
|
244 |
|
245 | stat(path: string): Stats;
|
246 |
|
247 | realpath?(path: string): string;
|
248 |
|
249 | writeFile(file: string, content: string): void;
|
250 |
|
251 | deleteFile(path: string): void;
|
252 |
|
253 | createDirectory(dir: string): void;
|
254 | }
|
255 | export declare abstract class FileSystem {
|
256 | }
|
257 | export interface Stats {
|
258 | isDirectory(): boolean;
|
259 | isFile(): boolean;
|
260 | }
|
261 | export interface Dirent extends Stats {
|
262 | name: string;
|
263 | isSymbolicLink(): boolean;
|
264 | }
|
265 | export interface RuleLoaderHost {
|
266 | loadCoreRule(name: string): RuleConstructor | undefined;
|
267 | loadCustomRule(name: string, directory: string): RuleConstructor | undefined;
|
268 | }
|
269 | export declare abstract class RuleLoaderHost {
|
270 | }
|
271 | export interface FormatterLoaderHost {
|
272 | loadCoreFormatter(name: string): FormatterConstructor | undefined;
|
273 | loadCustomFormatter(name: string, basedir: string): FormatterConstructor | undefined;
|
274 | }
|
275 | export declare abstract class FormatterLoaderHost {
|
276 | }
|
277 | export interface CacheFactory {
|
278 |
|
279 | create<K extends object, V = any>(weak: true): Cache<K, V>;
|
280 | create<K = any, V = any>(weak?: false): Cache<K, V>;
|
281 | }
|
282 | export declare abstract class CacheFactory {
|
283 | }
|
284 | export interface Cache<K, V> {
|
285 | get(key: K): V | undefined;
|
286 | set(key: K, value: V): void;
|
287 | delete(key: K): void;
|
288 | has(key: K): boolean;
|
289 | clear(): void;
|
290 | }
|
291 | export interface Resolver {
|
292 | getDefaultExtensions(): ReadonlyArray<string>;
|
293 | resolve(id: string, basedir?: string, extensions?: ReadonlyArray<string>, paths?: ReadonlyArray<string>): string;
|
294 | require(id: string, options?: {
|
295 | cache?: boolean;
|
296 | }): any;
|
297 | }
|
298 | export declare abstract class Resolver {
|
299 | }
|
300 | export interface BuiltinResolver {
|
301 | resolveConfig(name: string): string;
|
302 | resolveRule(name: string): string;
|
303 | resolveFormatter(name: string): string;
|
304 | }
|
305 | export declare abstract class BuiltinResolver {
|
306 | }
|
307 | export interface DirectoryService {
|
308 | getCurrentDirectory(): string;
|
309 | getHomeDirectory?(): string;
|
310 | }
|
311 | export declare abstract class DirectoryService {
|
312 | }
|
313 | export interface FindingFilterFactory {
|
314 | create(context: FindingFilterContext): FindingFilter;
|
315 | }
|
316 | export declare abstract class FindingFilterFactory {
|
317 | }
|
318 | export interface FindingFilterContext {
|
319 | sourceFile: ts.SourceFile;
|
320 | ruleNames: ReadonlyArray<string>;
|
321 | getWrappedAst(): WrappedAst;
|
322 | }
|
323 | export interface FindingFilter {
|
324 |
|
325 | filter(finding: Finding): boolean;
|
326 | |
327 |
|
328 |
|
329 |
|
330 | reportUseless(severity: Severity): ReadonlyArray<Finding>;
|
331 | }
|
332 | export interface LineSwitchParser {
|
333 | parse(context: LineSwitchParserContext): ReadonlyArray<RawLineSwitch>;
|
334 | }
|
335 | export declare abstract class LineSwitchParser {
|
336 | }
|
337 | export interface LineSwitchParserContext {
|
338 | sourceFile: ts.SourceFile;
|
339 | getCommentAtPosition(pos: number): ts.CommentRange | undefined;
|
340 | }
|
341 | export interface RawLineSwitch {
|
342 | readonly rules: ReadonlyArray<RawLineSwitchRule>;
|
343 | readonly enable: boolean;
|
344 | readonly pos: number;
|
345 | readonly end?: number;
|
346 | readonly location: Readonly<ts.TextRange>;
|
347 | }
|
348 | export interface RawLineSwitchRule {
|
349 | readonly predicate: string | RegExp | ((ruleName: string) => boolean);
|
350 | readonly location?: Readonly<ts.TextRange>;
|
351 | readonly fixLocation?: Readonly<ts.TextRange>;
|
352 | }
|
353 | export interface FileFilterContext {
|
354 | program: ts.Program;
|
355 | host: Required<Pick<ts.CompilerHost, 'directoryExists'>>;
|
356 | }
|
357 | export interface FileFilterFactory {
|
358 | create(context: FileFilterContext): FileFilter;
|
359 | }
|
360 | export declare abstract class FileFilterFactory {
|
361 | }
|
362 | export interface FileFilter {
|
363 | /** @returns `true` if the file should be linted, false if it should be filtered out. Intended for use in `Array.prototype.filter`. */
|
364 | filter(file: ts.SourceFile): boolean;
|
365 | }
|
366 | export declare type ContentIdHost = Pick<ts.CompilerHost, 'readFile'>;
|
367 | export interface ContentId {
|
368 | forFile(fileName: string, host: ContentIdHost): string;
|
369 | }
|
370 | export declare abstract class ContentId {
|
371 | }
|
372 | export interface StatePersistence {
|
373 | loadState(project: string): StaticProgramState | undefined;
|
374 | saveState(project: string, state: StaticProgramState): void;
|
375 | }
|
376 | export declare abstract class StatePersistence {
|
377 | }
|
378 | export interface StaticProgramState {
|
379 | /** Version of the cache format */
|
380 | readonly v: number;
|
381 | /** TypeScript version */
|
382 | readonly ts: string;
|
383 | /** Whether the state was created using case-sensitive file names */
|
384 | readonly cs: boolean;
|
385 | /** Hash of compilerOptions */
|
386 | readonly options: string;
|
387 | /** Maps filename to index in 'files' array */
|
388 | readonly lookup: Readonly<Record<string, number>>;
|
389 | /** Index of files that affect global scope */
|
390 | readonly global: readonly number[];
|
391 | /** Information about all files in the program */
|
392 | readonly files: readonly StaticProgramState.FileState[];
|
393 | }
|
394 | export declare namespace StaticProgramState {
|
395 | interface FileState {
|
396 | /** ID of file contents (typically a hash) */
|
397 | readonly id: string;
|
398 | /**
|
399 | * Key: module specifier as referenced in the file, order may be random
|
400 | * Value: - `null` if dependency could not be resolved
|
401 | * - List of files (or rather their index) that the module specifier resolves to.
|
402 | * That is the actual file at that path and/or files containing `declare module "..."` for that module specifier.
|
403 | * May contain the current file.
|
404 | * This list is ordered by the ID of the files ascending,
|
405 | */
|
406 | readonly dependencies?: Readonly<Record<string, null | readonly number[]>>;
|
407 | /** The list of findings if this file has up-to-date results */
|
408 | readonly result?: readonly Finding[];
|
409 | /** Hash of the configuration used to produce `result` for this file */
|
410 | readonly config?: string;
|
411 | }
|
412 | }
|
413 |
|
\ | No newline at end of file |