Skip to content

Commit 5709064

Browse files
committed
Improve linting
1 parent 291a31a commit 5709064

9 files changed

+67
-61
lines changed

.eslintrc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"browser": true,
66
"node": true,
77
"mocha": true,
8-
"es6": true
8+
"es6": true,
9+
"jest": true
910
},
1011
"plugins": [
1112
"react",
@@ -81,7 +82,7 @@
8182
"block-spacing": [1, "always"],
8283
"brace-style": 1,
8384
"camelcase": 1,
84-
"comma-dangle": 1,
85+
"comma-dangle": [1, "always-multiline"],
8586
"comma-spacing": 1,
8687
"comma-style": 1,
8788
"computed-property-spacing": 1,

src/components/LazyLoadComponent.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class LazyLoadComponent extends React.Component {
1111
const { afterLoad, beforeLoad, scrollPosition, visibleByDefault } = props;
1212

1313
this.state = {
14-
visible: visibleByDefault
14+
visible: visibleByDefault,
1515
};
1616

1717
if (visibleByDefault) {
@@ -35,7 +35,7 @@ class LazyLoadComponent extends React.Component {
3535
onVisible() {
3636
this.props.beforeLoad();
3737
this.setState({
38-
visible: true
38+
visible: true,
3939
});
4040
}
4141

@@ -77,13 +77,13 @@ class LazyLoadComponent extends React.Component {
7777
LazyLoadComponent.propTypes = {
7878
afterLoad: PropTypes.func,
7979
beforeLoad: PropTypes.func,
80-
visibleByDefault: PropTypes.bool
80+
visibleByDefault: PropTypes.bool,
8181
};
8282

8383
LazyLoadComponent.defaultProps = {
8484
afterLoad: () => ({}),
8585
beforeLoad: () => ({}),
86-
visibleByDefault: false
86+
visibleByDefault: false,
8787
};
8888

8989
export default LazyLoadComponent;

src/components/LazyLoadComponent.spec.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint max-len: 0 */
12
import React from 'react';
23
import ReactTestUtils from 'react-dom/test-utils';
34
import { configure, mount } from 'enzyme';
@@ -11,14 +12,14 @@ configure({ adapter: new Adapter() });
1112

1213
const {
1314
scryRenderedComponentsWithType,
14-
scryRenderedDOMComponentsWithTag
15+
scryRenderedDOMComponentsWithTag,
1516
} = ReactTestUtils;
1617

1718
describe('LazyLoadComponent', function() {
1819
it('renders a PlaceholderWithTracking when scrollPosition is undefined', function() {
1920
const lazyLoadComponent = mount(
2021
<LazyLoadComponent
21-
style={{marginTop: 100000}}>>
22+
style={{ marginTop: 100000 }}>
2223
<p>Lorem Ipsum</p>
2324
</LazyLoadComponent>
2425
);
@@ -32,8 +33,8 @@ describe('LazyLoadComponent', function() {
3233
it('renders a PlaceholderWithoutTracking when scrollPosition is defined', function() {
3334
const lazyLoadComponent = mount(
3435
<LazyLoadComponent
35-
scrollPosition={{ x: 0, y: 0}}
36-
style={{marginTop: 100000}}>>
36+
scrollPosition={{ x: 0, y: 0 }}
37+
style={{ marginTop: 100000 }}>
3738
<p>Lorem Ipsum</p>
3839
</LazyLoadComponent>
3940
);
@@ -64,7 +65,7 @@ describe('LazyLoadComponent', function() {
6465
const lazyLoadComponent = mount(
6566
<LazyLoadComponent
6667
beforeLoad={beforeLoad}
67-
style={{marginTop: 100000}}>
68+
style={{ marginTop: 100000 }}>
6869
<p>Lorem Ipsum</p>
6970
</LazyLoadComponent>
7071
);
@@ -79,7 +80,7 @@ describe('LazyLoadComponent', function() {
7980
const lazyLoadComponent = mount(
8081
<LazyLoadComponent
8182
afterLoad={afterLoad}
82-
style={{marginTop: 100000}}>
83+
style={{ marginTop: 100000 }}>
8384
<p>Lorem Ipsum</p>
8485
</LazyLoadComponent>
8586
);
@@ -96,7 +97,7 @@ describe('LazyLoadComponent', function() {
9697
<LazyLoadComponent
9798
afterLoad={afterLoad}
9899
beforeLoad={beforeLoad}
99-
style={{marginTop: 100000}}>
100+
style={{ marginTop: 100000 }}>
100101
<p>Lorem Ipsum</p>
101102
</LazyLoadComponent>
102103
);

src/components/LazyLoadImage.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class LazyLoadImage extends React.Component {
88
super(props);
99

1010
this.state = {
11-
loaded: false
11+
loaded: false,
1212
};
1313
}
1414

@@ -21,7 +21,7 @@ class LazyLoadImage extends React.Component {
2121
this.props.afterLoad();
2222

2323
this.setState({
24-
loaded: true
24+
loaded: true,
2525
});
2626
};
2727
}
@@ -76,7 +76,7 @@ class LazyLoadImage extends React.Component {
7676
color: 'transparent',
7777
display: 'inline-block',
7878
height: height,
79-
width: width
79+
width: width,
8080
}}>
8181
{lazyLoadImage}
8282
</span>
@@ -102,12 +102,12 @@ class LazyLoadImage extends React.Component {
102102
LazyLoadImage.propTypes = {
103103
afterLoad: PropTypes.func,
104104
effect: PropTypes.string,
105-
placeholderSrc: PropTypes.string
105+
placeholderSrc: PropTypes.string,
106106
};
107107

108108
LazyLoadImage.defaultProps = {
109109
afterLoad: () => ({}),
110-
effect: ''
110+
effect: '',
111111
};
112112

113113
export default LazyLoadImage;

src/components/LazyLoadImage.spec.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint max-len: 0 */
2+
/* eslint max-statements: 0 */
13
import React from 'react';
24
import ReactTestUtils from 'react-dom/test-utils';
35
import { configure, mount } from 'enzyme';
@@ -13,7 +15,7 @@ const {
1315
findRenderedDOMComponentWithTag,
1416
scryRenderedDOMComponentsWithClass,
1517
scryRenderedDOMComponentsWithTag,
16-
Simulate
18+
Simulate,
1719
} = ReactTestUtils;
1820

1921
describe('LazyLoadImage', function() {
@@ -23,10 +25,10 @@ describe('LazyLoadImage', function() {
2325
delayMethod: 'debounce',
2426
delayTime: 600,
2527
placeholder: null,
26-
scrollPosition: {x: 0, y: 0},
28+
scrollPosition: { x: 0, y: 0 },
2729
style: {},
2830
src: 'http://localhost/lorem-ipsum.jpg',
29-
visibleByDefault: false
31+
visibleByDefault: false,
3032
};
3133
const lazyLoadImage = mount(
3234
<LazyLoadImage
@@ -104,7 +106,7 @@ describe('LazyLoadImage', function() {
104106
it('renders placeholder background when defined', function() {
105107
const lazyLoadImage = mount(
106108
<LazyLoadImage
107-
placeholderSrc='lorem-ipsum.jpg'
109+
placeholderSrc="lorem-ipsum.jpg"
108110
visibleByDefault={false} />
109111
);
110112

@@ -116,7 +118,7 @@ describe('LazyLoadImage', function() {
116118
it('doesn\'t render placeholder background when visibleByDefault is true', function() {
117119
const lazyLoadImage = mount(
118120
<LazyLoadImage
119-
placeholderSrc='lorem-ipsum.jpg'
121+
placeholderSrc="lorem-ipsum.jpg"
120122
visibleByDefault={true} />
121123
);
122124

src/components/PlaceholderWithoutTracking.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ class PlaceholderWithoutTracking extends React.Component {
2020
const style = ReactDOM.findDOMNode(this.placeholder).style;
2121
const margin = {
2222
left: parseInt(style.getPropertyValue('margin-left'), 10) || 0,
23-
top: parseInt(style.getPropertyValue('margin-top'), 10) || 0
23+
top: parseInt(style.getPropertyValue('margin-top'), 10) || 0,
2424
};
2525

2626
return {
2727
bottom: scrollPosition.y + boundingRect.bottom + margin.top,
2828
left: scrollPosition.x + boundingRect.left + margin.left,
2929
right: scrollPosition.x + boundingRect.right + margin.left,
30-
top: scrollPosition.y + boundingRect.top + margin.top
30+
top: scrollPosition.y + boundingRect.top + margin.top,
3131
};
3232
}
3333

@@ -42,7 +42,7 @@ class PlaceholderWithoutTracking extends React.Component {
4242
bottom: scrollPosition.y + window.innerHeight,
4343
left: scrollPosition.x,
4444
right: scrollPosition.x + window.innerWidth,
45-
top: scrollPosition.y
45+
top: scrollPosition.y,
4646
};
4747

4848
return Boolean(viewport.top - threshold <= boundingBox.bottom &&
@@ -78,21 +78,21 @@ PlaceholderWithoutTracking.propTypes = {
7878
onVisible: PropTypes.func.isRequired,
7979
scrollPosition: PropTypes.shape({
8080
x: PropTypes.number.isRequired,
81-
y: PropTypes.number.isRequired
81+
y: PropTypes.number.isRequired,
8282
}).isRequired,
8383
className: PropTypes.string,
8484
height: PropTypes.number,
8585
placeholder: PropTypes.element,
8686
threshold: PropTypes.number,
87-
width: PropTypes.number
87+
width: PropTypes.number,
8888
};
8989

9090
PlaceholderWithoutTracking.defaultProps = {
9191
className: '',
9292
height: 0,
9393
placeholder: null,
9494
threshold: 100,
95-
width: 0
95+
width: 0,
9696
};
9797

9898
export default PlaceholderWithoutTracking;

src/components/PlaceholderWithoutTracking.spec.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint require-jsdoc: 0 */
2+
/* eslint max-len: 0 */
13
import React from 'react';
24
import ReactTestUtils from 'react-dom/test-utils';
35
import { configure, mount } from 'enzyme';
@@ -8,16 +10,16 @@ import PlaceholderWithoutTracking from './PlaceholderWithoutTracking.jsx';
810
configure({ adapter: new Adapter() });
911

1012
const {
11-
scryRenderedDOMComponentsWithTag
13+
scryRenderedDOMComponentsWithTag,
1214
} = ReactTestUtils;
1315

1416
describe('PlaceholderWithoutTracking', function() {
1517
function renderPlaceholderWithoutTracking({
16-
onVisible = () => null,
17-
placeholder = null,
18-
scrollPosition = {x: 0, y: 0},
19-
style = {}
20-
} = {}) {
18+
onVisible = () => null,
19+
placeholder = null,
20+
scrollPosition = { x: 0, y: 0 },
21+
style = {},
22+
} = {}) {
2123
return mount(
2224
<PlaceholderWithoutTracking
2325
onVisible={onVisible}
@@ -38,13 +40,13 @@ describe('PlaceholderWithoutTracking', function() {
3840
left: -offsetX,
3941
right: -offsetX,
4042
top: -offsetY,
41-
width: 0
43+
width: 0,
4244
});
4345

4446
component.instance().placeholder.getBoundingClientRect = myMock;
4547

4648
component.setProps({
47-
scrollPosition: {x: offsetX, y: offsetY}
49+
scrollPosition: { x: offsetX, y: offsetY },
4850
});
4951
}
5052

@@ -62,21 +64,21 @@ describe('PlaceholderWithoutTracking', function() {
6264

6365
it('renders the default placeholder when it\'s not in the viewport', function() {
6466
const component = renderPlaceholderWithoutTracking({
65-
style: {marginTop: 100000}
67+
style: { marginTop: 100000 },
6668
});
6769

6870
expectParagraphs(component, 0);
6971
expectPlaceholders(component, 1);
7072
});
7173

7274
it('renders the prop placeholder when it\'s not in the viewport', function() {
73-
const style = {marginTop: 100000};
75+
const style = { marginTop: 100000 };
7476
const placeholder = (
7577
<strong style={style}></strong>
7678
);
7779
const component = renderPlaceholderWithoutTracking({
7880
placeholder,
79-
style
81+
style,
8082
});
8183

8284
expectParagraphs(component, 0);
@@ -87,7 +89,7 @@ describe('PlaceholderWithoutTracking', function() {
8789
const onVisible = jest.fn();
8890
const component = renderPlaceholderWithoutTracking({
8991
onVisible,
90-
style: {marginTop: 100000}
92+
style: { marginTop: 100000 },
9193
});
9294

9395
expect(onVisible).toHaveBeenCalledTimes(0);
@@ -96,7 +98,7 @@ describe('PlaceholderWithoutTracking', function() {
9698
it('triggers onVisible when the image is in the viewport', function() {
9799
const onVisible = jest.fn();
98100
const component = renderPlaceholderWithoutTracking({
99-
onVisible
101+
onVisible,
100102
});
101103

102104
expect(onVisible).toHaveBeenCalledTimes(1);
@@ -107,7 +109,7 @@ describe('PlaceholderWithoutTracking', function() {
107109
const offset = 100000;
108110
const component = renderPlaceholderWithoutTracking({
109111
onVisible,
110-
style: {marginTop: offset}
112+
style: { marginTop: offset },
111113
});
112114

113115
simulateScroll(component, 0, offset);
@@ -120,10 +122,10 @@ describe('PlaceholderWithoutTracking', function() {
120122
const offset = 100000;
121123
const component = renderPlaceholderWithoutTracking({
122124
onVisible,
123-
style: {marginLeft: offset}
125+
style: { marginLeft: offset },
124126
});
125127

126-
simulateScroll(component, offset, 0);
128+
simulateScroll(component, offset, 0);
127129

128130
expect(onVisible).toHaveBeenCalledTimes(1);
129131
});

src/hoc/trackWindowScroll.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ const trackWindowScroll = (BaseComponent) => {
1919
this.state = {
2020
scrollPosition: {
2121
x: window.scrollX || window.pageXOffset,
22-
y: window.scrollY || window.pageYOffset
23-
}
22+
y: window.scrollY || window.pageYOffset,
23+
},
2424
};
2525
}
2626

@@ -38,8 +38,8 @@ const trackWindowScroll = (BaseComponent) => {
3838
this.setState({
3939
scrollPosition: {
4040
x: window.scrollX || window.pageXOffset,
41-
y: window.scrollY || window.pageYOffset
42-
}
41+
y: window.scrollY || window.pageYOffset,
42+
},
4343
});
4444
}
4545

@@ -56,12 +56,12 @@ const trackWindowScroll = (BaseComponent) => {
5656

5757
ScrollAwareComponent.propTypes = {
5858
delayMethod: PropTypes.oneOf(['debounce', 'throttle']),
59-
delayTime: PropTypes.number
59+
delayTime: PropTypes.number,
6060
};
6161

6262
ScrollAwareComponent.defaultProps = {
6363
delayMethod: 'throttle',
64-
delayTime: 300
64+
delayTime: 300,
6565
};
6666

6767
return ScrollAwareComponent;

0 commit comments

Comments
 (0)