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 {
8 * Initialize the Linter.
9 * @param config the config object
11 constructor(config?: Linter.LinterOptions);
13 * Define a new parser module
14 * @param parserId Name of the parser
15 * @param parserModule The parser object
17 defineParser(parserId: string, parserModule: Linter.ParserModule): void;
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
23 defineRule<TMessageIds extends string, TOptions extends readonly unknown[]>(ruleId: string, ruleModule: RuleModule<TMessageIds, TOptions> | RuleCreateFunction): void;
25 * Defines many new linting rules.
26 * @param rulesToDefine map from unique rule identifier to rule
28 defineRules<TMessageIds extends string, TOptions extends readonly unknown[]>(rulesToDefine: Record<string, RuleModule<TMessageIds, TOptions> | RuleCreateFunction>): void;
30 * Gets an object with all loaded rules.
31 * @returns All loaded rules
33 getRules(): Map<string, RuleModule<string, unknown[]>>;
35 * Gets the `SourceCode` object representing the parsed source.
36 * @returns The `SourceCode` object.
38 getSourceCode(): SourceCode;
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.
48 verify(textOrSourceCode: SourceCode | string, config: Linter.Config, filenameOrOptions?: string | Linter.VerifyOptions): Linter.LintMessage[];
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.
56 verifyAndFix(code: string, config: Linter.Config, options: Linter.FixOptions): Linter.FixReport;
58 * The version from package.json.
60 readonly version: string;
62 * The version from package.json.
64 static readonly version: string;
66 declare namespace Linter {
67 export interface LinterOptions {
69 * path to a directory that should be considered as the current working directory.
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 {
82 * The environment settings.
85 [name: string]: boolean;
88 * The path to other config files or the package name of shareable configs.
90 extends?: string | string[];
92 * The global variable settings.
95 [name: string]: boolean;
98 * The flag that disables directive comments.
100 noInlineConfig?: boolean;
102 * The override settings per kind of files.
104 overrides?: ConfigOverride[];
106 * The path to a parser or the package name of a parser.
110 * The parser options.
112 parserOptions?: ParserOptions;
114 * The plugin specifiers.
118 * The processor specifier.
122 * The flag to report unused `eslint-disable` comments.
124 reportUnusedDisableDirectives?: boolean;
130 * The shared settings.
133 [name: string]: unknown;
136 export interface ConfigOverride extends BaseConfig {
137 excludedFiles?: string | string[];
138 files: string | string[];
140 export interface Config extends BaseConfig {
142 * The glob patterns that ignore to lint.
144 ignorePatterns?: string | string[];
150 export type ParserOptions = TSParserOptions;
151 export interface VerifyOptions {
153 * Allow/disallow inline comments' ability to change config once it is set. Defaults to true if not supplied.
154 * Useful if you want to validate JS without comments overriding rules.
156 allowInlineConfig?: boolean;
158 * if `true` then the linter doesn't make `fix` properties into the lint result.
160 disableFixes?: boolean;
162 * the filename of the source code.
166 * the predicate function that selects adopt code blocks.
168 filterCodeBlock?: (filename: string, text: string) => boolean;
170 * postprocessor for report messages.
171 * If provided, this should accept an array of the message lists
172 * for each code block returned from the preprocessor, apply a mapping to
173 * the messages as appropriate, and return a one-dimensional array of
176 postprocess?: Processor['postprocess'];
178 * preprocessor for source text.
179 * If provided, this should accept a string of source text, and return an array of code blocks to lint.
181 preprocess?: Processor['preprocess'];
183 * Adds reported errors for unused `eslint-disable` directives.
185 reportUnusedDisableDirectives?: boolean | SeverityString;
187 export interface FixOptions extends VerifyOptions {
189 * Determines whether fixes should be applied.
193 export interface LintSuggestion {
198 export interface LintMessage {
200 * The 1-based column number.
204 * The 1-based column number of the end location.
208 * The 1-based line number of the end location.
212 * If `true` then this is a fatal error.
216 * Information for autofix.
220 * The 1-based line number.
230 * The ID of the rule which makes this message.
232 ruleId: string | null;
234 * The severity of this message.
237 source: string | null;
239 * Information for suggestions
241 suggestions?: LintSuggestion[];
243 export interface FixReport {
245 * True, if the code was fixed
249 * Fixed code text (might be the same as input if no fixes were applied).
253 * Collection of all messages for the given code
255 messages: LintMessage[];
257 export type ParserModule = {
258 parse(text: string, options?: ParserOptions): TSESTree.Program;
260 parseForESLint(text: string, options?: ParserOptions): ESLintParseResult;
262 export interface ESLintParseResult {
263 ast: TSESTree.Program;
264 parserServices?: ParserServices;
265 scopeManager?: Scope.ScopeManager;
266 visitorKeys?: SourceCode.VisitorKeys;
268 export interface Processor {
270 * The function to extract code blocks.
272 preprocess?: (text: string, filename: string) => Array<string | {
277 * The function to merge messages.
279 postprocess?: (messagesList: Linter.LintMessage[][], filename: string) => Linter.LintMessage[];
281 * If `true` then it means the processor supports autofix.
283 supportsAutofix?: boolean;
285 export interface Environment {
287 * The definition of global variables.
289 globals?: Record<string, Linter.Config>;
291 * The parser options that will be enabled under this environment.
293 parserOptions?: ParserOptions;
295 export interface Plugin {
297 * The definition of plugin configs.
299 configs?: Record<string, Linter.Config>;
301 * The definition of plugin environments.
303 environments?: Record<string, Environment>;
305 * The definition of plugin processors.
307 processors?: Record<string, Processor>;
309 * The definition of plugin rules.
311 rules?: Record<string, RuleCreateFunction | RuleModule<string, unknown[]>>;
315 declare const Linter_base: typeof LinterBase;
317 * The Linter object does the actual evaluation of the JavaScript code. It doesn't do any filesystem operations, it
318 * simply parses and reports on the code. In particular, the Linter object does not process configuration objects
321 declare class Linter extends Linter_base {
324 //# sourceMappingURL=Linter.d.ts.map