我使用babel-eslint来修饰/修复我的代码。工作得很好,直到我想采用一些ES2017 async await
找到overhere。
我相应地更改了我的React应用程序,但稍有不同:
我的index.js的相关部分:
async function renderApp() {
const store = await configureStore()
const history = syncHistoryWithStore(browserHistory, store, {
selectLocationState: state => state.get('routing')
})
ReactDOM.render(
<AppContainer>
<MuiThemeProvider muiTheme={muiTheme}>
<Provider store={store}>
<Router history={history} routes={routes(store)} />
</Provider>
</MuiThemeProvider>
</AppContainer>,
document.getElementById('root')
)
}
renderApp()
我的商店:
// @flow
import 'babel-polyfill'
import { addFormSubmitSagaTo } from 'redux-form-submit-saga/es/immutable'
import { applyMiddleware, createStore, compose } from 'redux'
import { autoRehydrate, persistStore } from 'redux-persist-immutable'
import { browserHistory } from 'react-router'
import { combineReducers } from 'redux-immutable'
import { fromJS } from 'immutable'
import { routerMiddleware } from 'react-router-redux'
import createSagaMiddleware from 'redux-saga'
import rootReducer from './rootReducer'
import sagas from './rootSaga'
export default function configureStore() {
return new Promise((resolve, reject) => {
try {
const sagaMiddleware = createSagaMiddleware()
const middleware = [ routerMiddleware(browserHistory), sagaMiddleware ]
const enhancer = compose(
autoRehydrate(),
applyMiddleware(...middleware)
)
const store = createStore(
combineReducers(rootReducer),
undefined,
enhancer
)
// Decorate with Redux Form Submit Saga
// and create hook for saga's
const rootSaga = addFormSubmitSagaTo(sagas)
sagaMiddleware.run(rootSaga)
// Persist store to the local storage
persistStore(
store,
{ whitelist: ['auth', 'timezone'] },
() => resolve(store)
)
} catch (e) {
reject(e)
}
})
}
这是我的.eslintrc:
{
"env": {
"browser": true,
"jest/globals": true
},
"extends": [
"standard",
"standard-flow",
"plugin:react/recommended"
],
"plugins": [
"compat",
"jest",
"react"
],
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"comma-dangle": ["warn", "only-multiline"],
"compat/compat": 2,
"jest/no-disabled-tests": "warn",
"jest/no-focused-tests": "error",
"jest/no-identical-title": "error",
"max-len": ["warn", 80],
"no-debugger": 0,
"react/jsx-uses-vars": [2]
}
}
这是我的.babelrc:
{
"plugins": [
"react-hot-loader/babel",
"syntax-flow",
"tcomb",
"transform-class-properties"
],
"presets": [
"es2015",
"react",
["env", {
"targets": {
"browsers": ["last 2 versions"]
}
}]
]
}
但无论我做什么:我一直收到以下错误:
Module build failed: TypeError: Cannot read property 'range' of null
at TokenStore.getTokenBefore (/Users/danielterwiel/dev/nimbus/node_modules/eslint/lib/token-store/index.js:318:17)
at EventEmitter.checkFunction (/Users/danielterwiel/dev/nimbus/node_modules/eslint/lib/rules/generator-star-spacing.js:131:42)
at emitOne (events.js:101:20)
at EventEmitter.emit (events.js:191:7)
at NodeEventGenerator.enterNode (/Users/danielterwiel/dev/nimbus/node_modules/eslint/lib/util/node-event-generator.js:39:22)
at CodePathAnalyzer.enterNode (/Users/danielterwiel/dev/nimbus/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:607:23)
at CommentEventGenerator.enterNode (/Users/danielterwiel/dev/nimbus/node_modules/eslint/lib/util/comment-event-generator.js:98:23)
at Controller.enter (/Users/danielterwiel/dev/nimbus/node_modules/eslint/lib/eslint.js:928:36)
at Controller.__execute (/Users/danielterwiel/dev/nimbus/node_modules/estraverse/estraverse.js:397:31)
at Controller.traverse (/Users/danielterwiel/dev/nimbus/node_modules/estraverse/estraverse.js:501:28)
@ multi react-hot-loader/patch webpack-hot-middleware/client babel-polyfill ./src/index.js ./src/style/main.css
答案 0 :(得分:11)
在ESLint本地支持ES2017 async
/ await
之前,workarounds that were removed中babel-eslint
包括babel-eslint@7.0.0
。您应该将babel-eslint
升级到v7,或者如果您不能,请使用eslint-plugin-babel
的{{3}}。