From 5533a2a57cf00c09c41559561523b2b429bed2fe Mon Sep 17 00:00:00 2001 From: Mark Pedrotti Date: Mon, 12 Jun 2017 15:25:30 -0400 Subject: [PATCH 1/2] Define separate type for pretty-format plugin Options --- packages/pretty-format/src/index.js | 14 +++++--------- types/PrettyFormat.js | 10 +++++++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/pretty-format/src/index.js b/packages/pretty-format/src/index.js index 5f6e04c2c608..f2a7d21f0500 100644 --- a/packages/pretty-format/src/index.js +++ b/packages/pretty-format/src/index.js @@ -13,7 +13,7 @@ import type { Refs, StringOrNull, Plugins, - Options, + PrettyOptions, } from 'types/PrettyFormat'; import style from 'ansi-styles'; @@ -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, |}; @@ -792,9 +790,8 @@ function print( ); } -const DEFAULTS: Options = { +const DEFAULTS: PrettyOptions = { callToJSON: true, - edgeSpacing: '\n', escapeRegex: false, highlight: false, indent: 2, @@ -802,7 +799,6 @@ const DEFAULTS: Options = { min: false, plugins: [], printFunctionName: true, - spacing: '\n', theme: { comment: 'gray', content: 'reset', @@ -826,7 +822,7 @@ function validateOptions(opts: InitialOptions) { } } -function normalizeOptions(opts: InitialOptions): Options { +function normalizeOptions(opts: InitialOptions): PrettyOptions { const result = {}; Object.keys(DEFAULTS).forEach( @@ -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) { @@ -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 { diff --git a/types/PrettyFormat.js b/types/PrettyFormat.js index b8482e5fc4af..8976b808d2fb 100644 --- a/types/PrettyFormat.js +++ b/types/PrettyFormat.js @@ -20,9 +20,8 @@ export type Refs = Array; 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, @@ -30,7 +29,6 @@ export type Options = {| min: boolean, plugins: Plugins, printFunctionName: boolean, - spacing: string, theme: {| comment: string, content: string, @@ -40,6 +38,12 @@ export type Options = {| |}, |}; +export type Options = {| + edgeSpacing: string, + min: boolean, + spacing: string, +|}; + export type Plugin = { print: ( val: any, From 2b876adfb5ee66e38165eef583a170c85b0c7ebb Mon Sep 17 00:00:00 2001 From: Mark Pedrotti Date: Tue, 13 Jun 2017 13:01:06 -0400 Subject: [PATCH 2/2] Rename separate type as PluginOptions --- packages/pretty-format/src/index.js | 10 +++++----- .../pretty-format/src/plugins/AsymmetricMatcher.js | 10 ++++++++-- packages/pretty-format/src/plugins/ConvertAnsi.js | 10 ++++++++-- packages/pretty-format/src/plugins/HTMLElement.js | 10 ++++++++-- packages/pretty-format/src/plugins/ImmutableList.js | 10 ++++++++-- packages/pretty-format/src/plugins/ImmutableMap.js | 10 ++++++++-- .../pretty-format/src/plugins/ImmutableOrderedMap.js | 10 ++++++++-- .../pretty-format/src/plugins/ImmutableOrderedSet.js | 10 ++++++++-- packages/pretty-format/src/plugins/ImmutableRecord.js | 10 ++++++++-- packages/pretty-format/src/plugins/ImmutableSet.js | 10 ++++++++-- packages/pretty-format/src/plugins/ImmutableStack.js | 10 ++++++++-- packages/pretty-format/src/plugins/ReactElement.js | 10 ++++++++-- .../pretty-format/src/plugins/ReactTestComponent.js | 4 ++-- .../pretty-format/src/plugins/lib/printImmutable.js | 4 ++-- types/PrettyFormat.js | 6 +++--- 15 files changed, 100 insertions(+), 34 deletions(-) diff --git a/packages/pretty-format/src/index.js b/packages/pretty-format/src/index.js index f2a7d21f0500..0fea19411c0e 100644 --- a/packages/pretty-format/src/index.js +++ b/packages/pretty-format/src/index.js @@ -13,7 +13,7 @@ import type { Refs, StringOrNull, Plugins, - PrettyOptions, + Options, } from 'types/PrettyFormat'; import style from 'ansi-styles'; @@ -790,7 +790,7 @@ function print( ); } -const DEFAULTS: PrettyOptions = { +const DEFAULTS: Options = { callToJSON: true, escapeRegex: false, highlight: false, @@ -822,7 +822,7 @@ function validateOptions(opts: InitialOptions) { } } -function normalizeOptions(opts: InitialOptions): PrettyOptions { +function normalizeOptions(opts: InitialOptions): Options { const result = {}; Object.keys(DEFAULTS).forEach( @@ -837,7 +837,7 @@ function normalizeOptions(opts: InitialOptions): PrettyOptions { } // $FlowFixMe the type cast below means YOU are responsible to verify the code above. - return (result: PrettyOptions); + return (result: Options); } function normalizeTheme(themeOption: ?Theme) { @@ -867,7 +867,7 @@ function createIndent(indent: number): string { } function prettyFormat(val: any, initialOptions?: InitialOptions): string { - let opts: PrettyOptions; + let opts: Options; if (!initialOptions) { opts = DEFAULTS; } else { diff --git a/packages/pretty-format/src/plugins/AsymmetricMatcher.js b/packages/pretty-format/src/plugins/AsymmetricMatcher.js index e49beb74a3f1..b98d4b484ae9 100644 --- a/packages/pretty-format/src/plugins/AsymmetricMatcher.js +++ b/packages/pretty-format/src/plugins/AsymmetricMatcher.js @@ -8,7 +8,13 @@ * @flow */ -import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat'; +import type { + Colors, + Indent, + PluginOptions, + Print, + Plugin, +} from 'types/PrettyFormat'; const asymmetricMatcher = Symbol.for('jest.asymmetricMatcher'); const SPACE = ' '; @@ -20,7 +26,7 @@ const print = ( val: any, print: Print, indent: Indent, - opts: Options, + opts: PluginOptions, colors: Colors, ) => { const stringedValue = val.toString(); diff --git a/packages/pretty-format/src/plugins/ConvertAnsi.js b/packages/pretty-format/src/plugins/ConvertAnsi.js index b3bccc2e0859..9c60fc5369fe 100644 --- a/packages/pretty-format/src/plugins/ConvertAnsi.js +++ b/packages/pretty-format/src/plugins/ConvertAnsi.js @@ -8,7 +8,13 @@ * @flow */ -import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat'; +import type { + Colors, + Indent, + PluginOptions, + Print, + Plugin, +} from 'types/PrettyFormat'; import ansiRegex from 'ansi-regex'; import style from 'ansi-styles'; @@ -42,7 +48,7 @@ const print = ( val: any, print: Print, indent: Indent, - opts: Options, + opts: PluginOptions, colors: Colors, ) => print(toHumanReadableAnsi(val)); diff --git a/packages/pretty-format/src/plugins/HTMLElement.js b/packages/pretty-format/src/plugins/HTMLElement.js index a30fb88f4c35..5b4da85efda0 100644 --- a/packages/pretty-format/src/plugins/HTMLElement.js +++ b/packages/pretty-format/src/plugins/HTMLElement.js @@ -8,7 +8,13 @@ * @flow */ -import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat'; +import type { + Colors, + Indent, + PluginOptions, + Print, + Plugin, +} from 'types/PrettyFormat'; import escapeHTML from './lib/escapeHTML'; @@ -80,7 +86,7 @@ const print = ( element: HTMLElement | HTMLText | HTMLComment, print: Print, indent: Indent, - opts: Options, + opts: PluginOptions, colors: Colors, ): string => { if (element.nodeType === 3) { diff --git a/packages/pretty-format/src/plugins/ImmutableList.js b/packages/pretty-format/src/plugins/ImmutableList.js index a9a957d415ba..b62c3187619f 100644 --- a/packages/pretty-format/src/plugins/ImmutableList.js +++ b/packages/pretty-format/src/plugins/ImmutableList.js @@ -8,7 +8,13 @@ * @flow */ -import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat'; +import type { + Colors, + Indent, + PluginOptions, + Print, + Plugin, +} from 'types/PrettyFormat'; import printImmutable from './lib/printImmutable'; @@ -19,7 +25,7 @@ const print = ( val: any, print: Print, indent: Indent, - opts: Options, + opts: PluginOptions, colors: Colors, ) => printImmutable(val, print, indent, opts, colors, 'List', false); diff --git a/packages/pretty-format/src/plugins/ImmutableMap.js b/packages/pretty-format/src/plugins/ImmutableMap.js index e311985aada8..c625b51082a2 100644 --- a/packages/pretty-format/src/plugins/ImmutableMap.js +++ b/packages/pretty-format/src/plugins/ImmutableMap.js @@ -8,7 +8,13 @@ * @flow */ -import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat'; +import type { + Colors, + Indent, + PluginOptions, + Print, + Plugin, +} from 'types/PrettyFormat'; import printImmutable from './lib/printImmutable'; @@ -21,7 +27,7 @@ const print = ( val: any, print: Print, indent: Indent, - opts: Options, + opts: PluginOptions, colors: Colors, ) => printImmutable(val, print, indent, opts, colors, 'Map', true); diff --git a/packages/pretty-format/src/plugins/ImmutableOrderedMap.js b/packages/pretty-format/src/plugins/ImmutableOrderedMap.js index c51199ed2882..1dfd255d4af2 100644 --- a/packages/pretty-format/src/plugins/ImmutableOrderedMap.js +++ b/packages/pretty-format/src/plugins/ImmutableOrderedMap.js @@ -8,7 +8,13 @@ * @flow */ -import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat'; +import type { + Colors, + Indent, + PluginOptions, + Print, + Plugin, +} from 'types/PrettyFormat'; import printImmutable from './lib/printImmutable'; @@ -21,7 +27,7 @@ const print = ( val: any, print: Print, indent: Indent, - opts: Options, + opts: PluginOptions, colors: Colors, ) => printImmutable(val, print, indent, opts, colors, 'OrderedMap', true); diff --git a/packages/pretty-format/src/plugins/ImmutableOrderedSet.js b/packages/pretty-format/src/plugins/ImmutableOrderedSet.js index 88763fd78866..0132ad1aced6 100644 --- a/packages/pretty-format/src/plugins/ImmutableOrderedSet.js +++ b/packages/pretty-format/src/plugins/ImmutableOrderedSet.js @@ -8,7 +8,13 @@ * @flow */ -import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat'; +import type { + Colors, + Indent, + PluginOptions, + Print, + Plugin, +} from 'types/PrettyFormat'; import printImmutable from './lib/printImmutable'; @@ -21,7 +27,7 @@ const print = ( val: any, print: Print, indent: Indent, - opts: Options, + opts: PluginOptions, colors: Colors, ) => printImmutable(val, print, indent, opts, colors, 'OrderedSet', false); diff --git a/packages/pretty-format/src/plugins/ImmutableRecord.js b/packages/pretty-format/src/plugins/ImmutableRecord.js index 1b8656b9ae76..2d20d818e7e3 100644 --- a/packages/pretty-format/src/plugins/ImmutableRecord.js +++ b/packages/pretty-format/src/plugins/ImmutableRecord.js @@ -8,7 +8,13 @@ * @flow */ -import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat'; +import type { + Colors, + Indent, + PluginOptions, + Print, + Plugin, +} from 'types/PrettyFormat'; import printImmutable from './lib/printImmutable'; @@ -19,7 +25,7 @@ const print = ( val: any, print: Print, indent: Indent, - opts: Options, + opts: PluginOptions, colors: Colors, ) => printImmutable(val, print, indent, opts, colors, 'Record', true); diff --git a/packages/pretty-format/src/plugins/ImmutableSet.js b/packages/pretty-format/src/plugins/ImmutableSet.js index 74005a69c471..69afdd5b0b25 100644 --- a/packages/pretty-format/src/plugins/ImmutableSet.js +++ b/packages/pretty-format/src/plugins/ImmutableSet.js @@ -8,7 +8,13 @@ * @flow */ -import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat'; +import type { + Colors, + Indent, + PluginOptions, + Print, + Plugin, +} from 'types/PrettyFormat'; import printImmutable from './lib/printImmutable'; @@ -21,7 +27,7 @@ const print = ( val: any, print: Print, indent: Indent, - opts: Options, + opts: PluginOptions, colors: Colors, ) => printImmutable(val, print, indent, opts, colors, 'Set', false); diff --git a/packages/pretty-format/src/plugins/ImmutableStack.js b/packages/pretty-format/src/plugins/ImmutableStack.js index 110400e8a996..53d02642c93d 100644 --- a/packages/pretty-format/src/plugins/ImmutableStack.js +++ b/packages/pretty-format/src/plugins/ImmutableStack.js @@ -8,7 +8,13 @@ * @flow */ -import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat'; +import type { + Colors, + Indent, + PluginOptions, + Print, + Plugin, +} from 'types/PrettyFormat'; import printImmutable from './lib/printImmutable'; @@ -19,7 +25,7 @@ const print = ( val: any, print: Print, indent: Indent, - opts: Options, + opts: PluginOptions, colors: Colors, ) => printImmutable(val, print, indent, opts, colors, 'Stack', false); diff --git a/packages/pretty-format/src/plugins/ReactElement.js b/packages/pretty-format/src/plugins/ReactElement.js index 899e46e9824f..75482cec27fa 100644 --- a/packages/pretty-format/src/plugins/ReactElement.js +++ b/packages/pretty-format/src/plugins/ReactElement.js @@ -8,7 +8,13 @@ * @flow */ -import type {Colors, Indent, Options, Print, Plugin} from 'types/PrettyFormat'; +import type { + Colors, + Indent, + PluginOptions, + Print, + Plugin, +} from 'types/PrettyFormat'; import escapeHTML from './lib/escapeHTML'; @@ -71,7 +77,7 @@ const print = ( element: React$Element<*>, print: Print, indent: Indent, - opts: Options, + opts: PluginOptions, colors: Colors, ) => { let result = colors.tag.open + '<'; diff --git a/packages/pretty-format/src/plugins/ReactTestComponent.js b/packages/pretty-format/src/plugins/ReactTestComponent.js index 97ca3be3d53e..40bb035290da 100644 --- a/packages/pretty-format/src/plugins/ReactTestComponent.js +++ b/packages/pretty-format/src/plugins/ReactTestComponent.js @@ -11,7 +11,7 @@ import type { Colors, Indent, - Options, + PluginOptions, Print, Plugin, ReactTestObject, @@ -73,7 +73,7 @@ const print = ( instance: ReactTestObject, print: Print, indent: Indent, - opts: Options, + opts: PluginOptions, colors: Colors, ) => { let closeInNewLine = false; diff --git a/packages/pretty-format/src/plugins/lib/printImmutable.js b/packages/pretty-format/src/plugins/lib/printImmutable.js index 715a79d2b207..0cbe0b412ceb 100644 --- a/packages/pretty-format/src/plugins/lib/printImmutable.js +++ b/packages/pretty-format/src/plugins/lib/printImmutable.js @@ -8,7 +8,7 @@ * @flow */ -import type {Colors, Indent, Options, Print} from 'types/PrettyFormat'; +import type {Colors, Indent, PluginOptions, Print} from 'types/PrettyFormat'; const IMMUTABLE_NAMESPACE = 'Immutable.'; const SPACE = ' '; @@ -22,7 +22,7 @@ const printImmutable = ( val: any, print: Print, indent: Indent, - opts: Options, + opts: PluginOptions, colors: Colors, immutableDataStructureName: string, isMap: boolean, diff --git a/types/PrettyFormat.js b/types/PrettyFormat.js index 8976b808d2fb..a2d8292bb4a8 100644 --- a/types/PrettyFormat.js +++ b/types/PrettyFormat.js @@ -20,7 +20,7 @@ export type Refs = Array; export type Print = any => string; export type StringOrNull = string | null; -export type PrettyOptions = {| +export type Options = {| callToJSON: boolean, escapeRegex: boolean, highlight: boolean, @@ -38,7 +38,7 @@ export type PrettyOptions = {| |}, |}; -export type Options = {| +export type PluginOptions = {| edgeSpacing: string, min: boolean, spacing: string, @@ -49,7 +49,7 @@ export type Plugin = { val: any, serialize: Print, indent: Indent, - opts: Options, + opts: PluginOptions, colors: Colors, ) => string, test: any => boolean,