Skip to content

Commit d578b9c

Browse files
fix: mapmapStateToProps-no-Store bug getting body of a var (#5)
1 parent 30741b2 commit d578b9c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/rules/mapStateToProps-no-store.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ module.exports = function (context) {
4444
CallExpression(node) {
4545
if (isReactReduxConnect(node)) {
4646
const mapStateToProps = node.arguments && node.arguments[0];
47-
checkFunction(context, mapStateToProps.body, getFirstParamName(mapStateToProps));
47+
if (mapStateToProps.body) {
48+
checkFunction(context, mapStateToProps.body, getFirstParamName(mapStateToProps));
49+
}
4850
}
4951
},
5052
};

tests/lib/rules/mapStateToProps-no-store.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const ruleTester = new RuleTester({ parserOptions });
1515

1616
ruleTester.run('mapStateToProps-no-store', rule, {
1717
valid: [
18+
'export default connect(() => {})(Alert)',
19+
'export default connect(() => {})(Alert)',
20+
'export default connect(null, null)(Alert)',
1821
'connect((state) => ({isActive: state.isActive}), null)(App)',
1922
`connect(
2023
(state) => {
@@ -41,6 +44,8 @@ ruleTester.run('mapStateToProps-no-store', rule, {
4144
}`,
4245
'const mapStateToProps = (state, ownProps) => {}',
4346
'const mapStateToProps = (state) => {isActive: state.isActive}',
47+
`const mapStateToProps = (state, ownProps) => {};
48+
connect(mapStateToProps, null)(Alert);`,
4449
],
4550
invalid: [{
4651
code: 'const mapStateToProps = (state) => state',
@@ -92,5 +97,13 @@ ruleTester.run('mapStateToProps-no-store', rule, {
9297
message: 'mapStateToProps should not return complete store object',
9398
},
9499
],
100+
}, {
101+
code: `const mapStateToProps = (state, ownProps) => state;
102+
connect(mapStateToProps, null)(Alert);`,
103+
errors: [
104+
{
105+
message: 'mapStateToProps should not return complete store object',
106+
},
107+
],
95108
}],
96109
});

0 commit comments

Comments
 (0)