-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.d.ts
199 lines (168 loc) · 4.01 KB
/
index.d.ts
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
export type TestCase = {
/**
* The code of the test case.
*/
code: string;
/**
* The filename for this `code` property.
*/
codeFilename?: string;
/**
* Description of the test case.
*/
description?: string;
/**
* Maps to Jest's `test.only`. Default: `false`.
*
* @see https://jestjs.io/docs/en/api#testonlyname-fn-timeout
*/
only?: boolean;
/**
* Maps to Jest's `test.skip`. Default: `false`.
*
* @see https://jestjs.io/docs/api#testskipname-fn
*/
skip?: boolean;
};
export type AcceptTestCase = TestCase;
export type Warning = {
/**
* Expected message from the test case. Usually exported from the plugin.
* Optional if `warnings` is used.
*/
message?: string;
/**
* Expected line number of the warning.
*/
line?: number;
/**
* Expected column number of the warning.
*/
column?: number;
/**
* Expected end line number of the warning.
*/
endLine?: number;
/**
* Expected end column number of the warning.
*/
endColumn?: number;
};
/**
* Use the `warnings` property, rather than `message`, `line`, and `column`,
* if the test case is expected to produce more than one warning.
*/
export type RejectTestCase = TestCase &
Warning & {
/**
* Expected fixed code of the test case. Optional if `fix` isn't `true`.
*/
fixed?: string;
/**
* Don't check the `fixed` code. Default: `false`.
*/
unfixable?: boolean;
/**
* Warning objects containing expected `message`, `line` and `column` etc.
* Optional if `message` is used.
*/
warnings?: Warning[];
};
export type TestSchema = {
/**
* Name of the rule being tested. Usually exported from the plugin.
*/
ruleName: string;
/**
* Config to pass to the rule.
*/
config: unknown;
/**
* Accept test cases.
*/
accept?: AcceptTestCase[];
/**
* Reject test cases.
*/
reject?: RejectTestCase[];
/**
* Turn on autofix. Default: `false`.
*/
fix?: boolean;
/**
* Maps to Stylelint's `plugins` configuration property.
*
* Path to the file that exports the plugin object, relative to the root.
* Usually it's the same path as a `main` property in plugin's `package.json`.
*
* If you're testing a plugin pack, it's the path to the file that exports the array of plugin objects.
*
* Optional, if `plugins` option was passed to advanced configuration with `getTestRule()`.
*
* @see https://stylelint.io/user-guide/configure#plugins
*/
plugins?: import('stylelint').Config['plugins'];
/**
* Maps to Stylelint's `customSyntax` option.
*
* @see https://stylelint.io/user-guide/usage/options#customsyntax
*/
customSyntax?: string;
/**
* Maps to Stylelint's `codeFilename` option.
*
* @see https://stylelint.io/user-guide/usage/options#codefilename
*/
codeFilename?: string;
/**
* Maps to Jest's `test.only`. Default: `false`.
*
* @see https://jestjs.io/docs/en/api#testonlyname-fn-timeout
*/
only?: boolean;
/**
* Maps to Jest's `test.skip`. Default: `false`.
*
* @see https://jestjs.io/docs/api#testskipname-fn
*/
skip?: boolean;
/**
* Loads the lint function.
*/
loadLint?: () => Promise<(typeof import('stylelint'))['lint']>;
};
type GetTestRuleOptions = {
plugins?: TestSchema['plugins'];
loadLint?: TestSchema['loadLint'];
};
/**
* Test a rule with the specified schema.
*/
export type TestRule = (schema: TestSchema) => void;
/**
* Create a `testRule()` function with any specified plugins.
*/
export function getTestRule(options?: GetTestRuleOptions): TestRule;
export type ConfigCase = {
config: unknown;
description?: string;
only?: boolean;
skip?: boolean;
};
/**
* Test configurations for a rule.
*/
export type TestRuleConfigs = (
schema: Pick<TestSchema, 'ruleName' | 'plugins' | 'only' | 'skip' | 'loadLint'> & {
accept?: ConfigCase[];
reject?: ConfigCase[];
},
) => void;
/**
* Create a `testRuleConfigs()` function with any specified plugins.
*/
export function getTestRuleConfigs(options?: GetTestRuleOptions): TestRuleConfigs;
declare global {
var testRule: TestRule;
var testRuleConfigs: TestRuleConfigs;
}