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