1 | import { TSESTree, ParserServices } from '../ts-estree';
|
2 | import { ParserOptions as TSParserOptions } from './ParserOptions';
|
3 | import { RuleCreateFunction, RuleFix, RuleModule, SharedConfigurationSettings } 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 | export type GlobalVariableOption = 'readonly' | 'writable' | 'off' | boolean;
|
80 | interface BaseConfig {
|
81 | $schema?: string;
|
82 | |
83 |
|
84 |
|
85 | env?: {
|
86 | [name: string]: boolean;
|
87 | };
|
88 | |
89 |
|
90 |
|
91 | extends?: string | string[];
|
92 | |
93 |
|
94 |
|
95 | globals?: {
|
96 | [name: string]: GlobalVariableOption;
|
97 | };
|
98 | |
99 |
|
100 |
|
101 | noInlineConfig?: boolean;
|
102 | |
103 |
|
104 |
|
105 | overrides?: ConfigOverride[];
|
106 | |
107 |
|
108 |
|
109 | parser?: string;
|
110 | |
111 |
|
112 |
|
113 | parserOptions?: ParserOptions;
|
114 | |
115 |
|
116 |
|
117 | plugins?: string[];
|
118 | |
119 |
|
120 |
|
121 | processor?: string;
|
122 | |
123 |
|
124 |
|
125 | reportUnusedDisableDirectives?: boolean;
|
126 | |
127 |
|
128 |
|
129 | rules?: RulesRecord;
|
130 | |
131 |
|
132 |
|
133 | settings?: SharedConfigurationSettings;
|
134 | }
|
135 | export interface ConfigOverride extends BaseConfig {
|
136 | excludedFiles?: string | string[];
|
137 | files: string | string[];
|
138 | }
|
139 | export interface Config extends BaseConfig {
|
140 | |
141 |
|
142 |
|
143 | ignorePatterns?: string | string[];
|
144 | |
145 |
|
146 |
|
147 | root?: boolean;
|
148 | }
|
149 | export type ParserOptions = TSParserOptions;
|
150 | export interface VerifyOptions {
|
151 | |
152 |
|
153 |
|
154 |
|
155 | allowInlineConfig?: boolean;
|
156 | |
157 |
|
158 |
|
159 | disableFixes?: boolean;
|
160 | |
161 |
|
162 |
|
163 | filename?: string;
|
164 | |
165 |
|
166 |
|
167 | filterCodeBlock?: (filename: string, text: string) => boolean;
|
168 | |
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 | postprocess?: Processor['postprocess'];
|
176 | |
177 |
|
178 |
|
179 |
|
180 | preprocess?: Processor['preprocess'];
|
181 | |
182 |
|
183 |
|
184 | reportUnusedDisableDirectives?: boolean | SeverityString;
|
185 | }
|
186 | export interface FixOptions extends VerifyOptions {
|
187 | |
188 |
|
189 |
|
190 | fix?: boolean;
|
191 | }
|
192 | export interface LintSuggestion {
|
193 | desc: string;
|
194 | fix: RuleFix;
|
195 | messageId?: string;
|
196 | }
|
197 | export interface LintMessage {
|
198 | |
199 |
|
200 |
|
201 | column: number;
|
202 | |
203 |
|
204 |
|
205 | endColumn?: number;
|
206 | |
207 |
|
208 |
|
209 | endLine?: number;
|
210 | |
211 |
|
212 |
|
213 | fatal?: true;
|
214 | |
215 |
|
216 |
|
217 | fix?: RuleFix;
|
218 | |
219 |
|
220 |
|
221 | line: number;
|
222 | |
223 |
|
224 |
|
225 | message: string;
|
226 | messageId?: string;
|
227 | nodeType: string;
|
228 | |
229 |
|
230 |
|
231 | ruleId: string | null;
|
232 | |
233 |
|
234 |
|
235 | severity: Severity;
|
236 | source: string | null;
|
237 | |
238 |
|
239 |
|
240 | suggestions?: LintSuggestion[];
|
241 | }
|
242 | export interface FixReport {
|
243 | |
244 |
|
245 |
|
246 | fixed: boolean;
|
247 | |
248 |
|
249 |
|
250 | output: string;
|
251 | |
252 |
|
253 |
|
254 | messages: LintMessage[];
|
255 | }
|
256 | export type ParserModule = {
|
257 | parse(text: string, options?: ParserOptions): TSESTree.Program;
|
258 | } | {
|
259 | parseForESLint(text: string, options?: ParserOptions): ESLintParseResult;
|
260 | };
|
261 | export interface ESLintParseResult {
|
262 | ast: TSESTree.Program;
|
263 | parserServices?: ParserServices;
|
264 | scopeManager?: Scope.ScopeManager;
|
265 | visitorKeys?: SourceCode.VisitorKeys;
|
266 | }
|
267 | export interface Processor {
|
268 | |
269 |
|
270 |
|
271 | preprocess?: (text: string, filename: string) => Array<string | {
|
272 | text: string;
|
273 | filename: string;
|
274 | }>;
|
275 | |
276 |
|
277 |
|
278 | postprocess?: (messagesList: Linter.LintMessage[][], filename: string) => Linter.LintMessage[];
|
279 | |
280 |
|
281 |
|
282 | supportsAutofix?: boolean;
|
283 | }
|
284 | export interface Environment {
|
285 | |
286 |
|
287 |
|
288 | globals?: Record<string, Linter.Config>;
|
289 | |
290 |
|
291 |
|
292 | parserOptions?: ParserOptions;
|
293 | }
|
294 | export interface Plugin {
|
295 | |
296 |
|
297 |
|
298 | configs?: Record<string, Linter.Config>;
|
299 | |
300 |
|
301 |
|
302 | environments?: Record<string, Environment>;
|
303 | |
304 |
|
305 |
|
306 | processors?: Record<string, Processor>;
|
307 | |
308 |
|
309 |
|
310 | rules?: Record<string, RuleCreateFunction | RuleModule<string, unknown[]>>;
|
311 | }
|
312 | export {};
|
313 | }
|
314 | declare const Linter_base: typeof LinterBase;
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 | declare class Linter extends Linter_base {
|
321 | }
|
322 | export { Linter };
|
323 |
|
\ | No newline at end of file |