Skip to content

Commit a211721

Browse files
committed
fixing tests
1 parent 786c2da commit a211721

File tree

6 files changed

+31
-50
lines changed

6 files changed

+31
-50
lines changed

docs/rules/connect-prefer-minimum-two-arguments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This rule enforces that Second argument is provided explicitly.
1111
The following pattern is considered incorrect:
1212

1313
```js
14-
connect(mapStateToProps, null, mergeProps)(Component)
14+
connect(mapStateToProps)(Component)
1515
```
1616

1717
The following patterns are considered correct:

index.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,31 @@ const rules = {
66
'prefer-separate-component-file': require('./lib/rules/prefer-separate-component-file'),
77
};
88

9+
function configureAsError() {
10+
const result = {};
11+
Object.keys(rules).forEach((key) => {
12+
result[`react-redux/${key}`] = 2;
13+
});
14+
return result;
15+
}
16+
17+
const activeRulesConfig = configureAsError();
18+
919
module.exports = {
20+
deprecatedRules: [],
1021
rules,
1122
configs: {
1223
recommended: {
13-
'react-redux/connect-prefer-minimum-two-arguments': 0,
14-
'react-redux/connect-prefer-named-arguments': 2,
15-
'react-redux/mapStateToProps-prefer-parameters-names': 2,
16-
'react-redux/mapDispatchToProps-prefer-parameters-names': 2,
17-
'prefer-separate-component-file/mapDispatchToProps-prefer-parameters-names': 1,
24+
rules: {
25+
'react-redux/connect-prefer-minimum-two-arguments': 0,
26+
'react-redux/connect-prefer-named-arguments': 2,
27+
'react-redux/mapStateToProps-prefer-parameters-names': 2,
28+
'react-redux/mapDispatchToProps-prefer-parameters-names': 2,
29+
'react-redux/prefer-separate-component-file': 1,
30+
},
1831
},
1932
all: {
20-
rules,
33+
rules: activeRulesConfig,
2134
},
2235
},
2336
};

lib/rules/connect-prefer-minimum-two-arguments.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const isReactReduxConnect = require('../isReactReduxConnect');
22

33
const report = function (context, node) {
44
context.report({
5-
message: 'Connect function should have 2 arguments',
5+
message: 'Connect function should have at least 2 arguments.',
66
node,
77
});
88
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"lint": "eslint ./",
1515
"test": "npm run lint && mocha tests --recursive",
1616
"test-single": "mocha tests/lib/rules/prefer-separate-component-file",
17-
"debug-test": "mocha --debug-brk --inspect tests/lib/rules/prefer-separate-component-file"
17+
"debug-test": "mocha --debug-brk --inspect tests/index.js"
1818
},
1919
"repository": {
2020
"type": "git",

tests/index.js

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,48 +19,24 @@ describe('all rule files should be exported by the plugin', () => {
1919
});
2020
});
2121

22-
describe('deprecated rules', () => {
23-
it('marks all deprecated rules as deprecated', () => {
24-
ruleFiles.forEach((ruleName) => {
25-
const inDeprecatedRules = Boolean(plugin.deprecatedRules[ruleName]);
26-
const isDeprecated = plugin.rules[ruleName].meta.deprecated;
27-
if (inDeprecatedRules) {
28-
assert(isDeprecated, `${ruleName} metadata should mark it as deprecated`);
29-
} else {
30-
assert(!isDeprecated, `${ruleName} metadata should not mark it as deprecated`);
31-
}
32-
});
33-
});
34-
});
35-
3622
describe('configurations', () => {
3723
it('should export a \'recommended\' configuration', () => {
3824
assert(plugin.configs.recommended);
3925
Object.keys(plugin.configs.recommended.rules).forEach((configName) => {
40-
assert.equal(configName.indexOf('react/'), 0);
41-
const ruleName = configName.substring('react/'.length);
26+
assert.equal(configName.indexOf('react-redux/'), 0);
27+
const ruleName = configName.substring('react-redux/'.length);
4228
assert(plugin.rules[ruleName]);
4329
});
44-
45-
ruleFiles.forEach((ruleName) => {
46-
const inRecommendedConfig = Boolean(plugin.configs.recommended.rules[`react/${ruleName}`]);
47-
const isRecommended = plugin.rules[ruleName].meta.docs.recommended;
48-
if (inRecommendedConfig) {
49-
assert(isRecommended, `${ruleName} metadata should mark it as recommended`);
50-
} else {
51-
assert(!isRecommended, `${ruleName} metadata should not mark it as recommended`);
52-
}
53-
});
5430
});
5531
it('should export a \'all\' configuration', () => {
5632
assert(plugin.configs.all);
5733
Object.keys(plugin.configs.all.rules).forEach((configName) => {
58-
assert.equal(configName.indexOf('react/'), 0);
34+
assert.equal(configName.indexOf('react-redux/'), 0);
5935
assert.equal(plugin.configs.all.rules[configName], 2);
6036
});
6137
ruleFiles.forEach((ruleName) => {
6238
const inDeprecatedRules = Boolean(plugin.deprecatedRules[ruleName]);
63-
const inAllConfig = Boolean(plugin.configs.all.rules[`react/${ruleName}`]);
39+
const inAllConfig = Boolean(plugin.configs.all.rules[`react-redux/${ruleName}`]);
6440
assert(inDeprecatedRules || inAllConfig);
6541
});
6642
});
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require('babel-eslint');
22

3-
const rule = require('../../../lib/rules/prefer-explicit-mapDispatchToProps');
3+
const rule = require('../../../lib/rules/connect-prefer-minimum-two-arguments');
44
const { RuleTester } = require('eslint');
55

66
const parserOptions = {
@@ -13,25 +13,17 @@ const parserOptions = {
1313

1414
const ruleTester = new RuleTester({ parserOptions });
1515

16-
ruleTester.run('prefer-explicit-mapDispatchToProps', rule, {
16+
ruleTester.run('connect-prefer-minimum-two-arguments', rule, {
1717
valid: [
1818
'connect(mapStateToProps, mapDispatchToProps, mergeProps, options)(Component)',
1919
'connect(mapStateToProps, mapDispatchToProps)(Component)',
2020
],
2121
invalid: [{
22-
code: 'connect(mapStateToProps, null, mergeProps)(Component)',
22+
code: 'connect(mapStateToProps)(Component)',
2323
errors: [
2424
{
25-
message: 'Connect function should have explicit mapDispatchToProps argument',
25+
message: 'Connect function should have at least 2 arguments.',
2626
},
2727
],
28-
}, {
29-
code: 'connect(mapStateToProps, undefined)(Component)',
30-
errors: [
31-
{
32-
message: 'Connect function should have explicit mapDispatchToProps argument',
33-
},
34-
],
35-
},
36-
],
28+
}],
3729
});

0 commit comments

Comments
 (0)