1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | import * as ts from "typescript";
|
18 | import { IWalker } from "../walker";
|
19 | export interface RuleConstructor {
|
20 | metadata: IRuleMetadata;
|
21 | new (options: IOptions): IRule;
|
22 | }
|
23 | export interface IRuleMetadata {
|
24 | |
25 |
|
26 |
|
27 | ruleName: string;
|
28 | |
29 |
|
30 |
|
31 | type: RuleType;
|
32 | |
33 |
|
34 |
|
35 | deprecationMessage?: string;
|
36 | |
37 |
|
38 |
|
39 | description: string;
|
40 | |
41 |
|
42 |
|
43 | descriptionDetails?: string;
|
44 | |
45 |
|
46 |
|
47 | hasFix?: boolean;
|
48 | |
49 |
|
50 |
|
51 | optionsDescription: string;
|
52 | |
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | options: any;
|
59 | |
60 |
|
61 |
|
62 |
|
63 | optionExamples?: Array<true | any[]> | string[] | Array<{
|
64 | options: any;
|
65 | }>;
|
66 | |
67 |
|
68 |
|
69 | rationale?: string;
|
70 | |
71 |
|
72 |
|
73 | requiresTypeInfo?: boolean;
|
74 | |
75 |
|
76 |
|
77 | typescriptOnly: boolean;
|
78 | |
79 |
|
80 |
|
81 | codeExamples?: ICodeExample[];
|
82 | }
|
83 | export declare type RuleType = "functionality" | "maintainability" | "style" | "typescript" | "formatting";
|
84 | export declare type RuleSeverity = "warning" | "error" | "off";
|
85 | export interface ICodeExample {
|
86 | config: string;
|
87 | description: string;
|
88 | pass: string;
|
89 | fail?: string;
|
90 | }
|
91 | export interface IOptions {
|
92 | ruleArguments: any[];
|
93 | ruleSeverity: RuleSeverity;
|
94 | ruleName: string;
|
95 | |
96 |
|
97 |
|
98 |
|
99 |
|
100 | disabledIntervals: IDisabledInterval[];
|
101 | }
|
102 |
|
103 |
|
104 |
|
105 |
|
106 | export interface IDisabledInterval {
|
107 | startPosition: number;
|
108 | endPosition: number;
|
109 | }
|
110 | export interface IRule {
|
111 | getOptions(): IOptions;
|
112 | isEnabled(): boolean;
|
113 | apply(sourceFile: ts.SourceFile): RuleFailure[];
|
114 | applyWithWalker(walker: IWalker): RuleFailure[];
|
115 | }
|
116 | export interface ITypedRule extends IRule {
|
117 | applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): RuleFailure[];
|
118 | }
|
119 | export interface IRuleFailureJson {
|
120 | endPosition: IRuleFailurePositionJson;
|
121 | failure: string;
|
122 | fix?: FixJson;
|
123 | name: string;
|
124 | ruleSeverity: string;
|
125 | ruleName: string;
|
126 | startPosition: IRuleFailurePositionJson;
|
127 | }
|
128 | export interface IRuleFailurePositionJson {
|
129 | character: number;
|
130 | line: number;
|
131 | position: number;
|
132 | }
|
133 | export declare function isTypedRule(rule: IRule): rule is ITypedRule;
|
134 | export interface ReplacementJson {
|
135 | innerStart: number;
|
136 | innerLength: number;
|
137 | innerText: string;
|
138 | }
|
139 | export declare class Replacement {
|
140 | readonly start: number;
|
141 | readonly length: number;
|
142 | readonly text: string;
|
143 | static applyFixes(content: string, fixes: Fix[]): string;
|
144 | static applyAll(content: string, replacements: Replacement[]): string;
|
145 | static replaceNode(node: ts.Node, text: string, sourceFile?: ts.SourceFile): Replacement;
|
146 | static replaceFromTo(start: number, end: number, text: string): Replacement;
|
147 | static deleteText(start: number, length: number): Replacement;
|
148 | static deleteFromTo(start: number, end: number): Replacement;
|
149 | static appendText(start: number, text: string): Replacement;
|
150 | constructor(start: number, length: number, text: string);
|
151 | get end(): number;
|
152 | apply(content: string): string;
|
153 | toJson(): ReplacementJson;
|
154 | }
|
155 | export declare class RuleFailurePosition {
|
156 | private readonly position;
|
157 | private readonly lineAndCharacter;
|
158 | constructor(position: number, lineAndCharacter: ts.LineAndCharacter);
|
159 | getPosition(): number;
|
160 | getLineAndCharacter(): ts.LineAndCharacter;
|
161 | toJson(): IRuleFailurePositionJson;
|
162 | equals(ruleFailurePosition: RuleFailurePosition): boolean;
|
163 | }
|
164 | export declare type Fix = Replacement | Replacement[];
|
165 | export declare type FixJson = ReplacementJson | ReplacementJson[];
|
166 | export declare class RuleFailure {
|
167 | private readonly sourceFile;
|
168 | private readonly failure;
|
169 | private readonly ruleName;
|
170 | private readonly fix?;
|
171 | static compare(a: RuleFailure, b: RuleFailure): number;
|
172 | private readonly fileName;
|
173 | private readonly startPosition;
|
174 | private readonly endPosition;
|
175 | private readonly rawLines;
|
176 | private ruleSeverity;
|
177 | constructor(sourceFile: ts.SourceFile, start: number, end: number, failure: string, ruleName: string, fix?: Replacement | Replacement[] | undefined);
|
178 | getFileName(): string;
|
179 | getRuleName(): string;
|
180 | getStartPosition(): RuleFailurePosition;
|
181 | getEndPosition(): RuleFailurePosition;
|
182 | getFailure(): string;
|
183 | hasFix(): boolean;
|
184 | getFix(): Replacement | Replacement[] | undefined;
|
185 | getRawLines(): string;
|
186 | getRuleSeverity(): RuleSeverity;
|
187 | setRuleSeverity(value: RuleSeverity): void;
|
188 | toJson(): IRuleFailureJson;
|
189 | equals(ruleFailure: RuleFailure): boolean;
|
190 | private createFailurePosition;
|
191 | }
|