Skip to content

Commit 55240b4

Browse files
authored
Merge pull request #138 from danielcaldas/chore/configure-eslint-and-prettier
Configure eslint and prettier
2 parents 096b8a2 + 158c22b commit 55240b4

File tree

6 files changed

+8994
-23
lines changed

6 files changed

+8994
-23
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/docs/**
2+
/lib/**
3+
/node_modules/**

.eslintrc.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = {
2+
extends: ["eslint:recommended", "plugin:jest/recommended"],
3+
globals: {
4+
document: true,
5+
window: true,
6+
__dirname: true,
7+
},
8+
parser: "babel-eslint",
9+
parserOptions: {
10+
ecmaVersion: 6,
11+
ecmaFeatures: {
12+
jsx: true,
13+
},
14+
},
15+
plugins: ["standard", "react", "jest", "babel"],
16+
env: {
17+
browser: true,
18+
},
19+
rules: {
20+
"react/jsx-uses-react": "error",
21+
"react/jsx-uses-vars": "error",
22+
camelcase: "error",
23+
"keyword-spacing": "error",
24+
"max-len": ["error", 120, 4, { ignoreComments: true }],
25+
"max-lines": ["error", { max: 450, skipComments: true }],
26+
"no-useless-constructor": "error",
27+
quotes: ["error", "double"],
28+
},
29+
};

app/index.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ export default class InfiniteScroll extends Component {
8787

8888
componentWillReceiveProps(props) {
8989
// do nothing when dataLength and key are unchanged
90-
if (this.props.key === props.key && this.props.dataLength === props.dataLength) return;
90+
if (
91+
this.props.key === props.key &&
92+
this.props.dataLength === props.dataLength
93+
)
94+
return;
9195

9296
this.actionTriggered = false;
9397
// update state when new data was sent in
@@ -98,8 +102,9 @@ export default class InfiniteScroll extends Component {
98102
}
99103

100104
getScrollableTarget() {
101-
if (this.props.scrollableTarget instanceof HTMLElement) return this.props.scrollableTarget;
102-
if (typeof this.props.scrollableTarget === 'string') {
105+
if (this.props.scrollableTarget instanceof HTMLElement)
106+
return this.props.scrollableTarget;
107+
if (typeof this.props.scrollableTarget === "string") {
103108
return document.getElementById(this.props.scrollableTarget);
104109
}
105110
if (this.props.scrollableTarget === null) {
@@ -119,7 +124,8 @@ export default class InfiniteScroll extends Component {
119124
this.currentY = this.startY;
120125

121126
this._infScroll.style.willChange = "transform";
122-
this._infScroll.style.transition = `transform 0.2s cubic-bezier(0,0,0.31,1)`;
127+
this._infScroll.style.transition =
128+
"transform 0.2s cubic-bezier(0,0,0.31,1)";
123129
}
124130

125131
onMove(evt) {
@@ -143,7 +149,7 @@ export default class InfiniteScroll extends Component {
143149
this.startY}px, 0px)`;
144150
}
145151

146-
onEnd(evt) {
152+
onEnd() {
147153
this.startY = 0;
148154
this.currentY = 0;
149155

@@ -156,9 +162,9 @@ export default class InfiniteScroll extends Component {
156162
requestAnimationFrame(() => {
157163
// this._infScroll
158164
if (this._infScroll) {
159-
this._infScroll.style.overflow = "auto";
160-
this._infScroll.style.transform = "none";
161-
this._infScroll.style.willChange = "none";
165+
this._infScroll.style.overflow = "auto";
166+
this._infScroll.style.transform = "none";
167+
this._infScroll.style.willChange = "none";
162168
}
163169
});
164170
}
@@ -178,7 +184,8 @@ export default class InfiniteScroll extends Component {
178184
}
179185

180186
return (
181-
target.scrollTop + clientHeight >= threshold.value / 100 * target.scrollHeight
187+
target.scrollTop + clientHeight >=
188+
(threshold.value / 100) * target.scrollHeight
182189
);
183190
}
184191

@@ -193,8 +200,8 @@ export default class InfiniteScroll extends Component {
193200
this.props.height || this._scrollableNode
194201
? event.target
195202
: document.documentElement.scrollTop
196-
? document.documentElement
197-
: document.body;
203+
? document.documentElement
204+
: document.body;
198205

199206
// return immediately if the action has already been triggered,
200207
// prevents multiple triggers.
@@ -232,7 +239,7 @@ export default class InfiniteScroll extends Component {
232239
return (
233240
<div style={outerDivStyle}>
234241
<div
235-
className={`infinite-scroll-component ${this.props.className || ''}`}
242+
className={`infinite-scroll-component ${this.props.className || ""}`}
236243
ref={infScroll => (this._infScroll = infScroll)}
237244
style={style}
238245
>

app/utils/threshold.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
11
export const ThresholdUnits = {
2-
Pixel: 'Pixel',
3-
Percent: 'Percent',
2+
Pixel: "Pixel",
3+
Percent: "Percent"
44
};
55

66
const defaultThreshold = {
77
unit: ThresholdUnits.Percent,
8-
value: 0.8,
8+
value: 0.8
99
};
1010

1111
export function parseThreshold(scrollThreshold) {
1212
if (typeof scrollThreshold === "number") {
1313
return {
1414
unit: ThresholdUnits.Percent,
15-
value: scrollThreshold * 100,
15+
value: scrollThreshold * 100
1616
};
1717
}
1818

1919
if (typeof scrollThreshold === "string") {
2020
if (scrollThreshold.match(/^(\d*(\.\d+)?)px$/)) {
2121
return {
2222
unit: ThresholdUnits.Pixel,
23-
value: parseFloat(scrollThreshold),
23+
value: parseFloat(scrollThreshold)
2424
};
2525
}
2626

2727
if (scrollThreshold.match(/^(\d*(\.\d+)?)%$/)) {
2828
return {
2929
unit: ThresholdUnits.Percent,
30-
value: parseFloat(scrollThreshold),
30+
value: parseFloat(scrollThreshold)
3131
};
3232
}
3333

34-
console.warn('scrollThreshold format is invalid. Valid formats: "120px", "50%"...');
34+
console.warn(
35+
"scrollThreshold format is invalid. Valid formats: '120px', '50%'..."
36+
);
3537

3638
return defaultThreshold;
3739
}
3840

39-
console.warn('scrollThreshold should be string or number');
41+
console.warn("scrollThreshold should be string or number");
4042

4143
return defaultThreshold;
4244
}

0 commit comments

Comments
 (0)