1 import { Linter } from './Linter';
2 declare class ESLintBase {
4 * Creates a new instance of the main ESLint API.
5 * @param options The options for this instance.
7 constructor(options?: ESLint.ESLintOptions);
9 * This method calculates the configuration for a given file, which can be useful for debugging purposes.
10 * - It resolves and merges extends and overrides settings into the top level configuration.
11 * - It resolves the parser setting to absolute paths.
12 * - It normalizes the plugins setting to align short names. (e.g., eslint-plugin-foo → foo)
13 * - It adds the processor setting if a legacy file extension processor is matched.
14 * - It doesn't interpret the env setting to the globals and parserOptions settings, so the result object contains
15 * the env setting as is.
16 * @param filePath The path to the file whose configuration you would like to calculate. Directory paths are forbidden
17 * because ESLint cannot handle the overrides setting.
18 * @returns The promise that will be fulfilled with a configuration object.
20 calculateConfigForFile(filePath: string): Promise<Linter.Config>;
22 * This method checks if a given file is ignored by your configuration.
23 * @param filePath The path to the file you want to check.
24 * @returns The promise that will be fulfilled with whether the file is ignored or not. If the file is ignored, then
25 * it will return true.
27 isPathIgnored(filePath: string): Promise<boolean>;
29 * This method lints the files that match the glob patterns and then returns the results.
30 * @param patterns The lint target files. This can contain any of file paths, directory paths, and glob patterns.
31 * @returns The promise that will be fulfilled with an array of LintResult objects.
33 lintFiles(patterns: string | string[]): Promise<ESLint.LintResult[]>;
35 * This method lints the given source code text and then returns the results.
37 * By default, this method uses the configuration that applies to files in the current working directory (the cwd
38 * constructor option). If you want to use a different configuration, pass options.filePath, and ESLint will load the
39 * same configuration that eslint.lintFiles() would use for a file at options.filePath.
41 * If the options.filePath value is configured to be ignored, this method returns an empty array. If the
42 * options.warnIgnored option is set along with the options.filePath option, this method returns a LintResult object.
43 * In that case, the result may contain a warning that indicates the file was ignored.
44 * @param code The source code text to check.
45 * @param options The options.
46 * @returns The promise that will be fulfilled with an array of LintResult objects. This is an array (despite there
47 * being only one lint result) in order to keep the interfaces between this and the eslint.lintFiles()
50 lintText(code: string, options?: ESLint.LintTextOptions): Promise<ESLint.LintResult[]>;
52 * This method loads a formatter. Formatters convert lint results to a human- or machine-readable string.
53 * @param name TThe path to the file you want to check.
54 * The following values are allowed:
55 * - undefined. In this case, loads the "stylish" built-in formatter.
56 * - A name of built-in formatters.
57 * - A name of third-party formatters. For examples:
58 * -- `foo` will load eslint-formatter-foo.
59 * -- `@foo` will load `@foo/eslint-formatter`.
60 * -- `@foo/bar` will load `@foo/eslint-formatter-bar`.
61 * - A path to the file that defines a formatter. The path must contain one or more path separators (/) in order to distinguish if it's a path or not. For example, start with ./.
62 * @returns The promise that will be fulfilled with a Formatter object.
64 loadFormatter(name?: string): Promise<ESLint.Formatter>;
66 * This method copies the given results and removes warnings. The returned value contains only errors.
67 * @param results The LintResult objects to filter.
68 * @returns The filtered LintResult objects.
70 static getErrorResults(results: ESLint.LintResult): ESLint.LintResult;
72 * This method writes code modified by ESLint's autofix feature into its respective file. If any of the modified
73 * files don't exist, this method does nothing.
74 * @param results The LintResult objects to write.
75 * @returns The promise that will be fulfilled after all files are written.
77 static outputFixes(results: ESLint.LintResult): Promise<void>;
81 static readonly version: string;
83 declare namespace ESLint {
84 interface ESLintOptions {
86 * If false is present, ESLint suppresses directive comments in source code.
87 * If this option is false, it overrides the noInlineConfig setting in your configurations.
89 allowInlineConfig?: boolean;
91 * Configuration object, extended by all configurations used with this instance.
92 * You can use this option to define the default settings that will be used if your configuration files don't
95 baseConfig?: Linter.Config | null;
97 * If true is present, the eslint.lintFiles() method caches lint results and uses it if each target file is not
98 * changed. Please mind that ESLint doesn't clear the cache when you upgrade ESLint plugins. In that case, you have
99 * to remove the cache file manually. The eslint.lintText() method doesn't use caches even if you pass the
100 * options.filePath to the method.
104 * The eslint.lintFiles() method writes caches into this file.
106 cacheLocation?: string;
108 * The working directory. This must be an absolute path.
112 * Unless set to false, the eslint.lintFiles() method will throw an error when no target files are found.
114 errorOnUnmatchedPattern?: boolean;
116 * If you pass directory paths to the eslint.lintFiles() method, ESLint checks the files in those directories that
117 * have the given extensions. For example, when passing the src/ directory and extensions is [".js", ".ts"], ESLint
118 * will lint *.js and *.ts files in src/. If extensions is null, ESLint checks *.js files and files that match
119 * overrides[].files patterns in your configuration.
120 * Note: This option only applies when you pass directory paths to the eslint.lintFiles() method.
121 * If you pass glob patterns, ESLint will lint all files matching the glob pattern regardless of extension.
123 extensions?: string[] | null;
125 * If true is present, the eslint.lintFiles() and eslint.lintText() methods work in autofix mode.
126 * If a predicate function is present, the methods pass each lint message to the function, then use only the
127 * lint messages for which the function returned true.
129 fix?: boolean | ((message: LintMessage) => boolean);
131 * The types of the rules that the eslint.lintFiles() and eslint.lintText() methods use for autofix.
135 * If false is present, the eslint.lintFiles() method doesn't interpret glob patterns.
137 globInputPaths?: boolean;
139 * If false is present, the eslint.lintFiles() method doesn't respect `.eslintignore` files or ignorePatterns in
140 * your configuration.
144 * The path to a file ESLint uses instead of `$CWD/.eslintignore`.
145 * If a path is present and the file doesn't exist, this constructor will throw an error.
149 * Configuration object, overrides all configurations used with this instance.
150 * You can use this option to define the settings that will be used even if your configuration files configure it.
152 overrideConfig?: Linter.ConfigOverride | null;
154 * The path to a configuration file, overrides all configurations used with this instance.
155 * The options.overrideConfig option is applied after this option is applied.
157 overrideConfigFile?: string | null;
159 * The plugin implementations that ESLint uses for the plugins setting of your configuration.
160 * This is a map-like object. Those keys are plugin IDs and each value is implementation.
162 plugins?: Record<string, Linter.Plugin> | null;
164 * The severity to report unused eslint-disable directives.
165 * If this option is a severity, it overrides the reportUnusedDisableDirectives setting in your configurations.
167 reportUnusedDisableDirectives?: Linter.SeverityString | null;
169 * The path to a directory where plugins should be resolved from.
170 * If null is present, ESLint loads plugins from the location of the configuration file that contains the plugin
172 * If a path is present, ESLint loads all plugins from there.
174 resolvePluginsRelativeTo?: string | null;
176 * An array of paths to directories to load custom rules from.
178 rulePaths?: string[];
180 * If false is present, ESLint doesn't load configuration files (.eslintrc.* files).
181 * Only the configuration of the constructor options is valid.
183 useEslintrc?: boolean;
185 interface DeprecatedRuleInfo {
191 * The rule IDs that replace this deprecated rule.
193 replacedBy: string[];
196 * The LintResult value is the information of the linting result of each file.
198 interface LintResult {
200 * The number of errors. This includes fixable errors.
204 * The absolute path to the file of this result. This is the string "<text>" if the file path is unknown (when you
205 * didn't pass the options.filePath option to the eslint.lintText() method).
209 * The number of errors that can be fixed automatically by the fix constructor option.
211 fixableErrorCount: number;
213 * The number of warnings that can be fixed automatically by the fix constructor option.
215 fixableWarningCount: number;
217 * The array of LintMessage objects.
219 messages: Linter.LintMessage[];
221 * The source code of the file that was linted, with as many fixes applied as possible.
225 * The original source code text. This property is undefined if any messages didn't exist or the output
230 * The information about the deprecated rules that were used to check this file.
232 usedDeprecatedRules: DeprecatedRuleInfo[];
234 * The number of warnings. This includes fixable warnings.
236 warningCount: number;
238 interface LintTextOptions {
240 * The path to the file of the source code text. If omitted, the result.filePath becomes the string "<text>".
244 * If true is present and the options.filePath is a file ESLint should ignore, this method returns a lint result
245 * contains a warning message.
247 warnIgnored?: boolean;
250 * The LintMessage value is the information of each linting error.
252 interface LintMessage {
254 * The 1-based column number of the begin point of this message.
258 * The 1-based column number of the end point of this message. This property is undefined if this message
261 endColumn: number | undefined;
263 * The 1-based line number of the end point of this message. This property is undefined if this
264 * message is not a range.
266 endLine: number | undefined;
268 * The EditInfo object of autofix. This property is undefined if this message is not fixable.
270 fix: EditInfo | undefined;
272 * The 1-based line number of the begin point of this message.
280 * The rule name that generates this lint message. If this message is generated by the ESLint core rather than
281 * rules, this is null.
283 ruleId: string | null;
285 * The severity of this message. 1 means warning and 2 means error.
289 * The list of suggestions. Each suggestion is the pair of a description and an EditInfo object to fix code. API
290 * users such as editor integrations can choose one of them to fix the problem of this message. This property is
291 * undefined if this message doesn't have any suggestions.
299 * The EditInfo value is information to edit text.
301 * This edit information means replacing the range of the range property by the text property value. It's like
302 * sourceCodeText.slice(0, edit.range[0]) + edit.text + sourceCodeText.slice(edit.range[1]). Therefore, it's an add
303 * if the range[0] and range[1] property values are the same value, and it's removal if the text property value is
308 * The pair of 0-based indices in source code text to remove.
310 range: [number, number];
317 * The Formatter value is the object to convert the LintResult objects to text.
319 interface Formatter {
321 * The method to convert the LintResult objects to text
323 format(results: LintResult[]): string;
326 declare const _ESLint: typeof ESLintBase;
328 * The ESLint class is the primary class to use in Node.js applications.
329 * This class depends on the Node.js fs module and the file system, so you cannot use it in browsers.
331 * If you want to lint code on browsers, use the Linter class instead.
335 declare class ESLint extends _ESLint {
338 //# sourceMappingURL=ESLint.d.ts.map