-
-
Notifications
You must be signed in to change notification settings - Fork 154
/
Copy pathindex.js
111 lines (97 loc) · 2.75 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
106
107
108
109
110
111
import assert from 'assert';
import {
camelCase,
} from 'lodash';
import Ajv from 'ajv';
import {
RuleTester,
} from 'eslint';
import plugin from '../../src';
const ruleTester = new RuleTester();
const reportingRules = [
'array-style-complex-type',
'array-style-simple-type',
'arrow-parens',
'boolean-style',
'define-flow-type',
'delimiter-dangle',
'enforce-line-break',
'enforce-suppression-code',
'generic-spacing',
'newline-after-flow-annotation',
'no-dupe-keys',
'no-existential-type',
'no-flow-fix-me-comments',
'no-mutable-array',
'no-primitive-constructor-types',
'no-types-missing-file-annotation',
'no-unused-expressions',
'no-weak-types',
'no-internal-flow-type',
'no-mixed',
'object-type-curly-spacing',
'object-type-delimiter',
'quotes',
'require-compound-type-alias',
'require-inexact-type',
'require-indexer-name',
'require-exact-type',
'require-parameter-type',
'require-readonly-react-props',
'require-return-type',
'require-types-at-top',
'require-valid-file-annotation',
'require-variable-type',
'semi',
'sort-keys',
'space-after-type-colon',
'space-before-generic-bracket',
'space-before-type-colon',
'spread-exact-type',
'type-id-match',
'type-import-style',
'union-intersection-spacing',
'use-flow-type',
'use-read-only-spread',
'valid-syntax',
];
const parser = require.resolve('babel-eslint');
const ajv = new Ajv({
verbose: true,
});
for (const ruleName of reportingRules) {
// eslint-disable-next-line global-require, import/no-dynamic-require
const assertions = require('./assertions/' + camelCase(ruleName));
if (assertions.misconfigured) {
for (const misconfiguration of assertions.misconfigured) {
RuleTester.describe(ruleName, () => {
RuleTester.describe('misconfigured', () => {
RuleTester.it(JSON.stringify(misconfiguration.options), () => {
const schema = plugin.rules[ruleName].schema && plugin.rules[ruleName].schema;
if (!schema) {
throw new Error('No schema.');
}
const validateSchema = ajv.compile({
items: schema,
type: 'array',
});
validateSchema(misconfiguration.options);
if (!validateSchema.errors) {
throw new Error('Schema was valid.');
}
assert.deepStrictEqual(validateSchema.errors, misconfiguration.errors);
});
});
});
}
}
assertions.invalid = assertions.invalid.map((assertion) => {
assertion.parser = parser;
return assertion;
});
assertions.valid = assertions.valid.map((assertion) => {
assertion.parser = parser;
return assertion;
});
ruleTester.run(ruleName, plugin.rules[ruleName], assertions);
}