-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
index.js
57 lines (51 loc) · 1.93 KB
/
index.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
/* eslint-env mocha */
'use strict';
var plugin = require('..');
var assert = require('assert');
var fs = require('fs');
var path = require('path');
var ruleFiles = fs.readdirSync(path.resolve(__dirname, '../lib/rules/'))
.map(function(f) {
return path.basename(f, '.js');
});
describe('all rule files should be exported by the plugin', function() {
ruleFiles.forEach(function(ruleName) {
it('should export ' + ruleName, function() {
assert.equal(
plugin.rules[ruleName],
require(path.join('../lib/rules', ruleName))
);
});
});
});
describe('configurations', function() {
it('should export a \'recommended\' configuration', function() {
assert(plugin.configs.recommended);
Object.keys(plugin.configs.recommended.rules).forEach(function (configName) {
assert.equal(configName.indexOf('react/'), 0);
var ruleName = configName.substring('react/'.length);
assert(plugin.rules[ruleName]);
});
ruleFiles.forEach(function(ruleName) {
var inRecommendedConfig = Boolean(plugin.configs.recommended.rules['react/' + ruleName]);
var isRecommended = plugin.rules[ruleName].meta.docs.recommended;
if (inRecommendedConfig) {
assert(isRecommended, ruleName + ' metadata should mark it as recommended');
} else {
assert(!isRecommended, ruleName + ' metadata should not mark it as recommended');
}
});
});
it('should export a \'all\' configuration', function() {
assert(plugin.configs.all);
Object.keys(plugin.configs.all.rules).forEach(function(configName) {
assert.equal(configName.indexOf('react/'), 0);
assert.equal(plugin.configs.all.rules[configName], 2);
});
ruleFiles.forEach(function(ruleName) {
var inDeprecatedRules = Boolean(plugin.deprecatedRules[ruleName]);
var inAllConfig = Boolean(plugin.configs.all.rules['react/' + ruleName]);
assert(inDeprecatedRules ^ inAllConfig);
});
});
});