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 all commits
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
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 @@ -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) {
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