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

Define separate type for pretty-format plugin Options #3802

Merged
merged 3 commits into from
Jun 26, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 5 additions & 9 deletions packages/pretty-format/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
Refs,
StringOrNull,
Plugins,
Options,
PrettyOptions,
} from 'types/PrettyFormat';

import style from 'ansi-styles';
Expand All @@ -36,14 +36,12 @@ type Theme = {|
type InitialOptions = {|
callToJSON?: boolean,
escapeRegex?: boolean,
edgeSpacing?: string,
highlight?: boolean,
indent?: number,
maxDepth?: number,
min?: boolean,
plugins?: Plugins,
printFunctionName?: boolean,
spacing?: string,
theme?: Theme,
|};

Expand Down Expand Up @@ -792,17 +790,15 @@ function print(
);
}

const DEFAULTS: Options = {
const DEFAULTS: PrettyOptions = {
callToJSON: true,
edgeSpacing: '\n',
escapeRegex: false,
highlight: false,
indent: 2,
maxDepth: Infinity,
min: false,
plugins: [],
printFunctionName: true,
spacing: '\n',
theme: {
comment: 'gray',
content: 'reset',
Expand All @@ -826,7 +822,7 @@ function validateOptions(opts: InitialOptions) {
}
}

function normalizeOptions(opts: InitialOptions): Options {
function normalizeOptions(opts: InitialOptions): PrettyOptions {
const result = {};

Object.keys(DEFAULTS).forEach(
Expand All @@ -841,7 +837,7 @@ function normalizeOptions(opts: InitialOptions): Options {
}

// $FlowFixMe the type cast below means YOU are responsible to verify the code above.
return (result: Options);
return (result: PrettyOptions);
}

function normalizeTheme(themeOption: ?Theme) {
Expand Down Expand Up @@ -871,7 +867,7 @@ function createIndent(indent: number): string {
}

function prettyFormat(val: any, initialOptions?: InitialOptions): string {
let opts: Options;
let opts: PrettyOptions;
if (!initialOptions) {
opts = DEFAULTS;
} else {
Expand Down
10 changes: 7 additions & 3 deletions types/PrettyFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ export type Refs = Array<any>;
export type Print = any => string;
export type StringOrNull = string | null;

export type Options = {|
export type PrettyOptions = {|
callToJSON: boolean,
edgeSpacing: string,
escapeRegex: boolean,
highlight: boolean,
indent: number,
maxDepth: number,
min: boolean,
plugins: Plugins,
printFunctionName: boolean,
spacing: string,
theme: {|
comment: string,
content: string,
Expand All @@ -40,6 +38,12 @@ export type Options = {|
|},
|};

export type Options = {|
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about PluginOptions? We could leave the old name of PrettyOptions then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thank you for good direction.

edgeSpacing: string,
min: boolean,
spacing: string,
|};

export type Plugin = {
print: (
val: any,
Expand Down