fix: make requested changes from PR

This commit is contained in:
Ifiok Jr 2019-04-14 18:58:41 +01:00
parent d15eb07b56
commit de79fe5294
No known key found for this signature in database
GPG Key ID: 8EF46CD5738DCC1B
13 changed files with 63 additions and 70 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -1,5 +0,0 @@
import { Plugin } from './';
declare const plugin: Plugin;
export as namespace plugin;
export = plugin;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -1,18 +1,5 @@
import { CursorOptions, CursorResult, Options, Plugin } from './';
type Omit<GType, GKeys extends keyof GType> = Pick<
GType,
Exclude<keyof GType, GKeys>
>;
type MakeRequired<GType extends {}, GKeys extends keyof GType> = Omit<
GType,
GKeys
> &
{ [P in GKeys]-?: GType[P] };
type MR<GType extends { parser?: any }> = MakeRequired<GType, 'parser'>;
/**
* 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<GType extends { parser?: any }> = MakeRequired<GType, 'parser'>;
*/
export function formatWithCursor(
source: string,
options: MR<CursorOptions>,
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<Options>): 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<Options>): boolean;
export function check(source: string, options?: Options): boolean;
export { Plugin };
export as namespace prettier;

View File

@ -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",