forked from jsx-eslint/eslint-plugin-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (62 loc) · 2.37 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
58
59
60
61
62
63
64
65
66
67
68
69
/* eslint-env mocha */
'use strict';
const plugin = require('..');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const ruleFiles = fs.readdirSync(path.resolve(__dirname, '../lib/rules/'))
.map(f => path.basename(f, '.js'));
describe('all rule files should be exported by the plugin', () => {
ruleFiles.forEach(ruleName => {
it(`should export ${ruleName}`, () => {
assert.equal(
plugin.rules[ruleName],
require(path.join('../lib/rules', ruleName))
);
});
});
});
describe('deprecated rules', () => {
it('marks all deprecated rules as deprecated', () => {
ruleFiles.forEach(ruleName => {
const inDeprecatedRules = Boolean(plugin.deprecatedRules[ruleName]);
const isDeprecated = plugin.rules[ruleName].meta.deprecated;
if (inDeprecatedRules) {
assert(isDeprecated, `${ruleName} metadata should mark it as deprecated`);
} else {
assert(!isDeprecated, `${ruleName} metadata should not mark it as deprecated`);
}
});
});
});
describe('configurations', () => {
it('should export a \'recommended\' configuration', () => {
assert(plugin.configs.recommended);
Object.keys(plugin.configs.recommended.rules).forEach(configName => {
assert.equal(configName.indexOf('react/'), 0);
const ruleName = configName.substring('react/'.length);
assert(plugin.rules[ruleName]);
});
ruleFiles.forEach(ruleName => {
const inRecommendedConfig = Boolean(plugin.configs.recommended.rules[`react/${ruleName}`]);
const 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', () => {
assert(plugin.configs.all);
Object.keys(plugin.configs.all.rules).forEach(configName => {
assert.equal(configName.indexOf('react/'), 0);
assert.equal(plugin.configs.all.rules[configName], 2);
});
ruleFiles.forEach(ruleName => {
const inDeprecatedRules = Boolean(plugin.deprecatedRules[ruleName]);
const inAllConfig = Boolean(plugin.configs.all.rules[`react/${ruleName}`]);
assert(inDeprecatedRules ^ inAllConfig);
});
});
});