-
-
Notifications
You must be signed in to change notification settings - Fork 153
/
index.js
105 lines (94 loc) · 2.9 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import _ from 'lodash';
import {
RuleTester,
} from 'eslint';
import config from '../../src';
const ruleTester = new RuleTester();
// eslint-disable-next-line no-process-env
(process.env.npm_config_rule ? process.env.npm_config_rule.split(',') : [
'check-access',
'check-alignment',
'check-examples',
'check-indentation',
'check-param-names',
'check-syntax',
'check-tag-names',
'check-types',
'check-values',
'empty-tags',
'implements-on-classes',
'match-description',
'newline-after-description',
'no-types',
'no-undefined-types',
'require-asterisk-prefix',
'require-description',
'require-description-complete-sentence',
'require-example',
'require-hyphen-before-param-description',
'require-jsdoc',
'require-param',
'require-param-description',
'require-param-name',
'require-param-type',
'require-returns',
'require-returns-check',
'require-returns-description',
'require-returns-type',
'valid-types',
]).forEach((ruleName) => {
const rule = config.rules[ruleName];
const parserOptions = {
ecmaVersion: 6,
};
// eslint-disable-next-line global-require, import/no-dynamic-require
const assertions = require(`./assertions/${_.camelCase(ruleName)}`);
if (!_.has(rule, 'meta.schema')) {
const testHasOptions = (item) => {
return item.options;
};
if (
assertions.invalid.some(testHasOptions) ||
assertions.valid.some(testHasOptions)
) {
throw new TypeError(
`Presence of testing options suggests that rule ${ruleName} should ` +
'include a schema.',
);
}
}
assertions.invalid = assertions.invalid.map((assertion) => {
assertion.parserOptions = _.defaultsDeep(assertion.parserOptions, parserOptions);
return assertion;
});
assertions.valid = assertions.valid.map((assertion) => {
if (assertion.errors) {
throw new Error(`Valid assertions for rule ${ruleName} should not have an \`errors\` array.`);
}
assertion.parserOptions = _.defaultsDeep(assertion.parserOptions, parserOptions);
return assertion;
});
/* eslint-disable no-process-env */
if (process.env.npm_config_invalid) {
const indexes = process.env.npm_config_invalid.split(',');
assertions.invalid = assertions.invalid.filter((assertion, idx) => {
return indexes.includes(String(idx)) ||
indexes.includes(String(idx - assertions.invalid.length));
});
if (!process.env.npm_config_valid) {
assertions.valid = [];
}
}
if (process.env.npm_config_valid) {
const indexes = process.env.npm_config_valid.split(',');
assertions.valid = assertions.valid.filter((assertion, idx) => {
return indexes.includes(String(idx)) ||
indexes.includes(String(idx - assertions.valid.length));
});
if (!process.env.npm_config_invalid) {
assertions.invalid = [];
}
}
/* eslint-enable no-process-env */
ruleTester.run(ruleName, rule, assertions);
});