From de79fe52949e13201f5675ecf918ae6c0ab4becb Mon Sep 17 00:00:00 2001 From: Ifiok Jr Date: Sun, 14 Apr 2019 18:58:41 +0100 Subject: [PATCH] fix: make requested changes from PR --- types/prettier/parser-angular.d.ts | 7 ++--- types/prettier/parser-babylon.d.ts | 7 ++--- types/prettier/parser-flow.d.ts | 7 ++--- types/prettier/parser-glimmer.d.ts | 5 ---- types/prettier/parser-graphql.d.ts | 7 ++--- types/prettier/parser-html.d.ts | 7 ++--- types/prettier/parser-markdown.d.ts | 7 ++--- types/prettier/parser-postcss.d.ts | 7 ++--- types/prettier/parser-typescript.d.ts | 7 ++--- types/prettier/parser-yaml.d.ts | 7 ++--- types/prettier/prettier-tests.ts | 43 ++++++++++++++++++++------- types/prettier/standalone.d.ts | 21 +++---------- types/prettier/tsconfig.json | 1 - 13 files changed, 63 insertions(+), 70 deletions(-) delete mode 100644 types/prettier/parser-glimmer.d.ts diff --git a/types/prettier/parser-angular.d.ts b/types/prettier/parser-angular.d.ts index 72f81da10e..97765d740d 100644 --- a/types/prettier/parser-angular.d.ts +++ b/types/prettier/parser-angular.d.ts @@ -1,5 +1,4 @@ -import { Plugin } from './'; +import { Parser } from './'; -declare const plugin: Plugin; -export as namespace plugin; -export = plugin; +declare const parser: { parsers: { [parserName: string]: Parser } }; +export = parser; diff --git a/types/prettier/parser-babylon.d.ts b/types/prettier/parser-babylon.d.ts index 72f81da10e..97765d740d 100644 --- a/types/prettier/parser-babylon.d.ts +++ b/types/prettier/parser-babylon.d.ts @@ -1,5 +1,4 @@ -import { Plugin } from './'; +import { Parser } from './'; -declare const plugin: Plugin; -export as namespace plugin; -export = plugin; +declare const parser: { parsers: { [parserName: string]: Parser } }; +export = parser; diff --git a/types/prettier/parser-flow.d.ts b/types/prettier/parser-flow.d.ts index 72f81da10e..97765d740d 100644 --- a/types/prettier/parser-flow.d.ts +++ b/types/prettier/parser-flow.d.ts @@ -1,5 +1,4 @@ -import { Plugin } from './'; +import { Parser } from './'; -declare const plugin: Plugin; -export as namespace plugin; -export = plugin; +declare const parser: { parsers: { [parserName: string]: Parser } }; +export = parser; diff --git a/types/prettier/parser-glimmer.d.ts b/types/prettier/parser-glimmer.d.ts deleted file mode 100644 index 72f81da10e..0000000000 --- a/types/prettier/parser-glimmer.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { Plugin } from './'; - -declare const plugin: Plugin; -export as namespace plugin; -export = plugin; diff --git a/types/prettier/parser-graphql.d.ts b/types/prettier/parser-graphql.d.ts index 72f81da10e..97765d740d 100644 --- a/types/prettier/parser-graphql.d.ts +++ b/types/prettier/parser-graphql.d.ts @@ -1,5 +1,4 @@ -import { Plugin } from './'; +import { Parser } from './'; -declare const plugin: Plugin; -export as namespace plugin; -export = plugin; +declare const parser: { parsers: { [parserName: string]: Parser } }; +export = parser; diff --git a/types/prettier/parser-html.d.ts b/types/prettier/parser-html.d.ts index 72f81da10e..97765d740d 100644 --- a/types/prettier/parser-html.d.ts +++ b/types/prettier/parser-html.d.ts @@ -1,5 +1,4 @@ -import { Plugin } from './'; +import { Parser } from './'; -declare const plugin: Plugin; -export as namespace plugin; -export = plugin; +declare const parser: { parsers: { [parserName: string]: Parser } }; +export = parser; diff --git a/types/prettier/parser-markdown.d.ts b/types/prettier/parser-markdown.d.ts index 72f81da10e..97765d740d 100644 --- a/types/prettier/parser-markdown.d.ts +++ b/types/prettier/parser-markdown.d.ts @@ -1,5 +1,4 @@ -import { Plugin } from './'; +import { Parser } from './'; -declare const plugin: Plugin; -export as namespace plugin; -export = plugin; +declare const parser: { parsers: { [parserName: string]: Parser } }; +export = parser; diff --git a/types/prettier/parser-postcss.d.ts b/types/prettier/parser-postcss.d.ts index 72f81da10e..97765d740d 100644 --- a/types/prettier/parser-postcss.d.ts +++ b/types/prettier/parser-postcss.d.ts @@ -1,5 +1,4 @@ -import { Plugin } from './'; +import { Parser } from './'; -declare const plugin: Plugin; -export as namespace plugin; -export = plugin; +declare const parser: { parsers: { [parserName: string]: Parser } }; +export = parser; diff --git a/types/prettier/parser-typescript.d.ts b/types/prettier/parser-typescript.d.ts index 72f81da10e..97765d740d 100644 --- a/types/prettier/parser-typescript.d.ts +++ b/types/prettier/parser-typescript.d.ts @@ -1,5 +1,4 @@ -import { Plugin } from './'; +import { Parser } from './'; -declare const plugin: Plugin; -export as namespace plugin; -export = plugin; +declare const parser: { parsers: { [parserName: string]: Parser } }; +export = parser; diff --git a/types/prettier/parser-yaml.d.ts b/types/prettier/parser-yaml.d.ts index 72f81da10e..97765d740d 100644 --- a/types/prettier/parser-yaml.d.ts +++ b/types/prettier/parser-yaml.d.ts @@ -1,5 +1,4 @@ -import { Plugin } from './'; +import { Parser } from './'; -declare const plugin: Plugin; -export as namespace plugin; -export = plugin; +declare const parser: { parsers: { [parserName: string]: Parser } }; +export = parser; diff --git a/types/prettier/prettier-tests.ts b/types/prettier/prettier-tests.ts index 21326e21d7..1295cca297 100644 --- a/types/prettier/prettier-tests.ts +++ b/types/prettier/prettier-tests.ts @@ -1,21 +1,29 @@ import * as prettier from 'prettier'; import { ExpressionStatement, CallExpression, Identifier } from 'babel-types'; +import * as prettierStandalone from 'prettier/standalone'; +import typescriptParser = require('prettier/parser-typescript'); +import graphqlParser = require('prettier/parser-graphql'); +import babylonParser = require('prettier/parser-babylon'); +import htmlParser = require('prettier/parser-html'); +import markdownParser = require('prettier/parser-markdown'); +import postcssParser = require('prettier/parser-postcss'); +import yamlParser = require('prettier/parser-yaml'); -const formatted = prettier.format("foo ( );", { semi: false }); +const formatted = prettier.format('foo ( );', { semi: false }); -const isFormatted = prettier.check("foo ( );", { semi: false }); +const isFormatted = prettier.check('foo ( );', { semi: false }); -const result = prettier.formatWithCursor(" 1", { cursorOffset: 2 }); +const result = prettier.formatWithCursor(' 1', { cursorOffset: 2 }); -const customFormatted = prettier.format("lodash ( )", { +const customFormatted = prettier.format('lodash ( )', { parser(text, { babylon }) { const ast = babylon(text); const statement = ast.program.body[0] as ExpressionStatement; const expression = statement.expression as CallExpression; const identifier = expression.callee as Identifier; - identifier.name = "_"; + identifier.name = '_'; return ast; - } + }, }); prettier.resolveConfig('path/to/somewhere').then(options => { @@ -28,10 +36,10 @@ if (prettier.getFileInfo.sync('./tsconfig.json').inferredParser !== 'json') { throw new Error('Bad parser'); } -prettier.getFileInfo('./tsconfig.json').then((result) => { - if (result.inferredParser !== 'json') { - throw new Error('Bad parser'); - } +prettier.getFileInfo('./tsconfig.json').then(result => { + if (result.inferredParser !== 'json') { + throw new Error('Bad parser'); + } }); // $ExpectError @@ -45,4 +53,17 @@ if (options !== null) { prettier.clearConfigCache(); const currentSupportInfo = prettier.getSupportInfo(); -const specificSupportInfo = prettier.getSupportInfo("1.8.0"); +const specificSupportInfo = prettier.getSupportInfo('1.8.0'); + +prettierStandalone.formatWithCursor(' 1', { cursorOffset: 2, parser: 'babel' }); + +prettierStandalone.format(' 1', { parser: 'babel' }); +prettierStandalone.check(' console.log(b)'); + +typescriptParser.parsers.typescript.parse; // $ExpectType (text: string, parsers: { [parserName: string]: Parser; }, options: ParserOptions) => any +graphqlParser.parsers.graphql.parse; // $ExpectType (text: string, parsers: { [parserName: string]: Parser; }, options: ParserOptions) => any +babylonParser.parsers.babylon.parse; // $ExpectType (text: string, parsers: { [parserName: string]: Parser; }, options: ParserOptions) => any +htmlParser.parsers.html.parse; // $ExpectType (text: string, parsers: { [parserName: string]: Parser; }, options: ParserOptions) => any +markdownParser.parsers.markdown.parse; // $ExpectType (text: string, parsers: { [parserName: string]: Parser; }, options: ParserOptions) => any +postcssParser.parsers.postcss.parse; // $ExpectType (text: string, parsers: { [parserName: string]: Parser; }, options: ParserOptions) => any +yamlParser.parsers.yaml.parse; // $ExpectType (text: string, parsers: { [parserName: string]: Parser; }, options: ParserOptions) => any diff --git a/types/prettier/standalone.d.ts b/types/prettier/standalone.d.ts index f985babdd5..59db8c9d47 100644 --- a/types/prettier/standalone.d.ts +++ b/types/prettier/standalone.d.ts @@ -1,18 +1,5 @@ import { CursorOptions, CursorResult, Options, Plugin } from './'; -type Omit = Pick< - GType, - Exclude ->; - -type MakeRequired = Omit< - GType, - GKeys -> & - { [P in GKeys]-?: GType[P] }; - -type MR = MakeRequired; - /** * formatWithCursor both formats the code, and translates a cursor position from unformatted code to formatted code. * This is useful for editor integrations, to prevent the cursor from moving when code is formatted @@ -26,18 +13,18 @@ type MR = MakeRequired; */ export function formatWithCursor( source: string, - options: MR, + options: CursorOptions, ): CursorResult; /** * `format` is used to format text using Prettier. [Options](https://github.com/prettier/prettier#options) may be provided to override the defaults. */ -export function format(source: string, options?: MR): string; +export function format(source: string, options?: Options): string; /** * `check` checks to see if the file has been formatted with Prettier given those options and returns a `Boolean`. * This is similar to the `--list-different` parameter in the CLI and is useful for running Prettier in CI scenarios. */ -export function check(source: string, options?: MR): boolean; +export function check(source: string, options?: Options): boolean; -export { Plugin }; +export as namespace prettier; diff --git a/types/prettier/tsconfig.json b/types/prettier/tsconfig.json index bf9eae5774..bf0dee4abf 100644 --- a/types/prettier/tsconfig.json +++ b/types/prettier/tsconfig.json @@ -18,7 +18,6 @@ "parser-angular.d.ts", "parser-babylon.d.ts", "parser-flow.d.ts", - "parser-glimmer.d.ts", "parser-graphql.d.ts", "parser-html.d.ts", "parser-markdown.d.ts",