Javascript 围绕箭头体ESlint的意外块语句
为什么这段代码会给我lint警告?解决办法是什么?任何帮助都将不胜感激Javascript 围绕箭头体ESlint的意外块语句,javascript,reactjs,ecmascript-6,eslint,arrow-functions,Javascript,Reactjs,Ecmascript 6,Eslint,Arrow Functions,为什么这段代码会给我lint警告?解决办法是什么?任何帮助都将不胜感激 const configureStore = () => { return createStore( rootReducer, middleware ); }; 这是我的eslint配置 { "parser": "babel-eslint", "extends": "airbnb", "plugins": [ "react" ], "rules": {
const configureStore = () => {
return createStore(
rootReducer,
middleware
);
};
这是我的eslint配置
{
"parser": "babel-eslint",
"extends": "airbnb",
"plugins": [
"react"
],
"rules": {
"comma-dangle": 0,
"object-curly-spacing": 0,
"no-multiple-empty-lines": [
"error",
{
"max": 1
}
],
"arrow-body-style": 1,
"newline-per-chained-call": 1
},
"env": {
"browser": true,
"node": true,
"mocha": true
}
}
在不知道特定lint配置的情况下进行调试有点困难 我唯一的猜测是,如果在只包含一个表达式的箭头体上使用一个块,那么您的linter的配置方式就会出现问题 试一试 如果这不起作用,请提供评论 -- 另外,如果你把你的代码粘贴进去,就不会有线头警告了
const configureStore = () => {
return createStore(
rootReducer,
middleware
);
};
将箭头后面的大括号更改为括号
const configureStore = () => (
createStore(
rootReducer,
middleware
);
);
这对我有用。
这是关于箭头体的主题--样式
箭头函数体中需要大括号(箭头体样式)
选择权
这条规则有一两个选择。第一个是字符串,可以是:
- “始终”在函数体周围强制使用大括号
- “按需”在可以省略的地方不强制使用大括号(默认)
- “从不”在函数体周围不强制使用大括号(将箭头函数约束为返回表达式的角色) 当您根据需要进行配置时
您可以从中找到更多详细信息。它删除了lint警告,但应用程序已停止工作。它没有得到
createStore
“它没有得到createStore
”-这到底是什么意思?createStore
是否在您的模块范围内?在“连接(登录)”的上下文或道具中找不到“store”。将根组件包装在中,或者将“store”作为prop显式传递给“Connect(Login)”。
是的。我正在从redux导入createStore
。好的,这是一个完全独立的问题。该错误与configureStore
、createStore
、rootReducer
或中间件
无关。
const configureStore = () => (
createStore(
rootReducer,
middleware
);
);
//this is a bad style
let foo = () => {
return {
bar: {
foo: 1,
bar: 2,
}
};
};
// This is good
let foo = () => ({
bar: {
foo: 1,
bar: 2,
}
});