From 22671e3941fb98da42a288fb99642f5cdc9c7bdd Mon Sep 17 00:00:00 2001 From: ikatyang Date: Tue, 29 Aug 2017 13:24:51 +0800 Subject: [PATCH] feat(prettier): update to version 1.6 --- types/prettier/index.d.ts | 27 ++++++++++++++++++++++++++- types/prettier/prettier-tests.ts | 8 ++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/types/prettier/index.d.ts b/types/prettier/index.d.ts index e02fd9a587..ad6880f04f 100644 --- a/types/prettier/index.d.ts +++ b/types/prettier/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for prettier 1.5 +// Type definitions for prettier 1.6 // Project: https://github.com/prettier/prettier // Definitions by: Ika // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -97,6 +97,31 @@ export function check(source: string, options?: Options): boolean; */ export function formatWithCursor(source: string, options: CursorOptions): CursorResult; +export interface ResolveConfigOptions { + /** + * If set to `false`, all caching will be bypassed. + */ + useCache?: boolean; +} + +/** + * `resolveConfig` can be used to resolve configuration for a given source file. + * The function optionally accepts an input file path as an argument, which defaults to the current working directory. + * A promise is returned which will resolve to: + * + * - An options object, providing a [config file](https://github.com/prettier/prettier#configuration-file) was found. + * - `null`, if no file was found. + * + * The promise will be rejected if there was an error parsing the configuration file. + */ +export function resolveConfig(filePath?: string, options?: ResolveConfigOptions): Promise; + +/** + * As you repeatedly call `resolveConfig`, the file system structure will be cached for performance. + * This function will clear the cache. Generally this is only needed for editor integrations that know that the file system has changed since the last format took place. + */ +export function clearConfigCache(): void; + /** * `version` field in `package.json` */ diff --git a/types/prettier/prettier-tests.ts b/types/prettier/prettier-tests.ts index d50cc47c98..a51e8902c4 100644 --- a/types/prettier/prettier-tests.ts +++ b/types/prettier/prettier-tests.ts @@ -17,3 +17,11 @@ const customFormatted = prettier.format("lodash ( )", { return ast; } }); + +prettier.resolveConfig('path/to/somewhere').then(options => { + if (options !== null) { + const formatted = prettier.format('hello world', options); + } +}); + +prettier.clearConfigCache();