UNPKG

3.18 kBTypeScriptView Raw
1import eslint = require("eslint");
2
3// eslint.CLIEngine.getErrorResults without modification
4// eslint.CLIEngine.getFormatter without modification
5// eslint.CLIEngine.outputFixes redeclared to match input shape
6
7/**
8 * Can be used to filter out all the non error messages from the report object.
9 */
10export const getErrorResults: typeof eslint.ESLint.getErrorResults;
11/**
12 * Returns the formatter representing the given format
13 * or null if no formatter with the given name can be found.
14 * see {@link https://github.com/eslint/eslint/blob/master/docs/developer-guide/nodejs-api.md#clienginegetformatter}
15 */
16export function getFormatter(
17 format?: string,
18): (results: eslint.ESLint.LintResult[], data?: eslint.ESLint.LintResultData) => string;
19/**
20 * Used to output fixes from report to disk.
21 * It does by looking for files that have an output property in their results
22 */
23export function outputFixes(report: ResultReport): void;
24
25export function getConfig(
26 options: CLIEngineOptions & { filePath: string },
27): ReturnType<eslint.ESLint["calculateConfigForFile"]>;
28export function lintText(text: string, options?: Options): ResultReport;
29export function lintFiles(patterns: string | string[], options?: Options): ResultReport | Promise<ResultReport>;
30
31export type CLIEngineOptions = Pick<eslint.ESLint.Options, "baseConfig" | "cwd" | "extensions" | "fix" | "ignore"> & {
32 envs?: string[] | undefined;
33 globals?: string[] | undefined;
34 parser?: string | undefined;
35 plugins?: string[];
36 rules?: { [name: string]: eslint.Linter.RuleLevel | eslint.Linter.RuleLevelAndOptions } | undefined;
37};
38export type ESLintOptions = Pick<eslint.Linter.LintOptions, "filename">;
39export type ESLintConfig = Pick<eslint.Linter.Config, "extends" | "settings">;
40
41export type Options =
42 & {
43 /** Some paths are ignored by default, including paths in .gitignore and .eslintignore. Additional ignores can be added here */
44 ignores?: string[] | undefined;
45 /** Enable rules specific to the Node.js versions within the configured range */
46 nodeVersion?: string | boolean | undefined;
47 /** Format code with Prettier */
48 prettier?: boolean | undefined;
49 /**
50 * Print the ESLint configuration for the given file
51 */
52 printConfig?: string | undefined;
53 /** Set it to false to enforce no-semicolon style. */
54 semicolon?: boolean | undefined;
55 /** Set it to true to get 2-space indentation or specify the number of spaces. */
56 space?: boolean | number | undefined;
57 /**
58 * Use {@link https://github.com/benmosher/eslint-plugin-import/tree/master/resolvers/webpack}
59 * to resolve import search paths. This is enabled automatically if a `webpack.config.js` file is found.
60 * Set this to a boolean to explicitly enable or disable the resolver.
61 * @default false
62 */
63 webpack?: boolean | object | undefined;
64 }
65 & CLIEngineOptions
66 & ESLintConfig
67 & ESLintOptions;
68
69export interface ResultReport {
70 readonly errorCount: number;
71 readonly warningCount: number;
72 readonly results: eslint.ESLint.LintResult[];
73}