Skip to content

Commit de3e36d

Browse files
committed
Add lint staged
1 parent 2deea2e commit de3e36d

File tree

7 files changed

+649
-19
lines changed

7 files changed

+649
-19
lines changed

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ module.exports = {
1616
'prettier/@typescript-eslint',
1717
'prettier/react',
1818
],
19+
rules: {
20+
'@typescript-eslint/prefer-regexp-exec': 1,
21+
},
1922
};

lint-staged.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
'**/*.ts?(x)': () => 'tsc -p tsconfig.json --noEmit',
3+
};

package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
"eslint": "^6.5.1",
5555
"eslint-config-prettier": "^6.3.0",
5656
"eslint-plugin-react": "^7.15.0",
57+
"husky": ">=1",
58+
"lint-staged": ">=8",
5759
"microbundle": "^0.11.0",
5860
"prettier": "1.18.2",
5961
"react": "^16.10.1",
@@ -63,5 +65,24 @@
6365
},
6466
"dependencies": {
6567
"throttle-debounce": "^2.1.0"
68+
},
69+
"husky": {
70+
"hooks": {
71+
"pre-commit": "lint-staged"
72+
}
73+
},
74+
"lint-staged": {
75+
"*.{js,css,json,md}": [
76+
"prettier --write",
77+
"git add"
78+
],
79+
"*.js": [
80+
"eslint --fix",
81+
"git add"
82+
],
83+
"*.{ts,tsx}": [
84+
"eslint --fix",
85+
"git add"
86+
]
6687
}
6788
}

src/index.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ export default class InfiniteScroll extends Component<Props, State> {
4040
pullToRefreshThresholdBreached: false,
4141
};
4242

43-
this.onScrollListener = this.onScrollListener.bind(this);
4443
this.throttledOnScrollListener = throttle(150, this.onScrollListener).bind(
4544
this
4645
);
4746
this.onStart = this.onStart.bind(this);
4847
this.onMove = this.onMove.bind(this);
4948
this.onEnd = this.onEnd.bind(this);
50-
this.getScrollableTarget = this.getScrollableTarget.bind(this);
5149
}
5250

5351
private throttledOnScrollListener: (e: MouseEvent) => void;
@@ -134,7 +132,7 @@ export default class InfiniteScroll extends Component<Props, State> {
134132
}
135133
}
136134

137-
componentWillReceiveProps(props: Props) {
135+
UNSAFE_componentWillReceiveProps(props: Props) {
138136
// do nothing when dataLength and key are unchanged
139137
if (
140138
this.props.key === props.key &&
@@ -150,7 +148,7 @@ export default class InfiniteScroll extends Component<Props, State> {
150148
});
151149
}
152150

153-
getScrollableTarget() {
151+
getScrollableTarget = () => {
154152
if (this.props.scrollableTarget instanceof HTMLElement)
155153
return this.props.scrollableTarget;
156154
if (typeof this.props.scrollableTarget === 'string') {
@@ -163,7 +161,7 @@ export default class InfiniteScroll extends Component<Props, State> {
163161
`);
164162
}
165163
return null;
166-
}
164+
};
167165

168166
onStart: EventListener = (evt: Event) => {
169167
if (this.lastScrollTop) return;
@@ -257,7 +255,7 @@ export default class InfiniteScroll extends Component<Props, State> {
257255
);
258256
}
259257

260-
onScrollListener(event: MouseEvent) {
258+
onScrollListener = (event: MouseEvent) => {
261259
if (typeof this.props.onScroll === 'function') {
262260
// Execute this callback in next tick so that it does not affect the
263261
// functionality of the library.
@@ -285,7 +283,7 @@ export default class InfiniteScroll extends Component<Props, State> {
285283
}
286284

287285
this.lastScrollTop = target.scrollTop;
288-
}
286+
};
289287

290288
render() {
291289
const style = {

src/stories/WindowInfiniteScrollComponent.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ export default class WindowInfiniteScrollComponent extends React.Component<
2727
dataLength={this.state.data.length}
2828
>
2929
{this.state.data.map((_, i) => (
30-
<div style={{ height: 30, margin: 4, border: '1px solid hotpink' }}>
30+
<div
31+
key={i}
32+
style={{ height: 30, margin: 4, border: '1px solid hotpink' }}
33+
>
3134
#{i + 1} row
3235
</div>
3336
))}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@
5757
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
5858
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
5959
},
60-
"include": ["src/**/*"]
60+
"include": ["src/**/*", "lint-staged.config.js"]
6161
}

0 commit comments

Comments
 (0)