.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / tslint / lib / language / rule / rule.d.ts
1 /**
2  * @license
3  * Copyright 2013 Palantir Technologies, Inc.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
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      * The kebab-case name of the rule.
26      */
27     ruleName: string;
28     /**
29      * The type of the rule - its overall purpose
30      */
31     type: RuleType;
32     /**
33      * A rule deprecation message, if applicable.
34      */
35     deprecationMessage?: string;
36     /**
37      * A short, one line description of what the rule does.
38      */
39     description: string;
40     /**
41      * More elaborate details about the rule.
42      */
43     descriptionDetails?: string;
44     /**
45      * Whether or not the rule will provide fix suggestions.
46      */
47     hasFix?: boolean;
48     /**
49      * An explanation of the available options for the rule.
50      */
51     optionsDescription: string;
52     /**
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.
57      */
58     options: any;
59     /**
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.
62      */
63     optionExamples?: Array<true | any[]> | string[] | Array<{
64         options: any;
65     }>;
66     /**
67      * An explanation of why the rule is useful.
68      */
69     rationale?: string;
70     /**
71      * Whether or not the rule requires type info to run.
72      */
73     requiresTypeInfo?: boolean;
74     /**
75      * Whether or not the rule use for TypeScript only. If `false`, this rule may be used with .js files.
76      */
77     typescriptOnly: boolean;
78     /**
79      * Examples demonstrating what the lint rule will pass and fail
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      * @deprecated
97      * Tslint now handles disables itself.
98      * This will be empty.
99      */
100     disabledIntervals: IDisabledInterval[];
101 }
102 /**
103  * @deprecated
104  * These are now handled internally.
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     readonly 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 }