Skip to content

Commit

Permalink
Define separate type for pretty-format plugin Options (jestjs#3802)
Browse files Browse the repository at this point in the history
* Define separate type for pretty-format plugin Options

* Rename separate type as PluginOptions
  • Loading branch information
pedrottimark authored and cpojer committed Jun 26, 2017
1 parent 928c5b1 commit 48af250
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 33 deletions.
4 changes: 0 additions & 4 deletions packages/pretty-format/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -794,15 +792,13 @@ function print(

const DEFAULTS: Options = {
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 Down
10 changes: 8 additions & 2 deletions packages/pretty-format/src/plugins/asymmetric_matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ' ';
Expand All @@ -20,7 +26,7 @@ const print = (
val: any,
print: Print,
indent: Indent,
opts: Options,
opts: PluginOptions,
colors: Colors,
) => {
const stringedValue = val.toString();
Expand Down
10 changes: 8 additions & 2 deletions packages/pretty-format/src/plugins/convert_ansi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -42,7 +48,7 @@ const print = (
val: any,
print: Print,
indent: Indent,
opts: Options,
opts: PluginOptions,
colors: Colors,
) => print(toHumanReadableAnsi(val));

Expand Down
10 changes: 8 additions & 2 deletions packages/pretty-format/src/plugins/html_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/escape_html';

Expand Down Expand Up @@ -85,7 +91,7 @@ const print = (
element: HTMLElement | HTMLText | HTMLComment,
print: Print,
indent: Indent,
opts: Options,
opts: PluginOptions,
colors: Colors,
): string => {
if (element.nodeType === 3) {
Expand Down
10 changes: 8 additions & 2 deletions packages/pretty-format/src/plugins/immutable_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/print_immutable';

Expand All @@ -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);

Expand Down
10 changes: 8 additions & 2 deletions packages/pretty-format/src/plugins/immutable_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/print_immutable';

Expand All @@ -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);

Expand Down
10 changes: 8 additions & 2 deletions packages/pretty-format/src/plugins/immutable_ordered_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/print_immutable';

Expand All @@ -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);

Expand Down
10 changes: 8 additions & 2 deletions packages/pretty-format/src/plugins/immutable_ordered_set.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/print_immutable';

Expand All @@ -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);

Expand Down
10 changes: 8 additions & 2 deletions packages/pretty-format/src/plugins/immutable_record.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/print_immutable';

Expand All @@ -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);

Expand Down
10 changes: 8 additions & 2 deletions packages/pretty-format/src/plugins/immutable_set.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/print_immutable';

Expand All @@ -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);

Expand Down
10 changes: 8 additions & 2 deletions packages/pretty-format/src/plugins/immutable_stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/print_immutable';

Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions packages/pretty-format/src/plugins/lib/print_immutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ' ';
Expand All @@ -22,7 +22,7 @@ const printImmutable = (
val: any,
print: Print,
indent: Indent,
opts: Options,
opts: PluginOptions,
colors: Colors,
immutableDataStructureName: string,
isMap: boolean,
Expand Down
10 changes: 8 additions & 2 deletions packages/pretty-format/src/plugins/react_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/escape_html';

Expand Down Expand Up @@ -71,7 +77,7 @@ const print = (
element: React$Element<*>,
print: Print,
indent: Indent,
opts: Options,
opts: PluginOptions,
colors: Colors,
) => {
let result = colors.tag.open + '<';
Expand Down
4 changes: 2 additions & 2 deletions packages/pretty-format/src/plugins/react_test_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import type {
Colors,
Indent,
Options,
PluginOptions,
Print,
Plugin,
ReactTestObject,
Expand Down Expand Up @@ -73,7 +73,7 @@ const print = (
instance: ReactTestObject,
print: Print,
indent: Indent,
opts: Options,
opts: PluginOptions,
colors: Colors,
) => {
let closeInNewLine = false;
Expand Down
10 changes: 7 additions & 3 deletions types/PrettyFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ export type StringOrNull = string | null;

export type Options = {|
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,12 +38,18 @@ export type Options = {|
|},
|};

export type PluginOptions = {|
edgeSpacing: string,
min: boolean,
spacing: string,
|};

export type Plugin = {
print: (
val: any,
serialize: Print,
indent: Indent,
opts: Options,
opts: PluginOptions,
colors: Colors,
) => string,
test: any => boolean,
Expand Down

0 comments on commit 48af250

Please sign in to comment.