Skip to content

Commit 35f3893

Browse files
committed
Limit file diff by adding by newline
1 parent 5409e11 commit 35f3893

6 files changed

+40
-4
lines changed

Diff for: .prettierignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
**/dist/**/*
22
**/node_modules/**/*
3-
src/**/*.js

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"prebuild": "rm -rf dist/",
1212
"lint": "eslint --ext ts --ext tsx src/",
1313
"lint:fix": "yarn run lint -- --fix",
14-
"prettier:fix": "prettier --write \"**/*.{ts,tsx,js}\"",
14+
"prettier:fix": "prettier --write \"**/*.{ts,tsx,js,json}\"",
1515
"test": "jest",
1616
"test:watch": "jest --watch",
1717
"release": "./release.sh",

Diff for: src/formatter/createPropFilter.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ describe('createPropFilter', () => {
77
b: 2,
88
c: 3,
99
};
10-
1110
const filter = createPropFilter(props, ['b']);
11+
1212
const filteredPropKeys = Object.keys(props).filter(filter);
1313

1414
expect(filteredPropKeys).toEqual(['a', 'c']);
@@ -20,11 +20,11 @@ describe('createPropFilter', () => {
2020
b: 2,
2121
c: 3,
2222
};
23-
2423
const filter = createPropFilter(
2524
props,
2625
(val, key) => key !== 'b' && val < 3
2726
);
27+
2828
const filteredPropKeys = Object.keys(props).filter(filter);
2929

3030
expect(filteredPropKeys).toEqual(['a']);

Diff for: src/formatter/formatComplexDataStructure.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default (
1414
options: Options
1515
): string => {
1616
const normalizedValue = sortObject(value);
17+
1718
const stringifiedValue = prettyPrint(normalizedValue, {
1819
transform: (currentObj, prop, originalResult) => {
1920
const currentValue = currentObj[prop];

Diff for: src/formatter/formatFunction.spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,39 @@ describe('formatFunction', () => {
1212
it('should replace a function with noRefCheck without showFunctions option', () => {
1313
expect(formatFunction(hello, {})).toEqual('function noRefCheck() {}');
1414
});
15+
1516
it('should replace a function with noRefCheck if showFunctions is false', () => {
1617
expect(
1718
formatFunction(hello, {
1819
showFunctions: false,
1920
})
2021
).toEqual('function noRefCheck() {}');
2122
});
23+
2224
it('should format a function if showFunctions is true', () => {
2325
expect(
2426
formatFunction(hello, {
2527
showFunctions: true,
2628
})
2729
).toEqual('function hello() {return 1;}');
2830
});
31+
2932
it('should format a function without name if showFunctions is true', () => {
3033
expect(
3134
formatFunction(() => 1, {
3235
showFunctions: true,
3336
})
3437
).toEqual('function () {return 1;}');
3538
});
39+
3640
it('should use the functionValue option', () => {
3741
expect(
3842
formatFunction(hello, {
3943
functionValue: () => '<Test />',
4044
})
4145
).toEqual('<Test />');
4246
});
47+
4348
it('should use the functionValue option even if showFunctions is true', () => {
4449
expect(
4550
formatFunction(hello, {
@@ -48,6 +53,7 @@ describe('formatFunction', () => {
4853
})
4954
).toEqual('<Test />');
5055
});
56+
5157
it('should use the functionValue option even if showFunctions is false', () => {
5258
expect(
5359
formatFunction(hello, {

Diff for: src/formatter/formatProp.spec.ts

+30
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
import formatProp from './formatProp';
22
import formatPropValue from './formatPropValue';
3+
34
jest.mock('./formatPropValue');
5+
46
const defaultOptions = {
57
useBooleanShorthandSyntax: true,
68
tabStop: 2,
79
};
10+
811
describe('formatProp', () => {
912
beforeEach(() => {
1013
jest.clearAllMocks();
1114
jest.resetAllMocks();
1215
});
16+
1317
it('should format prop with only a value', () => {
1418
formatPropValue.mockReturnValue('"MockedPropValue"');
19+
1520
expect(
1621
formatProp('foo', true, 'bar', false, null, true, 0, defaultOptions)
1722
).toEqual({
@@ -20,15 +25,18 @@ describe('formatProp', () => {
2025
foo="MockedPropValue"`,
2126
isMultilineAttribute: false,
2227
});
28+
2329
expect(formatPropValue).toHaveBeenCalledWith(
2430
'bar',
2531
true,
2632
0,
2733
defaultOptions
2834
);
2935
});
36+
3037
it('should format prop with only a default value', () => {
3138
formatPropValue.mockReturnValue('"MockedPropValue"');
39+
3240
expect(
3341
formatProp('foo', false, null, true, 'baz', true, 0, defaultOptions)
3442
).toEqual({
@@ -37,15 +45,18 @@ describe('formatProp', () => {
3745
foo="MockedPropValue"`,
3846
isMultilineAttribute: false,
3947
});
48+
4049
expect(formatPropValue).toHaveBeenCalledWith(
4150
'baz',
4251
true,
4352
0,
4453
defaultOptions
4554
);
4655
});
56+
4757
it('should format prop with a value and a default value', () => {
4858
formatPropValue.mockReturnValue('"MockedPropValue"');
59+
4960
expect(
5061
formatProp('foo', true, 'bar', true, 'baz', true, 0, defaultOptions)
5162
).toEqual({
@@ -54,19 +65,22 @@ describe('formatProp', () => {
5465
foo="MockedPropValue"`,
5566
isMultilineAttribute: false,
5667
});
68+
5769
expect(formatPropValue).toHaveBeenCalledWith(
5870
'bar',
5971
true,
6072
0,
6173
defaultOptions
6274
);
6375
});
76+
6477
it('should format a truthy boolean prop (with short syntax)', () => {
6578
const options = {
6679
useBooleanShorthandSyntax: true,
6780
tabStop: 2,
6881
};
6982
formatPropValue.mockReturnValue('{true}');
83+
7084
expect(
7185
formatProp('foo', true, true, false, false, true, 0, options)
7286
).toEqual({
@@ -75,29 +89,35 @@ describe('formatProp', () => {
7589
foo`,
7690
isMultilineAttribute: false,
7791
});
92+
7893
expect(formatPropValue).toHaveBeenCalledWith(true, true, 0, options);
7994
});
95+
8096
it('should ignore a falsy boolean prop (with short syntax)', () => {
8197
const options = {
8298
useBooleanShorthandSyntax: true,
8399
tabStop: 2,
84100
};
85101
formatPropValue.mockReturnValue('{false}');
102+
86103
expect(
87104
formatProp('foo', true, false, false, null, true, 0, options)
88105
).toEqual({
89106
attributeFormattedInline: '',
90107
attributeFormattedMultiline: '',
91108
isMultilineAttribute: false,
92109
});
110+
93111
expect(formatPropValue).toHaveBeenCalledWith(false, true, 0, options);
94112
});
113+
95114
it('should format a truthy boolean prop (with explicit syntax)', () => {
96115
const options = {
97116
useBooleanShorthandSyntax: false,
98117
tabStop: 2,
99118
};
100119
formatPropValue.mockReturnValue('{true}');
120+
101121
expect(
102122
formatProp('foo', true, true, false, false, true, 0, options)
103123
).toEqual({
@@ -106,14 +126,17 @@ describe('formatProp', () => {
106126
foo={true}`,
107127
isMultilineAttribute: false,
108128
});
129+
109130
expect(formatPropValue).toHaveBeenCalledWith(true, true, 0, options);
110131
});
132+
111133
it('should format a falsy boolean prop (with explicit syntax)', () => {
112134
const options = {
113135
useBooleanShorthandSyntax: false,
114136
tabStop: 2,
115137
};
116138
formatPropValue.mockReturnValue('{false}');
139+
117140
expect(
118141
formatProp('foo', true, false, false, false, true, 0, options)
119142
).toEqual({
@@ -122,13 +145,16 @@ describe('formatProp', () => {
122145
foo={false}`,
123146
isMultilineAttribute: false,
124147
});
148+
125149
expect(formatPropValue).toHaveBeenCalledWith(false, true, 0, options);
126150
});
151+
127152
it('should format a mulitline props', () => {
128153
formatPropValue.mockReturnValue(`{[
129154
"a",
130155
"b"
131156
]}`);
157+
132158
expect(
133159
formatProp(
134160
'foo',
@@ -152,13 +178,15 @@ describe('formatProp', () => {
152178
]}`,
153179
isMultilineAttribute: true,
154180
});
181+
155182
expect(formatPropValue).toHaveBeenCalledWith(
156183
['a', 'b'],
157184
false,
158185
0,
159186
defaultOptions
160187
);
161188
});
189+
162190
it('should indent the formatted string', () => {
163191
/*
164192
* lvl 4 and tabStop 2 :
@@ -171,6 +199,7 @@ describe('formatProp', () => {
171199
tabStop: 2,
172200
};
173201
formatPropValue.mockReturnValue('"MockedPropValue"');
202+
174203
expect(
175204
formatProp('foo', true, 'bar', false, null, true, 4, options)
176205
).toEqual({
@@ -180,6 +209,7 @@ describe('formatProp', () => {
180209
// 10 spaces
181210
isMultilineAttribute: false,
182211
});
212+
183213
expect(formatPropValue).toHaveBeenCalledWith('bar', true, 4, options);
184214
});
185215
});

0 commit comments

Comments
 (0)