-
Notifications
You must be signed in to change notification settings - Fork 17
/
mapDispatchToProps-prefer-parameters-names.js
57 lines (53 loc) · 1.81 KB
/
mapDispatchToProps-prefer-parameters-names.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const rule = require('../../../lib/rules/mapDispatchToProps-prefer-parameters-names');
const RuleTester = require('eslint').RuleTester;
const codeSamples = require('../../code-sanity-samples');
const parserOptions = {
ecmaVersion: 2018,
sourceType: 'module',
};
const ruleTester = new RuleTester({ parserOptions });
ruleTester.run('mapDispatchToProps-prefer-parameters-names', rule, {
valid: [
...codeSamples,
'const mapDispatchToProps = (dispatch, ownProps) => {}',
'const mapDispatchToProps = (dispatch, {prop1, prop2}) => {}',
'const mapDispatchToProps = (dispatch) => {}',
'const mapDispatchToProps = (dispatch, ownProps, moreArgs) => {}',
'const mapDispatchToProps = {anAction: anAction}',
'connect((state) => state, {anAction: anAction})(App)',
'connect(null, null)(App)',
'connect((state) => state, (dispatch, ownProps, moreArgs) => {})(App)',
'function mapDispatchToProps(dispatch, ownProps) {}',
],
invalid: [{
code: 'const mapDispatchToProps = (anyOtherName) => {}',
errors: [
{
message: 'mapDispatchToProps function parameter #0 should be named dispatch',
},
],
}, {
code: 'const mapDispatchToProps = (anyName, anyOtherName) => {}',
errors: [
{
message: 'mapDispatchToProps function parameter #0 should be named dispatch',
}, {
message: 'mapDispatchToProps function parameter #1 should be named ownProps',
},
],
}, {
code: 'function mapDispatchToProps(anyOtherName) {}',
errors: [
{
message: 'mapDispatchToProps function parameter #0 should be named dispatch',
},
],
}, {
code: 'connect((state) => state, (anyOtherName) => {})(App)',
errors: [
{
message: 'mapDispatchToProps function parameter #0 should be named dispatch',
},
],
}],
});