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 = [
\r
80 export type RuleEntry = RuleLevel | RuleLevelAndOptions;
\r
81 export type RulesRecord = Partial<Record<string, RuleEntry>>;
\r
82 interface BaseConfig {
\r
85 * The environment settings.
\r
88 [name: string]: boolean;
\r
91 * The path to other config files or the package name of shareable configs.
\r
93 extends?: string | string[];
\r
95 * The global variable settings.
\r
98 [name: string]: boolean;
\r
101 * The flag that disables directive comments.
\r
103 noInlineConfig?: boolean;
\r
105 * The override settings per kind of files.
\r
107 overrides?: ConfigOverride[];
\r
109 * The path to a parser or the package name of a parser.
\r
113 * The parser options.
\r
115 parserOptions?: ParserOptions;
\r
117 * The plugin specifiers.
\r
119 plugins?: string[];
\r
121 * The processor specifier.
\r
123 processor?: string;
\r
125 * The flag to report unused `eslint-disable` comments.
\r
127 reportUnusedDisableDirectives?: boolean;
\r
129 * The rule settings.
\r
131 rules?: RulesRecord;
\r
133 * The shared settings.
\r
136 [name: string]: unknown;
\r
139 export interface ConfigOverride extends BaseConfig {
\r
140 excludedFiles?: string | string[];
\r
141 files: string | string[];
\r
143 export interface Config extends BaseConfig {
\r
145 * The glob patterns that ignore to lint.
\r
147 ignorePatterns?: string | string[];
\r
153 export type ParserOptions = TSParserOptions;
\r
154 export interface VerifyOptions {
\r
156 * Allow/disallow inline comments' ability to change config once it is set. Defaults to true if not supplied.
\r
157 * Useful if you want to validate JS without comments overriding rules.
\r
159 allowInlineConfig?: boolean;
\r
161 * if `true` then the linter doesn't make `fix` properties into the lint result.
\r
163 disableFixes?: boolean;
\r
165 * the filename of the source code.
\r
169 * the predicate function that selects adopt code blocks.
\r
171 filterCodeBlock?: (filename: string, text: string) => boolean;
\r
173 * postprocessor for report messages.
\r
174 * If provided, this should accept an array of the message lists
\r
175 * for each code block returned from the preprocessor, apply a mapping to
\r
176 * the messages as appropriate, and return a one-dimensional array of
\r
179 postprocess?: Processor['postprocess'];
\r
181 * preprocessor for source text.
\r
182 * If provided, this should accept a string of source text, and return an array of code blocks to lint.
\r
184 preprocess?: Processor['preprocess'];
\r
186 * Adds reported errors for unused `eslint-disable` directives.
\r
188 reportUnusedDisableDirectives?: boolean | SeverityString;
\r
190 export interface FixOptions extends VerifyOptions {
\r
192 * Determines whether fixes should be applied.
\r
196 export interface LintSuggestion {
\r
199 messageId?: string;
\r
201 export interface LintMessage {
\r
203 * The 1-based column number.
\r
207 * The 1-based column number of the end location.
\r
209 endColumn?: number;
\r
211 * The 1-based line number of the end location.
\r
215 * If `true` then this is a fatal error.
\r
219 * Information for autofix.
\r
223 * The 1-based line number.
\r
227 * The error message.
\r
230 messageId?: string;
\r
233 * The ID of the rule which makes this message.
\r
235 ruleId: string | null;
\r
237 * The severity of this message.
\r
239 severity: Severity;
\r
240 source: string | null;
\r
242 * Information for suggestions
\r
244 suggestions?: LintSuggestion[];
\r
246 export interface FixReport {
\r
248 * True, if the code was fixed
\r
252 * Fixed code text (might be the same as input if no fixes were applied).
\r
256 * Collection of all messages for the given code
\r
258 messages: LintMessage[];
\r
260 export type ParserModule = {
\r
261 parse(text: string, options?: ParserOptions): TSESTree.Program;
\r
263 parseForESLint(text: string, options?: ParserOptions): ESLintParseResult;
\r
265 export interface ESLintParseResult {
\r
266 ast: TSESTree.Program;
\r
267 parserServices?: ParserServices;
\r
268 scopeManager?: Scope.ScopeManager;
\r
269 visitorKeys?: SourceCode.VisitorKeys;
\r
271 export interface Processor {
\r
273 * The function to extract code blocks.
\r
275 preprocess?: (text: string, filename: string) => Array<string | {
\r
280 * The function to merge messages.
\r
282 postprocess?: (messagesList: Linter.LintMessage[][], filename: string) => Linter.LintMessage[];
\r
284 * If `true` then it means the processor supports autofix.
\r
286 supportsAutofix?: boolean;
\r
288 export interface Environment {
\r
290 * The definition of global variables.
\r
292 globals?: Record<string, Linter.Config>;
\r
294 * The parser options that will be enabled under this environment.
\r
296 parserOptions?: ParserOptions;
\r
298 export interface Plugin {
\r
300 * The definition of plugin configs.
\r
302 configs?: Record<string, Linter.Config>;
\r
304 * The definition of plugin environments.
\r
306 environments?: Record<string, Environment>;
\r
308 * The definition of plugin processors.
\r
310 processors?: Record<string, Processor>;
\r
312 * The definition of plugin rules.
\r
314 rules?: Record<string, RuleCreateFunction | RuleModule<string, unknown[]>>;
\r
318 declare const Linter_base: typeof LinterBase;
\r
320 * The Linter object does the actual evaluation of the JavaScript code. It doesn't do any filesystem operations, it
\r
321 * simply parses and reports on the code. In particular, the Linter object does not process configuration objects
\r
324 declare class Linter extends Linter_base {
\r
327 //# sourceMappingURL=Linter.d.ts.map
\r