Skip to content

Commit f8e1cd2

Browse files
committed
fix: check ts
1 parent c0b33ca commit f8e1cd2

File tree

22 files changed

+93
-192
lines changed

22 files changed

+93
-192
lines changed

.eslintrc.json

+14-26
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
"airbnb",
88
"plugin:import/errors",
99
"plugin:import/warnings",
10+
"plugin:react/recommended",
1011
// ts项目可能跟eslint规则冲突,这个插件就是解决这个问题的
1112
// 注意优先级
12-
"plugin:react/recommended",
1313
"plugin:@typescript-eslint/recommended",
1414
"prettier", // 可能会覆盖eslint-config-airbnb的rule配置 不需要prettier/airbnb 理清楚这种关系 ===>基础配置
1515
"plugin:prettier/recommended"
@@ -82,6 +82,7 @@
8282
],
8383
"@typescript-eslint/type-annotation-spacing": "off",
8484
"@typescript-eslint/unified-signatures": "error",
85+
"@typescript-eslint/explicit-module-boundary-types": "off",
8586
"arrow-body-style": "error",
8687
"arrow-parens": ["off", "as-needed"],
8788
"camelcase": "off",
@@ -136,23 +137,9 @@
136137
"no-throw-literal": "error",
137138
"no-trailing-spaces": "off",
138139
"no-undef-init": "error",
140+
" no-plusplus":"off",
141+
" no-await-in-loop":"off",
139142
"class-methods-use-this": "off",
140-
// "no-underscore-dangle": [
141-
// "error",
142-
// {
143-
// "allow": [
144-
// "__INITIAL_DATA__",
145-
// "__STORE__",
146-
// "_insertCss",
147-
// "__SERVER__",
148-
// "__IS_PROD__",
149-
// "__IS_SSR__",
150-
// "_getContent"
151-
// ],
152-
// "allowAfterThis": true,
153-
// "allowAfterThisConstructor": true
154-
// }
155-
// ],
156143
"no-underscore-dangle": "off",
157144
"no-unsafe-finally": "error",
158145
"no-unused-expressions": [
@@ -223,13 +210,14 @@
223210
"react-hooks/rules-of-hooks": "error", // 检查 Hook 的规则
224211
"react-hooks/exhaustive-deps": "warn", // 检查 effect 的依赖
225212
"react/jsx-filename-extension": [2, { "extensions": [".js", ".jsx", ".ts", ".tsx"] }]
226-
}
227-
// "overrides": [
228-
// {
229-
// "files": ["global.d.ts", "css.modules.d.ts", "pro-config.ts"],
230-
// "rules": {
231-
// "@typescript-eslint/naming-convention": "off"
232-
// }
233-
// }
234-
// ]
213+
},
214+
"overrides": [
215+
{
216+
// enable the rule specifically for TypeScript files
217+
"files": ["*.js", "*.ts"],
218+
"rules": {
219+
"@typescript-eslint/explicit-module-boundary-types": ["error"]
220+
}
221+
}
222+
]
235223
}

build/client/webpack.base.conf.js

+6-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
const os = require('os')
21
const path = require('path')
32
const HtmlWebpackPlugin = require('html-webpack-plugin')
43
const WebpackBar = require('webpackbar')
54
const webpack = require('webpack')
6-
7-
// const ProgressBarPlugin = require('progress-bar-webpack-plugin')
8-
// const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
5+
const ESLintPlugin = require('eslint-webpack-plugin');
6+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
97

108
const utils = require('./utils')
119
const config = require('../../config')
@@ -44,15 +42,6 @@ module.exports = {
4442
}
4543
]
4644
},
47-
{
48-
test: /\.ts|\.tsx|\.js|\.json/,
49-
exclude: /node_modules/,
50-
loader: 'eslint-loader',
51-
options: {
52-
fix: true,
53-
cache: true
54-
}
55-
},
5645
{
5746
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
5847
loader: 'url-loader',
@@ -81,8 +70,10 @@ module.exports = {
8170
},
8271

8372
plugins: [
84-
// new ProgressBarPlugin(),
85-
// new ForkTsCheckerWebpackPlugin(),
73+
new ForkTsCheckerWebpackPlugin(),
74+
new ESLintPlugin({
75+
fix:true
76+
}),
8677
new WebpackBar({
8778
name: 'client',
8879
color: 'green'

build/server/webpack.server.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var utils = require('../client/utils')
88

99
//构建前清理目录
1010
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
11-
process.env.BABEL_ENV = 'node' //设置 babel 的运行环境
11+
process.env.BABEL_ENV = 'node' // 设置 babel 的运行环境
1212
const proConfig = require('../../config/pro-config')
1313

1414
const isProd = process.env.NODE_ENV === 'production'

package.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@
4040
"react-router-dom": "^5.2.0",
4141
"redux": "^4.1.0",
4242
"redux-actions": "^2.6.5",
43-
"redux-promise-middleware": "^6.1.2",
44-
"sa-sdk-javascript": "^1.16.12",
45-
"uuid": "^8.3.2"
43+
"redux-promise-middleware": "^6.1.2"
4644
},
4745
"devDependencies": {
4846
"@babel/core": "^7.13.16",
@@ -77,12 +75,12 @@
7775
"eslint-config-airbnb": "^18.2.1",
7876
"eslint-config-airbnb-typescript": "^12.3.1",
7977
"eslint-config-prettier": "^8.3.0",
80-
"eslint-loader": "^4.0.2",
8178
"eslint-plugin-import": "^2.22.1",
8279
"eslint-plugin-jsx-a11y": "^6.4.1",
8380
"eslint-plugin-prettier": "^3.4.0",
8481
"eslint-plugin-react": "^7.23.2",
8582
"eslint-plugin-react-hooks": "^4.2.0",
83+
"eslint-webpack-plugin": "^2.5.4",
8684
"express": "^4.17.1",
8785
"file-loader": "^6.2.0",
8886
"fork-ts-checker-webpack-plugin": "^6.2.5",
@@ -98,7 +96,6 @@
9896
"optimize-css-assets-webpack-plugin": "^5.0.4",
9997
"postcss-loader": "^5.2.0",
10098
"prettier": "^2.2.1",
101-
"progress-bar-webpack-plugin": "^2.1.0",
10299
"redux-devtools-extension": "^2.13.9",
103100
"redux-logger": "^3.0.6",
104101
"standard-version": "^9.2.0",

src/client/components/asyncBundle/index.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ interface IPops {
1212
children: any
1313
load: any
1414
}
15-
export default class AsyncBundle extends React.PureComponent<IPops, any> {
15+
16+
interface IState {
17+
mod?: any
18+
}
19+
export default class AsyncBundle extends React.PureComponent<IPops, IState> {
1620
state = {
1721
mod: null
1822
}
@@ -38,7 +42,6 @@ export default class AsyncBundle extends React.PureComponent<IPops, any> {
3842

3943
render() {
4044
const { mod } = this.state
41-
console.log('mod', mod)
4245
const { children } = this.props
4346
return mod ? children(mod) : <LoadingCompoent />
4447
}

src/client/components/container/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default (SourceComponent: any) =>
6262
}
6363
const { staticContext } = this.props
6464
const { canClientFetch, initialData } = this.state
65-
65+
// wwebpack会做替换
6666
if (__SERVER__) {
6767
// 服务端渲染
6868
props.initialData = staticContext.initialData || {}
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
22

3-
export default function LoadingComponent(props: any) {
3+
export default function LoadingComponent() {
44
return <div>loading......</div>
55
}

src/client/config/sensor.ts

-12
This file was deleted.

src/client/library/isConnect.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import Container from '@/components/container'
22
import { connect } from 'react-redux'
3-
// @ts-ignore
43
import withStyles from 'isomorphic-style-loader/withStyles'
5-
console.log('1')
6-
export default (
7-
{ css, mapStateToProps, mapDispatchToProps }: any,
8-
ActiveComponet: any
9-
) => {
10-
return withStyles(css)(
11-
connect(mapStateToProps, mapDispatchToProps)(Container(ActiveComponet))
12-
)
13-
}
4+
5+
export default ({ css, mapStateToProps, mapDispatchToProps }: any, ActiveComponet: any) =>
6+
withStyles(css)(connect(mapStateToProps, mapDispatchToProps)(Container(ActiveComponet)))

src/client/library/sensors.ts

-43
This file was deleted.

src/client/library/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export const to = (promise: any) => {
143143
}).catch(err => [err, null])
144144
}
145145
return promise
146-
.then((...args: any[]) => [null, ...args])
146+
.then((...args: any[]) => [null,...args])
147147
.catch((err: any) => [err, null])
148148
}
149149

src/client/modules/about/index.tsx

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import React, { FC, useState } from 'react'
1+
import React, { FC } from 'react'
22
import { Link } from 'react-router-dom'
33
import css from './index.less'
4-
54
import isConnect from '@/library/isConnect'
65

7-
console.log('css', css)
8-
export const About: FC<any> = (props: any) => {
9-
const [nums, setNums] = useState<number[]>([1, 2, 3, 4, 5, 6])
6+
export const About: FC<any> = () => {
107
const handleClick = () => {
118
window.alert('handleClick')
129
}
@@ -25,7 +22,7 @@ const mapStateToProps = (state: any) => ({
2522
home: state.home
2623
})
2724

28-
const mapDispatchToProps = (dispatch: any) => ({})
25+
const mapDispatchToProps = () => ({})
2926

3027
export default isConnect(
3128
{

src/client/modules/about/routes.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react'
21
import AsyncLoader from '@/components/asyncLoader'
32

43
export default [

src/client/modules/home/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import React, { FC, useState } from 'react'
1+
import React from 'react'
22
import { Link } from 'react-router-dom'
33
import css from './index.less'
44
import isConnect from '@/library/isConnect'
55

6-
export const Home = (props: any) => {
6+
export const Home = () => {
77
const handleClick = () => {
8-
window.alert('handleClick')
8+
alert('handleClick')
99
}
1010

1111
return (

src/client/modules/home/routes.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react'
1+
import React from 'react'
22
import AsyncLoader from '@/components/asyncLoader'
33

44
// 这种不能被做到热更新 那么应该reload啊

src/client/store/home/index.ts

+20-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createModel } from '@rematch/core'
22

3-
type HomeState = {
3+
interface HomeState {
44
players: any[]
55
}
66

@@ -9,35 +9,33 @@ export default createModel<any>()({
99
players: [1, 2, 3, 99]
1010
} as HomeState,
1111
reducers: {
12-
SET_PLAYERS: (state: HomeState, players: HomeState[]) => {
13-
return {
14-
...state,
15-
players
16-
}
17-
}
12+
SET_PLAYERS: (state: HomeState, players: HomeState[]) => ({
13+
...state,
14+
players
15+
})
1816
},
1917
effects: (dispatch: any) => {
2018
const { home } = dispatch
2119
return {
2220
async getPlayers(): Promise<any> {
23-
let response = await fetch('https://www.balldontlie.io/api/v1/players')
24-
let { data }: { data: HomeState[] } = await response.json()
21+
const response = await fetch('https://www.balldontlie.io/api/v1/players')
22+
const { data }: { data: HomeState[] } = await response.json()
2523
home.SET_PLAYERS(data)
2624
},
2725
// ! 约定的方法
28-
getInitialData(){
29-
return new Promise(resolve=>{
30-
//延迟 500ms 返回数据
31-
setTimeout(() => {
32-
const data = {
33-
test:'123'
34-
}
35-
resolve(data);
36-
//更新状态
37-
console.log('players',home)
38-
home.SET_PLAYERS([800,800,800])
39-
}, 500);
40-
})
26+
getInitialData() {
27+
return new Promise(resolve => {
28+
// 延迟 500ms 返回数据
29+
setTimeout(() => {
30+
const data = {
31+
test: '123'
32+
}
33+
resolve(data)
34+
// 更新状态
35+
console.log('players', home)
36+
home.SET_PLAYERS([800, 800, 800])
37+
}, 500)
38+
})
4139
}
4240
}
4341
}

0 commit comments

Comments
 (0)