Skip to content

Commit a5123fb

Browse files
refactor: eslint
1 parent 2a0a998 commit a5123fb

17 files changed

+914
-99
lines changed

.eslintrc.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
module.exports = {
2+
env: {
3+
browser: true,
4+
es2021: true,
5+
},
6+
extends: ['plugin:react/recommended', 'react-app', 'airbnb', 'plugin:prettier/recommended'],
27
parser: 'babel-eslint',
3-
extends: ['react-app', 'airbnb', 'prettier', 'prettier/react'],
4-
plugins: ['prettier'],
5-
globals: {
6-
// 这里填入你的项目需要的全局变量
7-
// 这里值为 false 表示这个全局变量不允许被重新赋值,比如:
8-
//
9-
// React: false,
10-
// ReactDOM: false
8+
parserOptions: {
9+
ecmaFeatures: {
10+
jsx: true,
11+
},
12+
ecmaVersion: 2021,
13+
sourceType: 'module',
1114
},
15+
plugins: ['react', 'prettier'],
1216
rules: {
1317
// 这里填入你的项目需要的个性化配置
14-
'prettier/prettier': 'error',
1518
'react-hooks/rules-of-hooks': 'error', // Checks rules of Hooks
1619
'react-hooks/exhaustive-deps': 'error', // Checks effect dependencies
1720
yoda: [2, 'always'],
@@ -28,4 +31,5 @@ module.exports = {
2831
'react/jsx-props-no-spreading': 0,
2932
'no-empty': ['error', { allowEmptyCatch: true }],
3033
},
34+
ignorePatterns: ['build', 'dist', 'node_modules'],
3135
};

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ npm-debug.log*
2323
yarn-debug.log*
2424
yarn-error.log*
2525
*.log
26+
___*

package.json

+19
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,34 @@
2828
"nrm": "nrm use taobao"
2929
},
3030
"devDependencies": {
31+
"@ant-design/icons": "^4.7.0",
3132
"@babel/core": "^7.15.8",
3233
"@rollup/plugin-babel": "^5.3.0",
3334
"@rollup/plugin-commonjs": "^21.0.0",
3435
"@rollup/plugin-node-resolve": "^13.0.5",
3536
"@rollup/plugin-url": "^6.1.0",
3637
"@svgr/rollup": "^5.5.0",
38+
"antd": "^4.16.13",
39+
"babel-eslint": "^10.1.0",
40+
"eslint": "^7.32.0",
41+
"eslint-config-airbnb": "^18.2.1",
42+
"eslint-config-prettier": "^8.3.0",
43+
"eslint-config-react-app": "^6.0.0",
44+
"eslint-plugin-flowtype": "^6.1.0",
45+
"eslint-plugin-import": "^2.25.2",
46+
"eslint-plugin-jsx-a11y": "^6.4.1",
47+
"eslint-plugin-prettier": "^4.0.0",
48+
"eslint-plugin-react": "^7.26.1",
49+
"eslint-plugin-react-hooks": "^4.2.0",
50+
"fbemitter": "^3.0.0",
3751
"gh-pages": "^3.2.3",
3852
"less": "^4.1.2",
53+
"numeral": "^2.0.6",
3954
"postcss": "^8.3.9",
55+
"prettier": "^2.4.1",
56+
"prop-types": "^15.7.2",
57+
"react": "^17.0.2",
58+
"react-swf": "^1.0.7",
4059
"rollup": "^2.58.0",
4160
"rollup-plugin-filesize": "^9.1.1",
4261
"rollup-plugin-peer-deps-external": "^2.2.4",

scripts/rollup.config.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
// import resolve from '@rollup/plugin-node-resolve';
2-
import { nodeResolve } from "@rollup/plugin-node-resolve";
3-
import commonjs from "@rollup/plugin-commonjs";
4-
import { babel } from "@rollup/plugin-babel";
5-
import external from "rollup-plugin-peer-deps-external";
6-
import postcss from "rollup-plugin-postcss";
7-
import url from "@rollup/plugin-url";
8-
import svgr from "@svgr/rollup";
9-
import filesize from "rollup-plugin-filesize";
2+
import { nodeResolve } from '@rollup/plugin-node-resolve';
3+
import commonjs from '@rollup/plugin-commonjs';
4+
import { babel } from '@rollup/plugin-babel';
5+
import external from 'rollup-plugin-peer-deps-external';
6+
import postcss from 'rollup-plugin-postcss';
7+
import url from '@rollup/plugin-url';
8+
import svgr from '@svgr/rollup';
9+
import filesize from 'rollup-plugin-filesize';
1010

11-
import pkg from "../package.json";
11+
import pkg from '../package.json';
1212

1313
export default {
14-
input: "src/index.js",
14+
input: 'src/index.js',
1515
output: [
1616
{
1717
file: pkg.browser,
1818
name: pkg.name,
19-
format: "umd",
19+
format: 'umd',
2020
sourcemap: true,
2121
globals: {
22-
react: "React",
23-
"prop-types": "PropTypes",
24-
"numeral": "numeral",
25-
"antd": "antd",
26-
"@ant-design/icons": "@ant-design/icons",
27-
"react-swf": "ReactSWF",
28-
"fbemitter": "fbemitter",
22+
react: 'React',
23+
'prop-types': 'PropTypes',
24+
numeral: 'numeral',
25+
antd: 'antd',
26+
'@ant-design/icons': '@ant-design/icons',
27+
'react-swf': 'ReactSWF',
28+
fbemitter: 'fbemitter',
2929
},
3030
},
3131
],
@@ -37,23 +37,23 @@ export default {
3737
url(),
3838
url({
3939
limit: 0,
40-
include: ["**/*.swf"],
40+
include: ['**/*.swf'],
4141
emitFiles: true,
42-
fileName: "[name][extname]",
42+
fileName: '[name][extname]',
4343
}),
4444
svgr(),
4545
babel({
4646
babelrc: false,
47-
exclude: "node_modules/**",
48-
babelHelpers: "bundled",
47+
exclude: 'node_modules/**',
48+
babelHelpers: 'bundled',
4949
presets: [
5050
[
51-
"@babel/preset-env",
51+
'@babel/preset-env',
5252
{
5353
modules: false,
5454
},
5555
],
56-
"@babel/preset-react",
56+
'@babel/preset-react',
5757
],
5858
}),
5959
nodeResolve(),

src/GrindPlayer/GrindPlayer.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class GrindPlayer {
2727
this.el = document.getElementById(this.id);
2828
// this.el.addEventListener('mediaError', () => );
2929
}),
30-
emitter.addListener(`${this.id}.mediaSize`, data => {
30+
emitter.addListener(`${this.id}.mediaSize`, (data) => {
3131
if (0 === data.videoHeight && 0 === data.videoWidth) {
3232
this.emitter.emit('canplay');
3333
} else {
@@ -41,11 +41,11 @@ class GrindPlayer {
4141
emitter.addListener(`${this.id}.complete`, () => this.emitter.emit('ended')),
4242
emitter.addListener(`${this.id}.buffering`, () => this.emitter.emit('waiting')),
4343

44-
emitter.addListener(`${this.id}.durationChange`, e => this.emitter.emit('durationchange', e)),
45-
emitter.addListener(`${this.id}.timeChange`, e => this.emitter.emit('timeupdate', e)),
46-
emitter.addListener(`${this.id}.progress`, e => this.emitter.emit('progress', e)),
44+
emitter.addListener(`${this.id}.durationChange`, (e) => this.emitter.emit('durationchange', e)),
45+
emitter.addListener(`${this.id}.timeChange`, (e) => this.emitter.emit('timeupdate', e)),
46+
emitter.addListener(`${this.id}.progress`, (e) => this.emitter.emit('progress', e)),
4747

48-
emitter.addListener(`${this.id}.volumeChange`, e => this.emitter.emit('volumechange', e)),
48+
emitter.addListener(`${this.id}.volumeChange`, (e) => this.emitter.emit('volumechange', e)),
4949
];
5050
}
5151

@@ -68,7 +68,7 @@ class GrindPlayer {
6868
if (!this.eventMap) {
6969
return;
7070
}
71-
this.eventMap = this.eventMap.filter(it => {
71+
this.eventMap = this.eventMap.filter((it) => {
7272
if (it.event !== event) {
7373
return true;
7474
}
@@ -82,12 +82,12 @@ class GrindPlayer {
8282

8383
destroy() {
8484
if (this.eventMap) {
85-
this.eventMap.map(it => it.token.remove());
85+
this.eventMap.map((it) => it.token.remove());
8686
delete this.eventMap;
8787
}
8888

8989
if (this.tokenList) {
90-
this.tokenList.map(it => it.remove());
90+
this.tokenList.map((it) => it.remove());
9191
delete this.tokenList;
9292
}
9393

src/GrindPlayer/useTime.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import React from 'react';
22

33
export default ({ ref, dispatch }) => {
44
const onDurationChange = React.useCallback(
5-
e => {
5+
(e) => {
66
const v = e.duration;
77
dispatch({ type: 'update', payload: { duration: Number.isNaN(v) || Number.isFinite(v) || !v ? v : 0 } });
88
},
99
[dispatch],
1010
);
1111

1212
const onTimeUpdate = React.useCallback(
13-
e => {
13+
(e) => {
1414
if (Number.isNaN(e.currentTime)) {
1515
return;
1616
}
@@ -19,12 +19,13 @@ export default ({ ref, dispatch }) => {
1919
[dispatch],
2020
);
2121

22-
const onProgress = React.useCallback(e => dispatch({ type: 'update', payload: { buffered: e.buffered } }), [
23-
dispatch,
24-
]);
22+
const onProgress = React.useCallback(
23+
(e) => dispatch({ type: 'update', payload: { buffered: e.buffered } }),
24+
[dispatch],
25+
);
2526

2627
const changeCurrentTime = React.useCallback(
27-
t => {
28+
(t) => {
2829
const v = parseFloat(t);
2930
if (Number.isNaN(v) || !ref.current || !ref.current.player) {
3031
return;

src/GrindPlayer/useVolume.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22

33
export default ({ ref, dispatch }) => {
4-
const onVolumeChange = React.useCallback(e => dispatch({ type: 'update', payload: e }), [dispatch]);
4+
const onVolumeChange = React.useCallback((e) => dispatch({ type: 'update', payload: e }), [dispatch]);
55

66
const onMutedClick = React.useCallback(() => {
77
if (!ref.current || !ref.current.player) {
@@ -15,7 +15,7 @@ export default ({ ref, dispatch }) => {
1515
}, [ref]);
1616

1717
const changeVolume = React.useCallback(
18-
v => {
18+
(v) => {
1919
if (ref.current && ref.current.player) {
2020
ref.current.player.invoker('setVolume', v);
2121
}

src/ReactPlayerSkin/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const ReactPlayerSkin = React.memo(
6060
const onBodyClick = React.useCallback(() => setVisible(false), []);
6161

6262
const onMenuClick = React.useCallback(
63-
e => {
63+
(e) => {
6464
changePlaybackRate(parseFloat(e.key, 10));
6565
setVisible(false);
6666
},
@@ -161,7 +161,7 @@ const ReactPlayerSkin = React.memo(
161161
</button>
162162
)}
163163
<span className={styles.volumeSlider}>
164-
<Slider value={volume * 100} onChange={v => changeVolume(v / 100)} max={100} />
164+
<Slider value={volume * 100} onChange={(v) => changeVolume(v / 100)} max={100} />
165165
</span>
166166
</span>
167167
<span className={styles.controlText}>

src/TimeSlider/index.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const getBufferedEnd = (currentTime, buffered) => {
1717
return 0;
1818
};
1919

20-
const getEventXCoordinate = e => {
20+
const getEventXCoordinate = (e) => {
2121
if (e.changedTouches && 1 <= e.changedTouches.length) {
2222
return e.changedTouches[0].pageX;
2323
}
@@ -83,7 +83,7 @@ const Slider = React.memo(({ live, hiding, currentTime, duration, buffered, onCh
8383
const updateRef = React.useRef(null);
8484

8585
const onClick = React.useCallback(
86-
e => {
86+
(e) => {
8787
e.preventDefault();
8888
setSliding(false);
8989
if (live) {
@@ -97,7 +97,7 @@ const Slider = React.memo(({ live, hiding, currentTime, duration, buffered, onCh
9797
);
9898

9999
const onMouseDown = React.useCallback(
100-
e => {
100+
(e) => {
101101
e.preventDefault();
102102
if (!sliderRef || !sliderRef.current || !reactRef || live) {
103103
return;
@@ -125,7 +125,7 @@ const Slider = React.memo(({ live, hiding, currentTime, duration, buffered, onCh
125125
}, []);
126126

127127
const onMouseUp = React.useCallback(
128-
e => {
128+
(e) => {
129129
e.preventDefault();
130130
setSliding(false);
131131
if (reactRef && reactRef.current && updateRef) {
@@ -139,7 +139,7 @@ const Slider = React.memo(({ live, hiding, currentTime, duration, buffered, onCh
139139
);
140140

141141
const onMouseMove = React.useCallback(
142-
e => {
142+
(e) => {
143143
e.preventDefault();
144144
if (!reactRef || !reactRef.current || !updateRef) {
145145
return;
@@ -176,7 +176,7 @@ const Slider = React.memo(({ live, hiding, currentTime, duration, buffered, onCh
176176
}, [sliding, onMouseMove, onMouseUp]);
177177

178178
const onSliderMouseOver = React.useCallback(
179-
e => {
179+
(e) => {
180180
e.preventDefault();
181181
if (live) {
182182
return;
@@ -188,7 +188,7 @@ const Slider = React.memo(({ live, hiding, currentTime, duration, buffered, onCh
188188
);
189189

190190
const onSliderMouseMove = React.useCallback(
191-
e => {
191+
(e) => {
192192
e.preventDefault();
193193
if (!reactRef || !reactRef.current || !updateRef) {
194194
return;
@@ -204,7 +204,7 @@ const Slider = React.memo(({ live, hiding, currentTime, duration, buffered, onCh
204204
[duration, update],
205205
);
206206

207-
const onResize = React.useCallback(e => {
207+
const onResize = React.useCallback((e) => {
208208
e.preventDefault();
209209
if (!sliderRef || !sliderRef.current) {
210210
return;

src/hooks/useFlvjs.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22

3-
const getFlvjs = src =>
4-
new Promise(resolve => {
3+
const getFlvjs = (src) =>
4+
new Promise((resolve) => {
55
if (global.flvjs) {
66
resolve(global.flvjs);
77
return;
@@ -17,7 +17,7 @@ const getFlvjs = src =>
1717
// eslint-disable-next-line no-console
1818
const debug = console.error;
1919

20-
const destroyPlayer = player => {
20+
const destroyPlayer = (player) => {
2121
if (!player) {
2222
return;
2323
}

src/hooks/useHlsjs.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22

3-
const getHls = src =>
4-
new Promise(resolve => {
3+
const getHls = (src) =>
4+
new Promise((resolve) => {
55
if (global.Hls) {
66
resolve(global.Hls);
77
return;
@@ -17,7 +17,7 @@ const getHls = src =>
1717
// eslint-disable-next-line no-console
1818
const debug = console.error;
1919

20-
const destroyPlayer = player => {
20+
const destroyPlayer = (player) => {
2121
if (player) {
2222
try {
2323
player.destroy();

0 commit comments

Comments
 (0)