Skip to content

Commit b0c20ee

Browse files
committed
code lint
1 parent f65f874 commit b0c20ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1906
-482
lines changed

package.json

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"scripts": {
99
"start": "npm run dev",
1010
"dev": "NODE_ENV=development webpack-dev-server --config build/webpack.dev.conf.js",
11-
"build": "NODE_ENV=production webpack --config build/webpack.prod.conf.js"
11+
"build": "NODE_ENV=production webpack --config build/webpack.prod.conf.js",
12+
"lint": "eslint --ext ts,tsx src/",
13+
"lint:fix": "eslint --ext ts,tsx src/ --fix"
1214
},
1315
"repository": {
1416
"type": "git",
@@ -41,12 +43,18 @@
4143
"@types/react": "^16.7.7",
4244
"@types/react-dom": "^16.0.10",
4345
"@types/react-router-dom": "^4.3.1",
46+
"@typescript-eslint/eslint-plugin": "^2.4.0",
47+
"@typescript-eslint/parser": "^2.4.0",
4448
"autoprefixer": "^9.3.1",
4549
"babel-loader": "^8.0.4",
4650
"clean-webpack-plugin": "^0.1.19",
4751
"copy-webpack-plugin": "^4.6.0",
4852
"css-loader": "^1.0.1",
53+
"eslint": "^6.5.1",
54+
"eslint-plugin-react": "^7.16.0",
4955
"html-webpack-plugin": "^3.2.0",
56+
"husky": "^3.0.9",
57+
"lint-staged": "^9.4.2",
5058
"mini-css-extract-plugin": "^0.4.4",
5159
"node-sass": "^4.12.0",
5260
"optimize-css-assets-webpack-plugin": "^5.0.1",
@@ -55,13 +63,28 @@
5563
"sass-loader": "^7.1.0",
5664
"style-loader": "^0.23.1",
5765
"sw-precache-webpack-plugin": "^0.11.5",
58-
"typescript": "^3.1.6",
66+
"typescript": "^3.6.4",
5967
"uglifyjs-webpack-plugin": "^2.0.1",
6068
"url-loader": "^1.1.2",
6169
"webpack": "^4.26.1",
6270
"webpack-cli": "^3.1.2",
6371
"webpack-dev-server": "^3.1.10",
6472
"webpack-manifest-plugin": "^2.0.4",
6573
"webpack-merge": "^4.1.4"
74+
},
75+
"husky": {
76+
"hooks": {
77+
"pre-commit": "lint-staged"
78+
}
79+
},
80+
"lint-staged": {
81+
"src/**/*.{js,jsx,ts,tsx}": [
82+
"npm run lint:fix",
83+
"git add"
84+
],
85+
"src/**/*.{css,less,json,html,md,markdown}": [
86+
"prettier --write",
87+
"git add"
88+
]
6689
}
6790
}

src/components/editor/index.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const toolbarOptions = [
2424
['link', 'image'],
2525

2626
['clean'], // remove formatting button
27-
];
27+
]
2828

2929
interface IEditor {
3030
disabled?: boolean
@@ -46,30 +46,32 @@ export default class QuillEditorComponent extends React.Component<IEditor> {
4646
readOnly: false,
4747
theme: 'snow',
4848
}
49+
50+
$editor: any = null
4951

5052
componentDidMount() {
5153
const { onChange } = this.props
52-
const { editor }: any = this.refs
53-
this.quillEditor = new Quill(editor, this.quillOptions)
54+
const { $editor } = this
55+
this.quillEditor = new Quill($editor, this.quillOptions)
5456

5557
this.quillEditor.on('text-change', (delta: any, oldDelta: any, source: any) => {
56-
let _html: string = this.quillEditor.root.innerHTML;
58+
let _html: string = this.quillEditor.root.innerHTML
5759
if (_html === '<p><br></p>') {
58-
_html = '';
60+
_html = ''
5961
}
6062
if(this.oldVal !== _html) {
6163
this.oldVal = _html
62-
onChange && onChange(_html);
64+
onChange && onChange(_html)
6365
}
64-
});
66+
})
6567
}
6668

6769
// change editor value
6870
changeEditorText = () => {
6971
const { value } = this.props
7072
// 赋值
7173
if(this.oldVal !== value && value !== undefined && this.quillEditor) {
72-
this.quillEditor.root.innerHTML = value;
74+
this.quillEditor.root.innerHTML = value
7375
this.oldVal = value
7476
}
7577
}
@@ -79,7 +81,7 @@ export default class QuillEditorComponent extends React.Component<IEditor> {
7981
this.changeEditorText()
8082

8183
return <div className="editor-wrap">
82-
<div style={{minHeight: '600px'}} ref="editor"></div>
84+
<div style={{minHeight: '600px'}} ref={this.$editor}></div>
8385
{disabled ? <div className="editor-mask"></div> : ''}
8486
</div>
8587

src/components/loading.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import * as React from 'react'
22
import { Spin } from 'antd'
33

44
interface ILoadingProps {

src/components/shared/footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react'
2-
import { Layout } from 'antd';
2+
import { Layout } from 'antd'
33

44
const { Footer } = Layout
55

src/components/shared/header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default class HeaderComponent extends React.Component<IHeaderProps> {
1818
padding: 0,
1919
display: 'flex',
2020
alignItems: 'center'
21-
}}>
21+
}}>
2222
<div style={{flex: '1 1 0'}}>
2323
<Icon
2424
style={{cursor: 'pointer'}}

src/components/shared/sider.tsx

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,26 @@ class SiderComponent extends React.Component<ISiderProps> {
9090
{
9191
MenuList.map(m => {
9292
return m.children ?
93-
<SubMenu
94-
key={m.key}
95-
title={<span><Icon type={m.icon} /><span>{m.title}</span></span>}>
96-
{
97-
m.children.map(mc => {
98-
return <Item key={mc.key}>
99-
<Link to={mc.path}>
100-
<Icon type={mc.icon} />
101-
<span>{mc.title}</span>
102-
</Link>
103-
</Item>
104-
})
105-
}
106-
</SubMenu> :
107-
<Item key={m.key}>
108-
<Link to={m.path}>
109-
<Icon type={m.icon} />
110-
<span>{m.title}</span>
111-
</Link>
112-
</Item>
93+
<SubMenu
94+
key={m.key}
95+
title={<span><Icon type={m.icon} /><span>{m.title}</span></span>}>
96+
{
97+
m.children.map(mc => {
98+
return <Item key={mc.key}>
99+
<Link to={mc.path}>
100+
<Icon type={mc.icon} />
101+
<span>{mc.title}</span>
102+
</Link>
103+
</Item>
104+
})
105+
}
106+
</SubMenu> :
107+
<Item key={m.key}>
108+
<Link to={m.path}>
109+
<Icon type={m.icon} />
110+
<span>{m.title}</span>
111+
</Link>
112+
</Item>
113113
})
114114
}
115115
</Menu>

src/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import * as React from 'react'
2-
import * as ReactDOM from 'react-dom';
3-
import App from './pages/app';
4-
import './assets/scss/app.scss';
2+
import * as ReactDOM from 'react-dom'
3+
import App from './pages/app'
4+
import './assets/scss/app.scss'
55
import 'antd/dist/antd.css'
6-
import 'quill/dist/quill.snow.css';
6+
import 'quill/dist/quill.snow.css'
77
import serviceWorker from './serviceWorker'
88

99
ReactDOM.render(
1010
<App/>,
1111
document.getElementById('app')
12-
);
12+
)
1313
serviceWorker()

src/pages/app.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as React from 'react';
2-
import { BrowserRouter as Router, Route, Switch, Redirect} from 'react-router-dom';
1+
import * as React from 'react'
2+
import { BrowserRouter as Router, Route, Switch, Redirect} from 'react-router-dom'
33
import { Provider } from 'mobx-react'
44
import stores from '../stores'
55
import Loading from '@components/loading'
@@ -28,4 +28,4 @@ class App extends React.Component {
2828
}
2929
}
3030

31-
export default App;
31+
export default App

src/pages/article/articleCreate.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as React from 'react'
22
import {inject, observer} from 'mobx-react'
3-
import { Row, Col, Form, Icon, Input, Button, DatePicker, Select, Checkbox, Badge } from 'antd';
3+
import { Row, Col, Form, Icon, Input, Button, DatePicker, Select, Checkbox, Badge } from 'antd'
44
import Editor from '@components/editor'
55

6-
const FormItem = Form.Item;
6+
const FormItem = Form.Item
77
const CheckboxGroup = Checkbox.Group
88

99
const formItemLayout = {
@@ -56,7 +56,7 @@ export default class ArticleCreate extends React.Component<IProps> {
5656
<FormItem label="文章类型" labelCol={{sm: {span: 8}}} wrapperCol={{sm: { span: 16 }}}>
5757
<Select value={mainData.typeId} onChange={e => inputChange(e, 'typeId')}>
5858
{
59-
typeList.map((t:any, i:number) => <Select.Option value={t.id} key={t.id}>{t.name}</Select.Option>)
59+
typeList.map((t: any, i: number) => <Select.Option value={t.id} key={t.id}>{t.name}</Select.Option>)
6060
}
6161
</Select>
6262
</FormItem>

src/pages/article/articleCreateStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { observable, action, autorun, runInAction, computed } from 'mobx';
1+
import { observable, action, autorun, runInAction, computed } from 'mobx'
22
import { GRAPHQL_API } from '@constants/index'
33

44
const getInitQuery = `{

0 commit comments

Comments
 (0)