Skip to content
This repository has been archived by the owner on Jan 29, 2021. It is now read-only.

Commit

Permalink
[update] 添加 pre commit lint
Browse files Browse the repository at this point in the history
  • Loading branch information
lawler61 committed Apr 21, 2019
1 parent bc2ddfe commit 886de42
Show file tree
Hide file tree
Showing 23 changed files with 78 additions and 95 deletions.
4 changes: 2 additions & 2 deletions app/components/ExampleCom/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class Hello extends React.PureComponent<IProps> {
return (
<div>
<h1>This is Example component.</h1>
<div className="name">
<div className='name'>
my name is {name}
</div>
<button onClick={this.handleClick}>
the count {count}
</button>
<div className="ruiwen">this is ruiwen</div>
<div className='ruiwen'>this is ruiwen</div>
</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion app/mockData/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export async function getGoods() {
return {
id: random,
name: `goods-${random}`,
desc: `desc-${random}`
desc: `desc-${random}`,
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/pages/Example/actions/exampleAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IRootAction, IRootStore } from '../../../typings'
export default class ExampleAction {
constructor(
public stores: IRootStore['Example'],
public actions: IRootAction['Example']
public actions: IRootAction['Example'],
) {}

async loadGoods() {
Expand Down
16 changes: 8 additions & 8 deletions app/pages/Example/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import addIcon from '../../assets/images/add.svg'

@inject(injector)
@observer
export default class Example extends React.Component<Props, {}> {
export default class Example extends React.Component<IProps, {}> {
static defaultProps = {
prefixCls: 'page-example',
}
Expand All @@ -31,18 +31,18 @@ export default class Example extends React.Component<Props, {}> {
return (
<div className={prefixCls}>
this is example page
<ExampleCom name="lawler" />
<img src={addIcon} alt="addIcon" />
<ExampleCom name='lawler' />
<img src={addIcon} alt='addIcon' />
<h1>当前产品</h1>
{isloading ? (
<h1 className="loading">loading...</h1>
<h1 className='loading'>loading...</h1>
) : (
<React.Fragment>
<ul className='qa-border-1px'>
<li>{curGoods!.name}</li>
<li>{curGoods!.desc}</li>
</ul>
<Button type="primary" onClick={this.handleLoadGoods}>
<Button type='primary' onClick={this.handleLoadGoods}>
换一个
</Button>
</React.Fragment>
Expand All @@ -54,7 +54,7 @@ export default class Example extends React.Component<Props, {}> {

type injectorReturnType = ReturnType<typeof injector>

interface Props extends Partial<injectorReturnType> {
interface IProps extends Partial<injectorReturnType> {
prefixCls?: string
[k: string]: any
}
Expand All @@ -63,8 +63,8 @@ function injector({
rootStore,
rootAction,
}: {
rootStore: IRootStore
rootAction: IRootAction
rootStore: IRootStore,
rootAction: IRootAction,
}) {
return {
store: rootStore.Example,
Expand Down
5 changes: 2 additions & 3 deletions app/pages/Home/actions/homeAction.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { mAction } from '../../../mobx/action'
import { IRootAction, IRootStore } from "../../../typings"
import { IRootAction, IRootStore } from '../../../typings'

@mAction
export default class HomeAction {
constructor(
public stores: IRootStore['Home'],
public actions: IRootAction['Home']
public actions: IRootAction['Home'],
) {}


}
16 changes: 6 additions & 10 deletions app/pages/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,28 @@ import './index.scss'

@inject(injector)
@observer
export default class Home extends React.Component<Props, {}> {
export default class Home extends React.Component<IProps, {}> {
static defaultProps = {
prefixCls: 'page-home'
prefixCls: 'page-home',
}

constructor(props) {
super(props)
}

componentDidMount() {

}

render() {
const { prefixCls } = this.props
return (
<div className={prefixCls}>

this is home page
</div>
)
}
}

type injectorReturnType = ReturnType<typeof injector>

interface Props extends Partial<injectorReturnType> {
interface IProps extends Partial<injectorReturnType> {
prefixCls?: string
[k: string]: any
}
Expand All @@ -40,8 +36,8 @@ function injector({
rootStore,
rootAction,
}: {
rootStore: IRootStore
rootAction: IRootAction
rootStore: IRootStore,
rootAction: IRootAction,
}) {
return {}
}
2 changes: 1 addition & 1 deletion app/pages/Home/stores/homeStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { action, observable, computed } from 'mobx'
import { mStore } from '../../../mobx/store'

interface ISomething {

prop: string
}

@mStore
Expand Down
4 changes: 2 additions & 2 deletions app/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import { HashRouter as Router, Route, Switch } from 'react-router-dom'
import routes, { IRoute } from './routes'
import routesAll, { IRoute } from './routes'

function getRoutes(routes: IRoute[]) {
return routes.map(route => {
Expand All @@ -17,6 +17,6 @@ function getRoutes(routes: IRoute[]) {

export default (
<Router>
<Switch>{getRoutes(routes)}</Switch>
<Switch>{getRoutes(routesAll)}</Switch>
</Router>
)
4 changes: 1 addition & 3 deletions app/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ const server = http.createServer((req, res) => {
})
})

server.listen(8080, () =>
console.log('your app is running at http://localhost:8080')
)
server.listen(8080, () => console.log('your app is running at http://localhost:8080'))
5 changes: 2 additions & 3 deletions app/tools/templates/actions/action.ts.tpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { mAction } from '../../../mobx/action'
import { IRootAction, IRootStore } from "../../../typings"
import { IRootAction, IRootStore } from '../../../typings'

@mAction
export default class ${uppercaseName}$Action {
constructor(
public stores: IRootStore['${rootPageName}$'],
public actions: IRootAction['${rootPageName}$']
public actions: IRootAction['${rootPageName}$'],
) {}


}
14 changes: 6 additions & 8 deletions app/tools/templates/index.tsx.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ import './index.scss'

@inject(injector)
@observer
export default class ${uppercaseName}$ extends React.Component<Props, {}> {
export default class ${uppercaseName}$ extends React.Component<IProps, {}> {
static defaultProps = {
prefixCls: '${type}$-${splitDashName}$'
prefixCls: '${type}$-${splitDashName}$',
}

constructor(props) {
super(props)
}

componentDidMount() {
}
componentDidMount() {}

render() {
const { prefixCls } = this.props
Expand All @@ -31,7 +29,7 @@ export default class ${uppercaseName}$ extends React.Component<Props, {}> {

type injectorReturnType = ReturnType<typeof injector>

interface Props extends Partial<injectorReturnType> {
interface IProps extends Partial<injectorReturnType> {
prefixCls?: string
[k: string]: any
}
Expand All @@ -40,8 +38,8 @@ function injector({
rootStore,
rootAction,
}: {
rootStore: IRootStore
rootAction: IRootAction
rootStore: IRootStore,
rootAction: IRootAction,
}) {
return {}
}
8 changes: 4 additions & 4 deletions app/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function formatDate(date: Date, fmt: string) {
// 拿到完整年份后,根据传入的y的个数进行截取,如传的是4,则从0截取,为2018,如传2个y则从2开始截取,为16
fmt = fmt.replace(
RegExp.$1,
`${date.getFullYear()}`.substr(4 - RegExp.$1.length)
`${date.getFullYear()}`.substr(4 - RegExp.$1.length),
)
}
const data = {
Expand All @@ -17,13 +17,13 @@ export function formatDate(date: Date, fmt: string) {
'm+': date.getMinutes(),
's+': date.getSeconds(),
}
Object.keys(data).forEach((k) => {
Object.keys(data).forEach(k => {
if (new RegExp(`(${k})`).test(fmt)) {
const str =`${data[k]}`
const str = `${data[k]}`
// 对于月,日,时,分,秒 这种如果传的 M、d等个数是 1个的话,就显示一个,如果为 2,则要在数 < 10时添加 0
fmt = fmt.replace(
RegExp.$1,
RegExp.$1.length === 1 ? str : padLeftZero(str)
RegExp.$1.length === 1 ? str : padLeftZero(str),
)
}
})
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
{
"name": "qa-app",
"version": "0.0.2",
"version": "0.0.3",
"description": "question-answer app",
"basePath": "app",
"main": "app/index.tsx",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --config config/webpack.prod.config.js --progress",
"start": "webpack-dev-server --config config/webpack.dev.config.js --progress",
"lint": "eslint --ext .js app",
"lint": "tslint --fix --project .",
"dll": "webpack --config config/webpack.dll.config.js --progress",
"serve": "nodemon app/serve.js",
"server": "ts-node server/bootstrap.ts"
},
"author": "lawler61",
"license": "ISC",
"pre-commit": [
"lint"
],
"keywords": [
"react",
"mobx",
Expand Down
8 changes: 4 additions & 4 deletions server/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import './controller/home';
import './controller/user';

// load everything needed to the Container
let container = new Container();
const container = new Container();
container.bind<UserService>(TYPES.UserService).to(UserService);

// start the server
let server = new InversifyExpressServer(container);
const server = new InversifyExpressServer(container);

server.setConfig((app) => {
server.setConfig(app => {
app.use(bodyParser.urlencoded({
extended: true
extended: true,
}));
app.use(bodyParser.json());
});
Expand Down
2 changes: 1 addition & 1 deletion server/constant/tags.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const TAGS = {
HomeController: 'HomeController',
UserController: 'UserController'
UserController: 'UserController',
};

export default TAGS;
2 changes: 1 addition & 1 deletion server/constant/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const TYPES = {
UserService: Symbol.for('UserService')
UserService: Symbol.for('UserService'),
};

export default TYPES;
2 changes: 1 addition & 1 deletion server/controller/user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
controller, httpGet, httpPost, httpPut, httpDelete
controller, httpGet, httpPost, httpPut, httpDelete,
} from 'inversify-express-utils';
import { inject } from 'inversify';
import { IUser, UserService } from '../service/user';
Expand Down
7 changes: 3 additions & 4 deletions server/service/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ export class UserService {

private userStorage: IUser[] = [{
email: 'lorem@ipsum.com',
name: 'Lorem'
name: 'Lorem',
}, {
email: 'doloe@sit.com',
name: 'Dolor'
name: 'Dolor',
}];


public getUsers(): IUser[] {
return this.userStorage;
}
Expand Down Expand Up @@ -48,7 +47,7 @@ export class UserService {
}

public deleteUser(id: string): string {
let updatedUser: IUser[] = [];
const updatedUser: IUser[] = [];
this.userStorage.map(user => {
if (user.name !== id) {
updatedUser.push(user);
Expand Down
2 changes: 1 addition & 1 deletion server/test/controller/home.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { HomeController } from '../../controller/home';

describe('HomeController', () => {
it('should give back `Home sweet home`', () => {
let service = new HomeController();
const service = new HomeController();

expect(service.get()).to.equal('Home sweet home');
});
Expand Down
Loading

0 comments on commit 886de42

Please sign in to comment.