1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
/**
* @license
* Copyright 2013 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as ts from "typescript";
import { IWalker } from "../walker";
export interface RuleConstructor {
metadata: IRuleMetadata;
new (options: IOptions): IRule;
}
export interface IRuleMetadata {
/**
* The kebab-case name of the rule.
*/
ruleName: string;
/**
* The type of the rule - its overall purpose
*/
type: RuleType;
/**
* A rule deprecation message, if applicable.
*/
deprecationMessage?: string;
/**
* A short, one line description of what the rule does.
*/
description: string;
/**
* More elaborate details about the rule.
*/
descriptionDetails?: string;
/**
* Whether or not the rule will provide fix suggestions.
*/
hasFix?: boolean;
/**
* An explanation of the available options for the rule.
*/
optionsDescription: string;
/**
* Schema of the options the rule accepts.
* The first boolean for whether the rule is enabled or not is already implied.
* This field describes the options after that boolean.
* If null, this rule has no options and is not configurable.
*/
options: any;
/**
* Examples of what a standard config for the rule might look like.
* Using a string[] here is deprecated. Write the options as a JSON object instead.
*/
optionExamples?: Array<true | any[]> | string[];
/**
* An explanation of why the rule is useful.
*/
rationale?: string;
/**
* Whether or not the rule requires type info to run.
*/
requiresTypeInfo?: boolean;
/**
* Whether or not the rule use for TypeScript only. If `false`, this rule may be used with .js files.
*/
typescriptOnly: boolean;
}
export declare type RuleType = "functionality" | "maintainability" | "style" | "typescript";
export declare type RuleSeverity = "warning" | "error" | "off";
export interface IOptions {
ruleArguments: any[];
ruleSeverity: RuleSeverity;
ruleName: string;
/**
* @deprecated
* Tslint now handles disables itself.
* This will be empty.
*/
disabledIntervals: IDisabledInterval[];
}
/**
* @deprecated
* These are now handled internally.
*/
export interface IDisabledInterval {
startPosition: number;
endPosition: number;
}
export interface IRule {
getOptions(): IOptions;
isEnabled(): boolean;
apply(sourceFile: ts.SourceFile): RuleFailure[];
applyWithWalker(walker: IWalker): RuleFailure[];
}
export interface ITypedRule extends IRule {
applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): RuleFailure[];
}
export interface IRuleFailureJson {
endPosition: IRuleFailurePositionJson;
failure: string;
fix?: FixJson;
name: string;
ruleSeverity: string;
ruleName: string;
startPosition: IRuleFailurePositionJson;
}
export interface IRuleFailurePositionJson {
character: number;
line: number;
position: number;
}
export declare function isTypedRule(rule: IRule): rule is ITypedRule;
export interface ReplacementJson {
innerStart: number;
innerLength: number;
innerText: string;
}
export declare class Replacement {
readonly start: number;
readonly length: number;
readonly text: string;
static applyFixes(content: string, fixes: Fix[]): string;
static applyAll(content: string, replacements: Replacement[]): string;
static replaceNode(node: ts.Node, text: string, sourceFile?: ts.SourceFile): Replacement;
static replaceFromTo(start: number, end: number, text: string): Replacement;
static deleteText(start: number, length: number): Replacement;
static deleteFromTo(start: number, end: number): Replacement;
static appendText(start: number, text: string): Replacement;
constructor(start: number, length: number, text: string);
readonly end: number;
apply(content: string): string;
toJson(): ReplacementJson;
}
export declare class RuleFailurePosition {
private position;
private lineAndCharacter;
constructor(position: number, lineAndCharacter: ts.LineAndCharacter);
getPosition(): number;
getLineAndCharacter(): ts.LineAndCharacter;
toJson(): IRuleFailurePositionJson;
equals(ruleFailurePosition: RuleFailurePosition): boolean;
}
export declare type Fix = Replacement | Replacement[];
export declare type FixJson = ReplacementJson | ReplacementJson[];
export declare class RuleFailure {
private sourceFile;
private failure;
private ruleName;
private fix;
private fileName;
private startPosition;
private endPosition;
private rawLines;
private ruleSeverity;
constructor(sourceFile: ts.SourceFile, start: number, end: number, failure: string, ruleName: string, fix?: Fix);
getFileName(): string;
getRuleName(): string;
getStartPosition(): RuleFailurePosition;
getEndPosition(): RuleFailurePosition;
getFailure(): string;
hasFix(): boolean;
getFix(): Replacement | Replacement[] | undefined;
getRawLines(): string;
getRuleSeverity(): RuleSeverity;
setRuleSeverity(value: RuleSeverity): void;
toJson(): IRuleFailureJson;
equals(ruleFailure: RuleFailure): boolean;
private createFailurePosition(position);
}
|