UNPKG

15.3 kBTypeScriptView Raw
1import { Linter } from './Linter';
2declare class ESLintBase {
3 /**
4 * Creates a new instance of the main ESLint API.
5 * @param options The options for this instance.
6 */
7 constructor(options?: ESLint.ESLintOptions);
8 /**
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.
19 */
20 calculateConfigForFile(filePath: string): Promise<Linter.Config>;
21 /**
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.
26 */
27 isPathIgnored(filePath: string): Promise<boolean>;
28 /**
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.
32 */
33 lintFiles(patterns: string | string[]): Promise<ESLint.LintResult[]>;
34 /**
35 * This method lints the given source code text and then returns the results.
36 *
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.
40 *
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()
48 * method similar.
49 */
50 lintText(code: string, options?: ESLint.LintTextOptions): Promise<ESLint.LintResult[]>;
51 /**
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.
63 */
64 loadFormatter(name?: string): Promise<ESLint.Formatter>;
65 /**
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.
69 */
70 static getErrorResults(results: ESLint.LintResult): ESLint.LintResult;
71 /**
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.
76 */
77 static outputFixes(results: ESLint.LintResult): Promise<void>;
78 /**
79 * The version text.
80 */
81 static readonly version: string;
82}
83declare namespace ESLint {
84 interface ESLintOptions {
85 /**
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.
88 */
89 allowInlineConfig?: boolean;
90 /**
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
93 * configure it.
94 */
95 baseConfig?: Linter.Config | null;
96 /**
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.
101 */
102 cache?: boolean;
103 /**
104 * The eslint.lintFiles() method writes caches into this file.
105 */
106 cacheLocation?: string;
107 /**
108 * The working directory. This must be an absolute path.
109 */
110 cwd?: string;
111 /**
112 * Unless set to false, the eslint.lintFiles() method will throw an error when no target files are found.
113 */
114 errorOnUnmatchedPattern?: boolean;
115 /**
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.
122 */
123 extensions?: string[] | null;
124 /**
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.
128 */
129 fix?: boolean | ((message: LintMessage) => boolean);
130 /**
131 * The types of the rules that the eslint.lintFiles() and eslint.lintText() methods use for autofix.
132 */
133 fixTypes?: string[];
134 /**
135 * If false is present, the eslint.lintFiles() method doesn't interpret glob patterns.
136 */
137 globInputPaths?: boolean;
138 /**
139 * If false is present, the eslint.lintFiles() method doesn't respect `.eslintignore` files or ignorePatterns in
140 * your configuration.
141 */
142 ignore?: boolean;
143 /**
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.
146 */
147 ignorePath?: string;
148 /**
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.
151 */
152 overrideConfig?: Linter.ConfigOverride | null;
153 /**
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.
156 */
157 overrideConfigFile?: string | null;
158 /**
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.
161 */
162 plugins?: Record<string, Linter.Plugin> | null;
163 /**
164 * The severity to report unused eslint-disable directives.
165 * If this option is a severity, it overrides the reportUnusedDisableDirectives setting in your configurations.
166 */
167 reportUnusedDisableDirectives?: Linter.SeverityString | null;
168 /**
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
171 * setting.
172 * If a path is present, ESLint loads all plugins from there.
173 */
174 resolvePluginsRelativeTo?: string | null;
175 /**
176 * An array of paths to directories to load custom rules from.
177 */
178 rulePaths?: string[];
179 /**
180 * If false is present, ESLint doesn't load configuration files (.eslintrc.* files).
181 * Only the configuration of the constructor options is valid.
182 */
183 useEslintrc?: boolean;
184 }
185 interface DeprecatedRuleInfo {
186 /**
187 * The rule ID.
188 */
189 ruleId: string;
190 /**
191 * The rule IDs that replace this deprecated rule.
192 */
193 replacedBy: string[];
194 }
195 /**
196 * The LintResult value is the information of the linting result of each file.
197 */
198 interface LintResult {
199 /**
200 * The number of errors. This includes fixable errors.
201 */
202 errorCount: number;
203 /**
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).
206 */
207 filePath: string;
208 /**
209 * The number of errors that can be fixed automatically by the fix constructor option.
210 */
211 fixableErrorCount: number;
212 /**
213 * The number of warnings that can be fixed automatically by the fix constructor option.
214 */
215 fixableWarningCount: number;
216 /**
217 * The array of LintMessage objects.
218 */
219 messages: Linter.LintMessage[];
220 /**
221 * The source code of the file that was linted, with as many fixes applied as possible.
222 */
223 output?: string;
224 /**
225 * The original source code text. This property is undefined if any messages didn't exist or the output
226 * property exists.
227 */
228 source?: string;
229 /**
230 * The information about the deprecated rules that were used to check this file.
231 */
232 usedDeprecatedRules: DeprecatedRuleInfo[];
233 /**
234 * The number of warnings. This includes fixable warnings.
235 */
236 warningCount: number;
237 }
238 interface LintTextOptions {
239 /**
240 * The path to the file of the source code text. If omitted, the result.filePath becomes the string "<text>".
241 */
242 filePath?: string;
243 /**
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.
246 */
247 warnIgnored?: boolean;
248 }
249 /**
250 * The LintMessage value is the information of each linting error.
251 */
252 interface LintMessage {
253 /**
254 * The 1-based column number of the begin point of this message.
255 */
256 column: number;
257 /**
258 * The 1-based column number of the end point of this message. This property is undefined if this message
259 * is not a range.
260 */
261 endColumn: number | undefined;
262 /**
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.
265 */
266 endLine: number | undefined;
267 /**
268 * The EditInfo object of autofix. This property is undefined if this message is not fixable.
269 */
270 fix: EditInfo | undefined;
271 /**
272 * The 1-based line number of the begin point of this message.
273 */
274 line: number;
275 /**
276 * The error message
277 */
278 message: string;
279 /**
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.
282 */
283 ruleId: string | null;
284 /**
285 * The severity of this message. 1 means warning and 2 means error.
286 */
287 severity: 1 | 2;
288 /**
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.
292 */
293 suggestions: {
294 desc: string;
295 fix: EditInfo;
296 }[] | undefined;
297 }
298 /**
299 * The EditInfo value is information to edit text.
300 *
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
304 * empty string.
305 */
306 interface EditInfo {
307 /**
308 * The pair of 0-based indices in source code text to remove.
309 */
310 range: [number, number];
311 /**
312 * The text to add.
313 */
314 text: string;
315 }
316 /**
317 * The Formatter value is the object to convert the LintResult objects to text.
318 */
319 interface Formatter {
320 /**
321 * The method to convert the LintResult objects to text
322 */
323 format(results: LintResult[]): string;
324 }
325}
326declare const _ESLint: typeof ESLintBase;
327/**
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.
330 *
331 * If you want to lint code on browsers, use the Linter class instead.
332 *
333 * @since 7.0.0
334 */
335declare class ESLint extends _ESLint {
336}
337export { ESLint };
338//# sourceMappingURL=ESLint.d.ts.map
\No newline at end of file