eslint-plugin-react-redux
Advanced tools
Comparing version
@@ -32,2 +32,6 @@ # Enforces that all mapDispatchToProps parameters have specific names. (react-redux/mapDispatchToProps-prefer-named-parameters) | ||
```js | ||
const mapDispatchToProps(dispatch, {prop1, prop2}) => {} | ||
``` | ||
```js | ||
const mapDispatchToProps(dispatch) => {} | ||
@@ -34,0 +38,0 @@ ``` |
@@ -39,2 +39,6 @@ # Enforces that mapStateToProps does not bind complete store to a component. (react-redux/mapStateToProps-no-store) | ||
```js | ||
const mapStateToProps = ({isActive}) => {isActive} | ||
``` | ||
```js | ||
connect((state) => ({isActive: state.isActive}), null)(App) | ||
@@ -41,0 +45,0 @@ ``` |
@@ -32,3 +32,7 @@ # Enforces that all mapStateToProps parameters have specific names. (react-redux/mapStateToProps-prefer-named-parameters) | ||
```js | ||
const mapStateToProps = ({isActive}) => {isActive} | ||
``` | ||
```js | ||
connect((state) => state, null)(App) | ||
``` |
@@ -17,3 +17,3 @@ const isReactReduxConnect = require('../isReactReduxConnect'); | ||
params.forEach((param, i) => { | ||
if (argumentNames[i] && argumentNames[i] !== param.name) { | ||
if (argumentNames[i] && param.type !== 'ObjectPattern' && argumentNames[i] !== param.name) { | ||
report(context, param, i); | ||
@@ -20,0 +20,0 @@ } |
@@ -11,4 +11,7 @@ const utils = require('../utils'); | ||
const getFirstParamName = node => | ||
node.params && node.params[0] && node.params[0].name; | ||
// first param name or false for destructuring assignment; | ||
const getFirstParamName = (node) => { | ||
const firstParam = node.params && node.params[0]; | ||
return firstParam && firstParam.type === 'Identifier' && firstParam.name; | ||
}; | ||
@@ -51,6 +54,6 @@ const propertyIsStore = (prop, storeName) => { | ||
const body = decl.init.body; | ||
const firstParamName = decl.init.params && | ||
decl.init.params[0] && | ||
decl.init.params[0].name; | ||
checkFunction(context, body, firstParamName); | ||
const firstParamName = getFirstParamName(decl.init); | ||
if (firstParamName) { | ||
checkFunction(context, body, firstParamName); | ||
} | ||
} | ||
@@ -61,3 +64,6 @@ }); | ||
if (node.id && node.id.name === 'mapStateToProps') { | ||
checkFunction(context, node.body, getFirstParamName(node)); | ||
const firstParamName = getFirstParamName(node); | ||
if (firstParamName) { | ||
checkFunction(context, node.body, firstParamName); | ||
} | ||
} | ||
@@ -69,3 +75,6 @@ }, | ||
if (mapStateToProps && mapStateToProps.body) { | ||
checkFunction(context, mapStateToProps.body, getFirstParamName(mapStateToProps)); | ||
const firstParamName = getFirstParamName(mapStateToProps); | ||
if (firstParamName) { | ||
checkFunction(context, mapStateToProps.body, firstParamName); | ||
} | ||
} | ||
@@ -72,0 +81,0 @@ } |
@@ -17,3 +17,3 @@ const isReactReduxConnect = require('../isReactReduxConnect'); | ||
params.forEach((param, i) => { | ||
if (argumentNames[i] && argumentNames[i] !== param.name) { | ||
if (argumentNames[i] && param.type !== 'ObjectPattern' && argumentNames[i] !== param.name) { | ||
report(context, param, i); | ||
@@ -20,0 +20,0 @@ } |
{ | ||
"name": "eslint-plugin-react-redux", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "Enforcing best practices for react-redux", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -20,2 +20,3 @@ require('babel-eslint'); | ||
'connect(mapStateToProps, mapDispatchToProps)(Component)', | ||
'connect({prop1, prop2}, {action1, action2})(Component)', | ||
], | ||
@@ -22,0 +23,0 @@ invalid: [{ |
@@ -19,2 +19,3 @@ require('babel-eslint'); | ||
'const mapDispatchToProps = (dispatch, ownProps) => {}', | ||
'const mapDispatchToProps = (dispatch, {prop1, prop2}) => {}', | ||
'const mapDispatchToProps = (dispatch) => {}', | ||
@@ -21,0 +22,0 @@ 'const mapDispatchToProps = (dispatch, ownProps, moreArgs) => {}', |
@@ -60,2 +60,8 @@ require('babel-eslint'); | ||
connect(mapStateToProps, null)(Alert);`, | ||
`const mapStateToProps = ({ header }) => ({ | ||
isLoggedIn: header.user && header.user.isLoggedIn, | ||
}); `, | ||
'const mapStateToProps = ({header}, ownProps) => {header};', | ||
'connect(({header}, ownProps) => {header})(App);', | ||
'connect(({header}, {ownProp1}) => {header, ownProp1})(App);', | ||
], | ||
@@ -62,0 +68,0 @@ invalid: [{ |
@@ -18,2 +18,3 @@ require('babel-eslint'); | ||
valid: [ | ||
'const mapStateToProps = ({prop1, prop2}, {ownProp1, ownProp2}) => {}', | ||
'const mapStateToProps = (state, ownProps) => {}', | ||
@@ -27,2 +28,3 @@ 'const mapStateToProps = (state) => {}', | ||
'connect(null, null)(App)', | ||
'const mapStateToProps = ({prop1, prop2}, ownProps) => {}', | ||
], | ||
@@ -29,0 +31,0 @@ invalid: [{ |
35301
3.3%856
2.27%