Skip to content

Commit b458de0

Browse files
ferrannpthymikee
authored andcommitted
Add eslint-config-callstack-io (#7)
1 parent a76eff3 commit b458de0

File tree

5 files changed

+771
-39
lines changed

5 files changed

+771
-39
lines changed

.eslintrc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "callstack-io",
3+
"rules": {
4+
"global-require": 0,
5+
"flowtype/no-weak-types": 0,
6+
"strict": [0, "global"]
7+
}
8+
}

__tests__/snapshotDiff.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ test('collapses diffs and strips ansi by default', () => {
121121
});
122122

123123
test('can expand diff', () => {
124-
expect(snapshotDiff(a, b, {expand: true})).toMatchSnapshot();
124+
expect(snapshotDiff(a, b, { expand: true })).toMatchSnapshot();
125125
});
126126

127127
test('can colorize diff', () => {
128-
expect(snapshotDiff(a, b, {colors: true})).toMatchSnapshot();
128+
expect(snapshotDiff(a, b, { colors: true })).toMatchSnapshot();
129129
});
130130

131131
test('can use contextLines on diff', () => {

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,29 @@
77
"author": "Michał Pierzchała <[email protected]>",
88
"scripts": {
99
"build": "babel src --out-dir build",
10-
"watch": "babel -w src --out-dir build",
11-
"test": "jest",
10+
"lint": "eslint src/ __tests__/",
11+
"flow": "flow check",
1212
"prepublish": "npm run build",
13-
"flow": "flow check"
13+
"test": "jest",
14+
"watch": "babel -w src --out-dir build"
1415
},
1516
"repository": "https://github.com/thymikee/snapshot-diff",
1617
"peerDependencies": {
1718
"jest": ">=16",
1819
"react-test-renderer": ">=15"
1920
},
2021
"dependencies": {
22+
"jest-diff": "^20.0.3",
23+
"pretty-format": "^20.0.3",
2124
"strip-ansi": "^4.0.0"
2225
},
2326
"devDependencies": {
2427
"babel-cli": "^6.24.1",
2528
"babel-preset-env": "^1.6.0",
2629
"babel-preset-flow": "^6.23.0",
2730
"babel-preset-react": "^6.24.1",
31+
"eslint": "^4.3.0",
32+
"eslint-config-callstack-io": "^0.4.0",
2833
"flow-bin": "^0.51.0",
2934
"jest": "^20.0.4",
3035
"react": "^15.6.1",

src/index.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// @flow
2+
23
'use strict';
34

45
const diff = require('jest-diff');
56
const prettyFormat = require('pretty-format');
6-
const {ReactElement} = prettyFormat.plugins;
7+
8+
const { ReactElement } = prettyFormat.plugins;
79
const reactElement = Symbol.for('react.element');
810

911
type Options = {
@@ -39,28 +41,29 @@ const snapshotDiff = (
3941
return difference;
4042
};
4143

42-
const isReactComponent = valueA => valueA && valueA.$$typeof === reactElement;
44+
const isReactComponent = (value: any) =>
45+
value && value.$$typeof === reactElement;
4346

44-
function diffStrings(valueA, valueB, options) {
47+
function diffStrings(valueA: any, valueB: any, options: Options) {
4548
return diff(valueA, valueB, {
4649
expand: options.expand,
4750
contextLines: options.contextLines,
4851
aAnnotation: 'First value',
49-
bAnnotation: 'Second value'
52+
bAnnotation: 'Second value',
5053
});
5154
}
5255

53-
function diffReactComponents(valueA, valueB, options) {
56+
function diffReactComponents(valueA: any, valueB: any, options: Options) {
5457
const renderer = require('react-test-renderer');
5558
const reactValueA = renderer.create(valueA).toJSON();
5659
const reactValueB = renderer.create(valueB).toJSON();
57-
const prettyFormatOptions = {plugins: [ReactElement], min: true};
60+
const prettyFormatOptions = { plugins: [ReactElement], min: true };
5861

5962
return diff(reactValueA, reactValueB, {
6063
expand: options.expand,
6164
contextLines: options.contextLines,
6265
aAnnotation: prettyFormat(valueA, prettyFormatOptions),
63-
bAnnotation: prettyFormat(valueB, prettyFormatOptions)
66+
bAnnotation: prettyFormat(valueB, prettyFormatOptions),
6467
});
6568
}
6669

0 commit comments

Comments
 (0)