Skip to content

Commit b271486

Browse files
author
M.U.N.I.N
authored
feat: ✨ Add TypeScript definitions (#739)
1 parent 3746d67 commit b271486

File tree

3 files changed

+114
-1
lines changed

3 files changed

+114
-1
lines changed

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
"version": "0.0.0-development",
44
"description": "Formats your JavaScript using prettier followed by eslint --fix",
55
"main": "dist/index.js",
6+
"types": "types/index.d.ts",
67
"scripts": {
78
"start": "nps",
89
"test": "nps test",
910
"precommit": "opt --in pre-commit --exec \"npm start validate\""
1011
},
1112
"files": [
12-
"dist"
13+
"dist",
14+
"types"
1315
],
1416
"keywords": [],
1517
"author": "Kent C. Dodds <[email protected]> (http://kentcdodds.com/)",
@@ -18,6 +20,8 @@
1820
],
1921
"license": "MIT",
2022
"dependencies": {
23+
"@types/eslint": "^8.4.2",
24+
"@types/prettier": "^2.6.0",
2125
"@typescript-eslint/parser": "^5.10.0",
2226
"common-tags": "^1.4.0",
2327
"dlv": "^1.1.0",

tsconfig.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"module": "CommonJS",
5+
"lib": ["ES2020", "DOM"],
6+
"moduleResolution": "Node",
7+
"rootDir": ".",
8+
"strict": true,
9+
"noEmit": true,
10+
"esModuleInterop": true,
11+
"baseUrl": "./"
12+
},
13+
"exclude": ["node_modules"]
14+
}

types/index.d.ts

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Type definitions for prettier-eslint 12.0
2+
// Project: https://github.com/prettier/prettier-eslint
3+
4+
import * as eslint from "eslint";
5+
import * as prettier from "prettier";
6+
7+
declare namespace format {
8+
/**
9+
* Logging level for the traceback of the synchronous formatting process.
10+
*/
11+
type LogLevel = "error" | "warn" | "info" | "debug" | "trace";
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+
*/
93+
declare function format(options: format.Options): string;
94+
95+
export = format;

0 commit comments

Comments
 (0)