Commit adfff206 by lirandong

添加 tslint 和项目规范

parent 81ffe04b
......@@ -7,12 +7,7 @@
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true,
"arrowFunctions": true,
"classes": true,
"modules": true,
"defaultParams": true
"jsx": true
},
"useJSXTextNode": true,
"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 @@
"dev:alipay": "npm run build:alipay -- --watch",
"dev:tt": "npm run build:tt -- --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": "",
"license": "MIT",
......@@ -71,8 +73,11 @@
"eslint-plugin-react-hooks": "^1.6.1",
"eslint-plugin-taro": "1.3.12",
"stylelint": "9.3.0",
"stylelint-config-standard": "^18.3.0",
"stylelint-config-taro-rn": "1.3.12",
"stylelint-taro-rn": "1.3.12",
"tslint": "^5.18.0",
"tslint-react": "^4.0.0",
"typescript": "^3.0.1"
}
}
import {
ADD,
MINUS
} from '../constants/counter'
import { ADD, MINUS } from '../constants/counter'
export const add = () => {
return {
......@@ -15,7 +12,7 @@ export const minus = () => {
}
// 异步的action
export function asyncAdd () {
export function asyncAdd() {
return dispatch => {
setTimeout(() => {
dispatch(add())
......
......@@ -17,7 +17,6 @@ import './app.less'
const store = configStore()
class App extends Component {
/**
* 指定config的类型声明为: Taro.Config
*
......@@ -26,9 +25,7 @@ class App extends Component {
* 提示和声明 navigationBarTextStyle: 'black' | 'white' 类型冲突, 需要显示声明类型
*/
config: Config = {
pages: [
'pages/index/index'
],
pages: ['pages/index/index'],
window: {
backgroundTextStyle: 'light',
navigationBarBackgroundColor: '#fff',
......@@ -37,17 +34,17 @@ class App extends Component {
}
}
componentDidMount () {}
componentDidMount() {}
componentDidShow () {}
componentDidShow() {}
componentDidHide () {}
componentDidHide() {}
componentDidCatchError () {}
componentDidCatchError() {}
// 在 App 类中的 render() 函数没有实际作用
// 请勿修改此函数
render () {
render() {
return (
<Provider store={store}>
<Index />
......
......@@ -79,14 +79,14 @@ class Index extends Component {
render() {
return (
<View className='index'>
<Button className='add_btn' onClick={this.props.add}>
<View className="index">
<Button className="add_btn" onClick={this.props.add}>
+
</Button>
<Button className='dec_btn' onClick={this.props.dec}>
<Button className="dec_btn" onClick={this.props.dec}>
-
</Button>
<Button className='dec_btn' onClick={this.props.asyncAdd}>
<Button className="dec_btn" onClick={this.props.asyncAdd}>
async
</Button>
<View>
......
......@@ -4,19 +4,19 @@ const INITIAL_STATE = {
num: 0
}
export default function counter (state = INITIAL_STATE, action) {
export default function counter(state = INITIAL_STATE, action) {
switch (action.type) {
case ADD:
return {
...state,
num: state.num + 1
}
case MINUS:
return {
...state,
num: state.num - 1
}
default:
return state
case MINUS:
return {
...state,
num: state.num - 1
}
default:
return state
}
}
......@@ -2,27 +2,34 @@ import { createStore, applyMiddleware, compose } from 'redux'
import thunkMiddleware from 'redux-thunk'
import rootReducer from '../reducers'
declare global {
interface Window {
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__: (val: any) => any
}
}
const composeEnhancers =
typeof window === 'object' &&
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
// Specify extension’s options like name, actionsBlacklist, actionsCreators, serialize...
}) : compose
typeof window === 'object' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
// Specify extension’s options like name, actionsBlacklist, actionsCreators, serialize...
})
: compose
const middlewares = [
thunkMiddleware
]
const middlewares = [thunkMiddleware]
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(
applyMiddleware(...middlewares),
applyMiddleware(...middlewares)
// other store enhancers if any
)
export default function configStore () {
export default function configStore() {
const store = createStore(rootReducer, enhancer)
return store
}
......@@ -19,13 +19,9 @@
"jsxFactory": "Taro.createElement",
"allowJs": true,
"resolveJsonModule": true,
"typeRoots": [
"node_modules/@types"
]
"typeRoots": ["node_modules/@types"]
},
"exclude": [
"node_modules",
"dist"
],
"compileOnSave": false
"exclude": ["node_modules", "dist"],
"compileOnSave": false,
"include": ["src", "typings"]
}
{
"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