3 * Copyright 2013 Palantir Technologies, Inc.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 import * as ts from "typescript";
18 import { IWalker } from "../walker";
19 export interface RuleConstructor {
20 metadata: IRuleMetadata;
21 new (options: IOptions): IRule;
23 export interface IRuleMetadata {
25 * The kebab-case name of the rule.
29 * The type of the rule - its overall purpose
33 * A rule deprecation message, if applicable.
35 deprecationMessage?: string;
37 * A short, one line description of what the rule does.
41 * More elaborate details about the rule.
43 descriptionDetails?: string;
45 * Whether or not the rule will provide fix suggestions.
49 * An explanation of the available options for the rule.
51 optionsDescription: string;
53 * Schema of the options the rule accepts.
54 * The first boolean for whether the rule is enabled or not is already implied.
55 * This field describes the options after that boolean.
56 * If null, this rule has no options and is not configurable.
60 * Examples of what a standard config for the rule might look like.
61 * Using a string[] here is deprecated. Write the options as a JSON object instead.
63 optionExamples?: Array<true | any[]> | string[] | Array<{
67 * An explanation of why the rule is useful.
71 * Whether or not the rule requires type info to run.
73 requiresTypeInfo?: boolean;
75 * Whether or not the rule use for TypeScript only. If `false`, this rule may be used with .js files.
77 typescriptOnly: boolean;
79 * Examples demonstrating what the lint rule will pass and fail
81 codeExamples?: ICodeExample[];
83 export declare type RuleType = "functionality" | "maintainability" | "style" | "typescript" | "formatting";
84 export declare type RuleSeverity = "warning" | "error" | "off";
85 export interface ICodeExample {
91 export interface IOptions {
93 ruleSeverity: RuleSeverity;
97 * Tslint now handles disables itself.
100 disabledIntervals: IDisabledInterval[];
104 * These are now handled internally.
106 export interface IDisabledInterval {
107 startPosition: number;
110 export interface IRule {
111 getOptions(): IOptions;
112 isEnabled(): boolean;
113 apply(sourceFile: ts.SourceFile): RuleFailure[];
114 applyWithWalker(walker: IWalker): RuleFailure[];
116 export interface ITypedRule extends IRule {
117 applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): RuleFailure[];
119 export interface IRuleFailureJson {
120 endPosition: IRuleFailurePositionJson;
124 ruleSeverity: string;
126 startPosition: IRuleFailurePositionJson;
128 export interface IRuleFailurePositionJson {
133 export declare function isTypedRule(rule: IRule): rule is ITypedRule;
134 export interface ReplacementJson {
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 readonly end: number;
152 apply(content: string): string;
153 toJson(): ReplacementJson;
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;
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;
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;