Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ Add TypeScript definitions #739

Merged
merged 2 commits into from May 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
"version": "0.0.0-development",
"description": "Formats your JavaScript using prettier followed by eslint --fix",
"main": "dist/index.js",
"types": "types/index.d.ts",
"scripts": {
"start": "nps",
"test": "nps test",
"precommit": "opt --in pre-commit --exec \"npm start validate\""
},
"files": [
"dist"
"dist",
"types"
],
"keywords": [],
"author": "Kent C. Dodds <[email protected]> (http://kentcdodds.com/)",
Expand All @@ -18,6 +20,8 @@
],
"license": "MIT",
"dependencies": {
"@types/eslint": "^8.4.2",
"@types/prettier": "^2.6.0",
"@typescript-eslint/parser": "^5.10.0",
"common-tags": "^1.4.0",
"dlv": "^1.1.0",
Expand Down
14 changes: 14 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "CommonJS",
"lib": ["ES2020", "DOM"],
"moduleResolution": "Node",
"rootDir": ".",
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"baseUrl": "./"
},
"exclude": ["node_modules"]
}
95 changes: 95 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Type definitions for prettier-eslint 12.0
// Project: https://github.com/prettier/prettier-eslint

import * as eslint from "eslint";
import * as prettier from "prettier";

declare namespace format {
/**
* Logging level for the traceback of the synchronous formatting process.
*/
type LogLevel = "error" | "warn" | "info" | "debug" | "trace";

/**
* Options to format text with Prettier and ESLint.
*/
interface Options {
/**
* The config to use for formatting with ESLint.
*/
eslintConfig?: eslint.Linter.Config;
/**
* The path to the eslint module to use.
* Will default to require.resolve('eslint')
*/
eslintPath?: string;
/**
* The options to pass for formatting with `prettier` if the given
* option is not inferrable from the `eslintConfig`.
*/
fallbackPrettierOptions?: prettier.Options;
/**
* The path of the file being formatted can be used in lieu of
* `eslintConfig` (eslint will be used to find the relevant
* config for the file). Will also be used to load the `text` if
* `text` is not provided.
*/
filePath?: string;
/**
* The level for the logs (`error`, `warn`, `info`, `debug`, `trace`).
*/
logLevel?: LogLevel;
/**
* The options to pass for formatting with `prettier`. If not provided,
* prettier-eslint will attempt to create the options based on the
* `eslintConfig` value.
*/
prettierOptions?: prettier.Options;
/**
* The path to the `prettier` module.
* Will default to require.resovlve('prettier')
*/
prettierPath?: string;
/**
* Run Prettier last.
*/
prettierLast?: boolean;
/**
* The text (JavaScript code) to format.
*/
text: string;
}
}

/**
* Formats the text with Prettier and then ESLint while obeying the user's
* configuration.
*
* @param options Options to format text with Prettier and Eslint.
* @param options.eslintConfig The config to use for formatting
* with ESLint.
* @param options.eslintPath The path to the eslint module to use.
* Will default to require.resolve('eslint')
* @param options.fallbackPrettierOptions The options to pass for
* formatting with `prettier` if the given option is not inferrable from the
* eslintConfig.
* @param options.filePath The path of the file being formatted
* can be used in lieu of `eslintConfig` (eslint will be used to find the
* relevant config for the file). Will also be used to load the `text` if
* `text` is not provided.
* @param options.prettierOptions The options to pass for
* formatting with `prettier`. If not provided, prettier-eslint will attempt
* to create the options based on the `eslintConfig` value.
* @param options.prettierLast Run Prettier last.
* @param options.prettierPath The path to the prettier module.
* Will default to require.resovlve('prettier')
* @param options.logLevel The level for the logs (`error`, `warn`,
* `info`, `debug`, `trace`).
* @param options.text The text (JavaScript code) to format.
* @return Auto-formatted text that is mostly compliant with the
* supplied configuration. The auto-formatting is limited to the issues that
* Prettier and ESLint can automatically fix.
*/
declare function format(options: format.Options): string;

export = format;