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