UNPKG

1.92 kBTypeScriptView Raw
1import * as ts from 'typescript';
2import { Finding, EffectiveConfiguration, LintAndFixFileResult, Severity, MessageHandler, AbstractProcessor, DeprecationHandler, FindingFilterFactory } from '@fimbul/ymir';
3import { RuleLoader } from './services/rule-loader';
4export interface LinterOptions {
5 reportUselessDirectives?: Severity;
6}
7/** This factory is used to lazily create or update the Program only when necessary. */
8export interface ProgramFactory {
9 /** Get the CompilerOptions used to create the Program. */
10 getCompilerOptions(): ts.CompilerOptions;
11 /** This method is called to retrieve the Program on the first use. It should create or update the Program if necessary. */
12 getProgram(): ts.Program;
13}
14/**
15 * Creates a new SourceFile from the updated source.
16 *
17 * @returns the new `SourceFile` on success or `undefined` to roll back the latest set of changes.
18 */
19export declare type UpdateFileCallback = (content: string, range: ts.TextChangeRange) => ts.SourceFile | undefined;
20export declare class Linter {
21 private ruleLoader;
22 private logger;
23 private deprecationHandler;
24 private filterFactory;
25 constructor(ruleLoader: RuleLoader, logger: MessageHandler, deprecationHandler: DeprecationHandler, filterFactory: FindingFilterFactory);
26 lintFile(file: ts.SourceFile, config: EffectiveConfiguration, programOrFactory?: ProgramFactory | ts.Program, options?: LinterOptions): ReadonlyArray<Finding>;
27 lintAndFix(file: ts.SourceFile, content: string, config: EffectiveConfiguration, updateFile: UpdateFileCallback, iterations?: number, programFactory?: ProgramFactory, processor?: AbstractProcessor, options?: LinterOptions,
28 /** Initial set of findings from a cache. If provided, the initial linting is skipped and these findings are used for fixing. */
29 findings?: readonly Finding[]): LintAndFixFileResult;
30 private prepareRules;
31 private applyRules;
32}