3.35 kBTypeScriptView Raw
1// Type definitions for prettier-eslint 12.0
2// Project: https://github.com/prettier/prettier-eslint
3
4import * as eslint from 'eslint';
5import * as prettier from 'prettier';
6
7declare namespace format {
8 /**
9 * Logging level for the traceback of the synchronous formatting process.
10 */
11 type LogLevel = 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'silent';
12
13 /**
14 * Options to format text with Prettier and ESLint.
15 */
16 interface Options {
17 /**
18 * The config to use for formatting with ESLint.
19 */
20 eslintConfig?: eslint.Linter.Config;
21 /**
22 * The path to the eslint module to use.
23 * Will default to require.resolve('eslint')
24 */
25 eslintPath?: string;
26 /**
27 * The options to pass for formatting with `prettier` if the given
28 * option is not inferrable from the `eslintConfig`.
29 */
30 fallbackPrettierOptions?: prettier.Options;
31 /**
32 * The path of the file being formatted can be used in lieu of
33 * `eslintConfig` (eslint will be used to find the relevant
34 * config for the file). Will also be used to load the `text` if
35 * `text` is not provided.
36 */
37 filePath?: string;
38 /**
39 * The level for the logs (`error`, `warn`, `info`, `debug`, `trace`).
40 */
41 logLevel?: LogLevel;
42 /**
43 * The options to pass for formatting with `prettier`. If not provided,
44 * prettier-eslint will attempt to create the options based on the
45 * `eslintConfig` value.
46 */
47 prettierOptions?: prettier.Options;
48 /**
49 * The path to the `prettier` module.
50 * Will default to require.resovlve('prettier')
51 */
52 prettierPath?: string;
53 /**
54 * Run Prettier last.
55 */
56 prettierLast?: boolean;
57 /**
58 * The text (JavaScript code) to format.
59 */
60 text: string;
61 }
62}
63
64/**
65 * Formats the text with Prettier and then ESLint while obeying the user's
66 * configuration.
67 *
68 * @param options Options to format text with Prettier and Eslint.
69 * @param options.eslintConfig The config to use for formatting
70 * with ESLint.
71 * @param options.eslintPath The path to the eslint module to use.
72 * Will default to require.resolve('eslint')
73 * @param options.fallbackPrettierOptions The options to pass for
74 * formatting with `prettier` if the given option is not inferrable from the
75 * eslintConfig.
76 * @param options.filePath The path of the file being formatted
77 * can be used in lieu of `eslintConfig` (eslint will be used to find the
78 * relevant config for the file). Will also be used to load the `text` if
79 * `text` is not provided.
80 * @param options.prettierOptions The options to pass for
81 * formatting with `prettier`. If not provided, prettier-eslint will attempt
82 * to create the options based on the `eslintConfig` value.
83 * @param options.prettierLast Run Prettier last.
84 * @param options.prettierPath The path to the prettier module.
85 * Will default to require.resovlve('prettier')
86 * @param options.logLevel The level for the logs (`error`, `warn`,
87 * `info`, `debug`, `trace`).
88 * @param options.text The text (JavaScript code) to format.
89 * @return Auto-formatted text that is mostly compliant with the
90 * supplied configuration. The auto-formatting is limited to the issues that
91 * Prettier and ESLint can automatically fix.
92 */
93declare function format(options: format.Options): Promise<string>;
94
95export = format;