From 12eb86bd1bbc28f5d49965adb63bfc25fd8e4558 Mon Sep 17 00:00:00 2001 From: Ika Date: Thu, 19 Oct 2017 23:36:58 +0800 Subject: [PATCH] feat(prettier): update to v1.7.x (#20708) --- types/prettier/index.d.ts | 26 +++++++++++++++++++++----- types/prettier/prettier-tests.ts | 3 +++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/types/prettier/index.d.ts b/types/prettier/index.d.ts index 1ed2568a1e..6ea1fcbbf9 100644 --- a/types/prettier/index.d.ts +++ b/types/prettier/index.d.ts @@ -9,7 +9,16 @@ import { File } from 'babel-types'; export type AST = File; export type BuiltInParser = (text: string, options?: any) => AST; -export type BuiltInParserName = 'babylon' | 'flow' | 'typescript' | 'postcss' | 'json' | 'graphql'; +export type BuiltInParserName = + | 'babylon' + | 'flow' + | 'typescript' + | 'postcss' // deprecated + | 'css' + | 'less' + | 'scss' + | 'json' + | 'graphql'; export type CustomParser = (text: string, parsers: Record, options: Options) => AST; @@ -107,11 +116,18 @@ export interface ResolveConfigOptions { * If set to `false`, all caching will be bypassed. */ useCache?: boolean; + /** + * Pass directly the path of the config file if you don't wish to search for it. + */ + config?: string; } /** - * `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. + * `resolveConfig` can be used to resolve configuration for a given source file, + * passing its path as the first argument. The config search will start at the + * file path and continue to search up the directory. + * (You can use `process.cwd()` to start searching from the current 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. @@ -119,9 +135,9 @@ export interface ResolveConfigOptions { * * The promise will be rejected if there was an error parsing the configuration file. */ -export function resolveConfig(filePath?: string, options?: ResolveConfigOptions): Promise; +export function resolveConfig(filePath: string, options?: ResolveConfigOptions): Promise; export namespace resolveConfig { - function sync(filePath?: string, options?: ResolveConfigOptions): null | Options; + function sync(filePath: string, options?: ResolveConfigOptions): null | Options; } /** diff --git a/types/prettier/prettier-tests.ts b/types/prettier/prettier-tests.ts index 8d95196101..9d78453bae 100644 --- a/types/prettier/prettier-tests.ts +++ b/types/prettier/prettier-tests.ts @@ -24,6 +24,9 @@ prettier.resolveConfig('path/to/somewhere').then(options => { } }); +// $ExpectError +prettier.resolveConfig(); + const options = prettier.resolveConfig.sync('path/to/somewhere'); if (options !== null) { const formatted = prettier.format('hello world', options);