Commit adfff206 by lirandong

添加 tslint 和项目规范

parent 81ffe04b
...@@ -7,12 +7,7 @@ ...@@ -7,12 +7,7 @@
"parser": "@typescript-eslint/parser", "parser": "@typescript-eslint/parser",
"parserOptions": { "parserOptions": {
"ecmaFeatures": { "ecmaFeatures": {
"experimentalObjectRestSpread": true, "jsx": true
"jsx": true,
"arrowFunctions": true,
"classes": true,
"modules": true,
"defaultParams": true
}, },
"useJSXTextNode": true, "useJSXTextNode": true,
"project": "./tsconfig.json" "project": "./tsconfig.json"
......
module.exports = {
extends: 'stylelint-config-standard',
// 使用的插件
// plugins: ['stylelint-less'],
// 需要忽略的文件类型
ignoreFiles: ['node_modules/**/*', '**/*.md', '**/*.ts', '**/*.tsx', '**/*.js'],
rules: {
indentation: 2,
'no-empty-source': null,
'at-rule-no-unknown': null,
'no-descending-specificity': null
}
}
\ No newline at end of file
...@@ -20,7 +20,9 @@ ...@@ -20,7 +20,9 @@
"dev:alipay": "npm run build:alipay -- --watch", "dev:alipay": "npm run build:alipay -- --watch",
"dev:tt": "npm run build:tt -- --watch", "dev:tt": "npm run build:tt -- --watch",
"dev:h5": "npm run build:h5 -- --watch", "dev:h5": "npm run build:h5 -- --watch",
"dev:rn": "npm run build:rn -- --watch" "dev:rn": "npm run build:rn -- --watch",
"lint": "tslint --project ./tsconfig.json && stylelint \"./src/**/*.less\"",
"precommit": "npm run lint"
}, },
"author": "", "author": "",
"license": "MIT", "license": "MIT",
...@@ -71,8 +73,11 @@ ...@@ -71,8 +73,11 @@
"eslint-plugin-react-hooks": "^1.6.1", "eslint-plugin-react-hooks": "^1.6.1",
"eslint-plugin-taro": "1.3.12", "eslint-plugin-taro": "1.3.12",
"stylelint": "9.3.0", "stylelint": "9.3.0",
"stylelint-config-standard": "^18.3.0",
"stylelint-config-taro-rn": "1.3.12", "stylelint-config-taro-rn": "1.3.12",
"stylelint-taro-rn": "1.3.12", "stylelint-taro-rn": "1.3.12",
"tslint": "^5.18.0",
"tslint-react": "^4.0.0",
"typescript": "^3.0.1" "typescript": "^3.0.1"
} }
} }
import { import { ADD, MINUS } from '../constants/counter'
ADD,
MINUS
} from '../constants/counter'
export const add = () => { export const add = () => {
return { return {
...@@ -15,7 +12,7 @@ export const minus = () => { ...@@ -15,7 +12,7 @@ export const minus = () => {
} }
// 异步的action // 异步的action
export function asyncAdd () { export function asyncAdd() {
return dispatch => { return dispatch => {
setTimeout(() => { setTimeout(() => {
dispatch(add()) dispatch(add())
......
...@@ -17,7 +17,6 @@ import './app.less' ...@@ -17,7 +17,6 @@ import './app.less'
const store = configStore() const store = configStore()
class App extends Component { class App extends Component {
/** /**
* 指定config的类型声明为: Taro.Config * 指定config的类型声明为: Taro.Config
* *
...@@ -26,9 +25,7 @@ class App extends Component { ...@@ -26,9 +25,7 @@ class App extends Component {
* 提示和声明 navigationBarTextStyle: 'black' | 'white' 类型冲突, 需要显示声明类型 * 提示和声明 navigationBarTextStyle: 'black' | 'white' 类型冲突, 需要显示声明类型
*/ */
config: Config = { config: Config = {
pages: [ pages: ['pages/index/index'],
'pages/index/index'
],
window: { window: {
backgroundTextStyle: 'light', backgroundTextStyle: 'light',
navigationBarBackgroundColor: '#fff', navigationBarBackgroundColor: '#fff',
...@@ -37,17 +34,17 @@ class App extends Component { ...@@ -37,17 +34,17 @@ class App extends Component {
} }
} }
componentDidMount () {} componentDidMount() {}
componentDidShow () {} componentDidShow() {}
componentDidHide () {} componentDidHide() {}
componentDidCatchError () {} componentDidCatchError() {}
// 在 App 类中的 render() 函数没有实际作用 // 在 App 类中的 render() 函数没有实际作用
// 请勿修改此函数 // 请勿修改此函数
render () { render() {
return ( return (
<Provider store={store}> <Provider store={store}>
<Index /> <Index />
......
...@@ -79,14 +79,14 @@ class Index extends Component { ...@@ -79,14 +79,14 @@ class Index extends Component {
render() { render() {
return ( return (
<View className='index'> <View className="index">
<Button className='add_btn' onClick={this.props.add}> <Button className="add_btn" onClick={this.props.add}>
+ +
</Button> </Button>
<Button className='dec_btn' onClick={this.props.dec}> <Button className="dec_btn" onClick={this.props.dec}>
- -
</Button> </Button>
<Button className='dec_btn' onClick={this.props.asyncAdd}> <Button className="dec_btn" onClick={this.props.asyncAdd}>
async async
</Button> </Button>
<View> <View>
......
...@@ -4,7 +4,7 @@ const INITIAL_STATE = { ...@@ -4,7 +4,7 @@ const INITIAL_STATE = {
num: 0 num: 0
} }
export default function counter (state = INITIAL_STATE, action) { export default function counter(state = INITIAL_STATE, action) {
switch (action.type) { switch (action.type) {
case ADD: case ADD:
return { return {
......
...@@ -2,27 +2,34 @@ import { createStore, applyMiddleware, compose } from 'redux' ...@@ -2,27 +2,34 @@ import { createStore, applyMiddleware, compose } from 'redux'
import thunkMiddleware from 'redux-thunk' import thunkMiddleware from 'redux-thunk'
import rootReducer from '../reducers' import rootReducer from '../reducers'
declare global {
interface Window {
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__: (val: any) => any
}
}
const composeEnhancers = const composeEnhancers =
typeof window === 'object' && typeof window === 'object' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
// Specify extension’s options like name, actionsBlacklist, actionsCreators, serialize... // Specify extension’s options like name, actionsBlacklist, actionsCreators, serialize...
}) : compose })
: compose
const middlewares = [ const middlewares = [thunkMiddleware]
thunkMiddleware
]
if (process.env.NODE_ENV === 'development' && process.env.TARO_ENV !== 'quickapp') { if (process.env.NODE_ENV === 'development' && process.env.TARO_ENV !== 'quickapp') {
middlewares.push(require('redux-logger').createLogger()) middlewares.push(
// tslint:disable-next-line:no-var-requires
require('redux-logger').createLogger()
)
} }
const enhancer = composeEnhancers( const enhancer = composeEnhancers(
applyMiddleware(...middlewares), applyMiddleware(...middlewares)
// other store enhancers if any // other store enhancers if any
) )
export default function configStore () { export default function configStore() {
const store = createStore(rootReducer, enhancer) const store = createStore(rootReducer, enhancer)
return store return store
} }
...@@ -19,13 +19,9 @@ ...@@ -19,13 +19,9 @@
"jsxFactory": "Taro.createElement", "jsxFactory": "Taro.createElement",
"allowJs": true, "allowJs": true,
"resolveJsonModule": true, "resolveJsonModule": true,
"typeRoots": [ "typeRoots": ["node_modules/@types"]
"node_modules/@types"
]
}, },
"exclude": [ "exclude": ["node_modules", "dist"],
"node_modules", "compileOnSave": false,
"dist" "include": ["src", "typings"]
],
"compileOnSave": false
} }
{
"extends": ["tslint:recommended", "tslint-react"],
"rules": {
"arrow-parens": false,
"arrow-return-shorthand": [false],
"comment-format": [true, "check-space"],
"import-blacklist": [true, "rxjs"],
"interface-over-type-literal": false,
"interface-name": false,
"max-line-length": false,
"member-access": false,
"member-ordering": [
true,
{
"order": "fields-first"
}
],
"newline-before-return": false,
"no-empty": false,
"no-any": false,
"no-empty-interface": false,
"no-import-side-effect": false,
"no-namespace": false,
"no-console": false,
"no-inferrable-types": [true, "ignore-params", "ignore-properties"],
"no-invalid-this": [true, "check-function-in-method"],
"no-null-keyword": false,
"no-require-imports": false,
"no-submodule-imports": false,
"no-this-assignment": [
true,
{
"allow-destructuring": true
}
],
"no-trailing-whitespace": true,
"object-literal-sort-keys": false,
"object-literal-shorthand": false,
"one-variable-per-declaration": false,
"only-arrow-functions": [true, "allow-declarations"],
"ordered-imports": false,
"prefer-method-signature": false,
"prefer-template": [true, "allow-single-concat"],
"quotemark": [true, "single", "jsx-double"],
"semicolon": [true, "never"],
"trailing-comma": [false],
"triple-equals": [true, "allow-null-check"],
"type-literal-delimiter": false,
"typedef": [true, "property-declaration"],
"variable-name": [true, "ban-keywords", "check-format", "allow-pascal-case", "allow-leading-underscore"],
"max-classes-per-file": false,
"jsx-no-lambda": false,
"jsx-no-multiline-js": false,
"jsx-curly-spacing": [
true,
{
"when": "never",
"allowMultiline": false
}
],
"jsx-boolean-value": false,
"curly": false,
"no-unused-expression": false,
"no-string-literal": false,
"object-literal-key-quotes": false
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment