1 | import { TSESTree, ParserServices } from '../ts-estree';
|
2 | import { ParserOptions as TSParserOptions } from './ParserOptions';
|
3 | import { RuleCreateFunction, RuleFix, RuleModule } from './Rule';
|
4 | import { Scope } from './Scope';
|
5 | import { SourceCode } from './SourceCode';
|
6 | declare class LinterBase {
|
7 | |
8 |
|
9 |
|
10 |
|
11 | constructor(config?: Linter.LinterOptions);
|
12 | /**
|
13 | * Define a new parser module
|
14 | * @param parserId Name of the parser
|
15 | * @param parserModule The parser object
|
16 | */
|
17 | defineParser(parserId: string, parserModule: Linter.ParserModule): void;
|
18 | /**
|
19 | * Defines a new linting rule.
|
20 | * @param ruleId A unique rule identifier
|
21 | * @param ruleModule Function from context to object mapping AST node types to event handlers
|
22 | */
|
23 | defineRule<TMessageIds extends string, TOptions extends readonly unknown[]>(ruleId: string, ruleModule: RuleModule<TMessageIds, TOptions> | RuleCreateFunction): void;
|
24 | /**
|
25 | * Defines many new linting rules.
|
26 | * @param rulesToDefine map from unique rule identifier to rule
|
27 | */
|
28 | defineRules<TMessageIds extends string, TOptions extends readonly unknown[]>(rulesToDefine: Record<string, RuleModule<TMessageIds, TOptions> | RuleCreateFunction>): void;
|
29 | /**
|
30 | * Gets an object with all loaded rules.
|
31 | * @returns All loaded rules
|
32 | */
|
33 | getRules(): Map<string, RuleModule<string, unknown[]>>;
|
34 | /**
|
35 | * Gets the `SourceCode` object representing the parsed source.
|
36 | * @returns The `SourceCode` object.
|
37 | */
|
38 | getSourceCode(): SourceCode;
|
39 | /**
|
40 | * Verifies the text against the rules specified by the second argument.
|
41 | * @param textOrSourceCode The text to parse or a SourceCode object.
|
42 | * @param config An ESLintConfig instance to configure everything.
|
43 | * @param filenameOrOptions The optional filename of the file being checked.
|
44 | * If this is not set, the filename will default to '<input>' in the rule context.
|
45 | * If this is an object, then it has "filename", "allowInlineConfig", and some properties.
|
46 | * @returns The results as an array of messages or an empty array if no messages.
|
47 | */
|
48 | verify(textOrSourceCode: SourceCode | string, config: Linter.Config, filenameOrOptions?: string | Linter.VerifyOptions): Linter.LintMessage[];
|
49 | /**
|
50 | * Performs multiple autofix passes over the text until as many fixes as possible have been applied.
|
51 | * @param text The source text to apply fixes to.
|
52 | * @param config The ESLint config object to use.
|
53 | * @param options The ESLint options object to use.
|
54 | * @returns The result of the fix operation as returned from the SourceCodeFixer.
|
55 | */
|
56 | verifyAndFix(code: string, config: Linter.Config, options: Linter.FixOptions): Linter.FixReport;
|
57 | /**
|
58 | * The version from package.json.
|
59 | */
|
60 | readonly version: string;
|
61 | /**
|
62 | * The version from package.json.
|
63 | */
|
64 | static readonly version: string;
|
65 | }
|
66 | declare namespace Linter {
|
67 | export interface LinterOptions {
|
68 | |
69 |
|
70 |
|
71 | cwd?: string;
|
72 | }
|
73 | export type Severity = 0 | 1 | 2;
|
74 | export type SeverityString = 'off' | 'warn' | 'error';
|
75 | export type RuleLevel = Severity | SeverityString;
|
76 | export type RuleLevelAndOptions = [RuleLevel, ...unknown[]];
|
77 | export type RuleEntry = RuleLevel | RuleLevelAndOptions;
|
78 | export type RulesRecord = Partial<Record<string, RuleEntry>>;
|
79 | interface BaseConfig {
|
80 | $schema?: string;
|
81 | |
82 |
|
83 |
|
84 | env?: {
|
85 | [name: string]: boolean;
|
86 | };
|
87 | |
88 |
|
89 |
|
90 | extends?: string | string[];
|
91 | |
92 |
|
93 |
|
94 | globals?: {
|
95 | [name: string]: boolean;
|
96 | };
|
97 | |
98 |
|
99 |
|
100 | noInlineConfig?: boolean;
|
101 | |
102 |
|
103 |
|
104 | overrides?: ConfigOverride[];
|
105 | |
106 |
|
107 |
|
108 | parser?: string;
|
109 | |
110 |
|
111 |
|
112 | parserOptions?: ParserOptions;
|
113 | |
114 |
|
115 |
|
116 | plugins?: string[];
|
117 | |
118 |
|
119 |
|
120 | processor?: string;
|
121 | |
122 |
|
123 |
|
124 | reportUnusedDisableDirectives?: boolean;
|
125 | |
126 |
|
127 |
|
128 | rules?: RulesRecord;
|
129 | |
130 |
|
131 |
|
132 | settings?: {
|
133 | [name: string]: unknown;
|
134 | };
|
135 | }
|
136 | export interface ConfigOverride extends BaseConfig {
|
137 | excludedFiles?: string | string[];
|
138 | files: string | string[];
|
139 | }
|
140 | export interface Config extends BaseConfig {
|
141 | |
142 |
|
143 |
|
144 | ignorePatterns?: string | string[];
|
145 | |
146 |
|
147 |
|
148 | root?: boolean;
|
149 | }
|
150 | export type ParserOptions = TSParserOptions;
|
151 | export interface VerifyOptions {
|
152 | |
153 |
|
154 |
|
155 |
|
156 | allowInlineConfig?: boolean;
|
157 | |
158 |
|
159 |
|
160 | disableFixes?: boolean;
|
161 | |
162 |
|
163 |
|
164 | filename?: string;
|
165 | |
166 |
|
167 |
|
168 | filterCodeBlock?: (filename: string, text: string) => boolean;
|
169 | |
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 | postprocess?: Processor['postprocess'];
|
177 | |
178 |
|
179 |
|
180 |
|
181 | preprocess?: Processor['preprocess'];
|
182 | |
183 |
|
184 |
|
185 | reportUnusedDisableDirectives?: boolean | SeverityString;
|
186 | }
|
187 | export interface FixOptions extends VerifyOptions {
|
188 | |
189 |
|
190 |
|
191 | fix?: boolean;
|
192 | }
|
193 | export interface LintSuggestion {
|
194 | desc: string;
|
195 | fix: RuleFix;
|
196 | messageId?: string;
|
197 | }
|
198 | export interface LintMessage {
|
199 | |
200 |
|
201 |
|
202 | column: number;
|
203 | |
204 |
|
205 |
|
206 | endColumn?: number;
|
207 | |
208 |
|
209 |
|
210 | endLine?: number;
|
211 | |
212 |
|
213 |
|
214 | fatal?: true;
|
215 | |
216 |
|
217 |
|
218 | fix?: RuleFix;
|
219 | |
220 |
|
221 |
|
222 | line: number;
|
223 | |
224 |
|
225 |
|
226 | message: string;
|
227 | messageId?: string;
|
228 | nodeType: string;
|
229 | |
230 |
|
231 |
|
232 | ruleId: string | null;
|
233 | |
234 |
|
235 |
|
236 | severity: Severity;
|
237 | source: string | null;
|
238 | |
239 |
|
240 |
|
241 | suggestions?: LintSuggestion[];
|
242 | }
|
243 | export interface FixReport {
|
244 | |
245 |
|
246 |
|
247 | fixed: boolean;
|
248 | |
249 |
|
250 |
|
251 | output: string;
|
252 | |
253 |
|
254 |
|
255 | messages: LintMessage[];
|
256 | }
|
257 | export type ParserModule = {
|
258 | parse(text: string, options?: ParserOptions): TSESTree.Program;
|
259 | } | {
|
260 | parseForESLint(text: string, options?: ParserOptions): ESLintParseResult;
|
261 | };
|
262 | export interface ESLintParseResult {
|
263 | ast: TSESTree.Program;
|
264 | parserServices?: ParserServices;
|
265 | scopeManager?: Scope.ScopeManager;
|
266 | visitorKeys?: SourceCode.VisitorKeys;
|
267 | }
|
268 | export interface Processor {
|
269 | |
270 |
|
271 |
|
272 | preprocess?: (text: string, filename: string) => Array<string | {
|
273 | text: string;
|
274 | filename: string;
|
275 | }>;
|
276 | |
277 |
|
278 |
|
279 | postprocess?: (messagesList: Linter.LintMessage[][], filename: string) => Linter.LintMessage[];
|
280 | |
281 |
|
282 |
|
283 | supportsAutofix?: boolean;
|
284 | }
|
285 | export interface Environment {
|
286 | |
287 |
|
288 |
|
289 | globals?: Record<string, Linter.Config>;
|
290 | |
291 |
|
292 |
|
293 | parserOptions?: ParserOptions;
|
294 | }
|
295 | export interface Plugin {
|
296 | |
297 |
|
298 |
|
299 | configs?: Record<string, Linter.Config>;
|
300 | |
301 |
|
302 |
|
303 | environments?: Record<string, Environment>;
|
304 | |
305 |
|
306 |
|
307 | processors?: Record<string, Processor>;
|
308 | |
309 |
|
310 |
|
311 | rules?: Record<string, RuleCreateFunction | RuleModule<string, unknown[]>>;
|
312 | }
|
313 | export {};
|
314 | }
|
315 | declare const Linter_base: typeof LinterBase;
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 | declare class Linter extends Linter_base {
|
322 | }
|
323 | export { Linter };
|
324 |
|
\ | No newline at end of file |