@@ -9,6 +9,7 @@ const eslint = require("../..");
9
9
const espree = require ( "espree" ) ;
10
10
const sinon = require ( "sinon" ) ;
11
11
const configRule = require ( "../../tools/config-rule" ) ;
12
+ const coreRules = require ( "../../lib/rules" ) ;
12
13
13
14
//------------------------------------------------------------------------------
14
15
// Tests
@@ -23,8 +24,7 @@ describe("eslint-fuzzer", function () {
23
24
*/
24
25
this . timeout ( 15000 ) ; // eslint-disable-line no-invalid-this -- Mocha timeout
25
26
26
- const linter = new eslint . Linter ( { configType : "eslintrc" } ) ;
27
- const coreRules = linter . getRules ( ) ;
27
+ const linter = new eslint . Linter ( ) ;
28
28
const fixableRuleNames = Array . from ( coreRules )
29
29
. filter ( rulePair => rulePair [ 1 ] . meta && rulePair [ 1 ] . meta . fixable )
30
30
. map ( rulePair => rulePair [ 0 ] ) ;
@@ -50,18 +50,33 @@ describe("eslint-fuzzer", function () {
50
50
configRule . createCoreRuleConfigs . restore ( ) ;
51
51
} ) ;
52
52
53
+ afterEach ( ( ) => {
54
+ /*
55
+ * LazyLoadingRuleMap prototype has the `delete` property set to `undefined`
56
+ * in order to prevent accidental mutations, so we need to call `Map.prototype.delete`
57
+ * directly here.
58
+ */
59
+ Map . prototype . delete . call ( coreRules , "test-fuzzer-rule" ) ;
60
+ } ) ;
61
+
62
+ /*
63
+ * LazyLoadingRuleMap prototype has the `set` property set to `undefined`
64
+ * in order to prevent accidental mutations, so we need to call `Map.prototype.set`
65
+ * directly in tests that add `test-fuzzer-rule`.
66
+ */
67
+
53
68
describe ( "when running in crash-only mode" , ( ) => {
54
69
describe ( "when a rule crashes on the given input" , ( ) => {
55
70
it ( "should report the crash with a minimal config" , ( ) => {
56
- linter . defineRule ( "test-fuzzer-rule" , {
71
+ Map . prototype . set . call ( coreRules , "test-fuzzer-rule" , ( ) => ( {
57
72
create : context => ( {
58
73
Program ( ) {
59
74
if ( context . sourceCode . text === "foo" ) {
60
75
throw CRASH_BUG ;
61
76
}
62
77
} ,
63
78
} ) ,
64
- } ) ;
79
+ } ) ) ;
65
80
66
81
const results = fuzz ( {
67
82
count : 1 ,
@@ -82,7 +97,9 @@ describe("eslint-fuzzer", function () {
82
97
83
98
describe ( "when no rules crash" , ( ) => {
84
99
it ( "should return an empty array" , ( ) => {
85
- linter . defineRule ( "test-fuzzer-rule" , { create : ( ) => ( { } ) } ) ;
100
+ Map . prototype . set . call ( coreRules , "test-fuzzer-rule" , ( ) => ( {
101
+ create : ( ) => ( { } ) ,
102
+ } ) ) ;
86
103
87
104
assert . deepStrictEqual (
88
105
fuzz ( {
@@ -109,15 +126,15 @@ describe("eslint-fuzzer", function () {
109
126
110
127
describe ( "when a rule crashes on the given input" , ( ) => {
111
128
it ( "should report the crash with a minimal config" , ( ) => {
112
- linter . defineRule ( "test-fuzzer-rule" , {
129
+ Map . prototype . set . call ( coreRules , "test-fuzzer-rule" , ( ) => ( {
113
130
create : context => ( {
114
131
Program ( ) {
115
132
if ( context . sourceCode . text === "foo" ) {
116
133
throw CRASH_BUG ;
117
134
}
118
135
} ,
119
136
} ) ,
120
- } ) ;
137
+ } ) ) ;
121
138
122
139
const results = fuzz ( {
123
140
count : 1 ,
@@ -139,7 +156,7 @@ describe("eslint-fuzzer", function () {
139
156
describe ( "when a rule's autofix produces valid syntax" , ( ) => {
140
157
it ( "does not report any errors" , ( ) => {
141
158
// Replaces programs that start with "foo" with "bar"
142
- linter . defineRule ( "test-fuzzer-rule" , {
159
+ Map . prototype . set . call ( coreRules , "test-fuzzer-rule" , ( ) => ( {
143
160
meta : { fixable : "code" } ,
144
161
create : context => ( {
145
162
Program ( node ) {
@@ -159,7 +176,7 @@ describe("eslint-fuzzer", function () {
159
176
}
160
177
} ,
161
178
} ) ,
162
- } ) ;
179
+ } ) ) ;
163
180
164
181
const results = fuzz ( {
165
182
count : 1 ,
@@ -180,7 +197,7 @@ describe("eslint-fuzzer", function () {
180
197
describe ( "when a rule's autofix produces invalid syntax on the first pass" , ( ) => {
181
198
it ( "reports an autofix error with a minimal config" , ( ) => {
182
199
// Replaces programs that start with "foo" with invalid syntax
183
- linter . defineRule ( "test-fuzzer-rule" , {
200
+ Map . prototype . set . call ( coreRules , "test-fuzzer-rule" , ( ) => ( {
184
201
meta : { fixable : "code" } ,
185
202
create : context => ( {
186
203
Program ( node ) {
@@ -202,7 +219,7 @@ describe("eslint-fuzzer", function () {
202
219
}
203
220
} ,
204
221
} ) ,
205
- } ) ;
222
+ } ) ) ;
206
223
207
224
const results = fuzz ( {
208
225
count : 1 ,
@@ -237,7 +254,7 @@ describe("eslint-fuzzer", function () {
237
254
const intermediateCode = `bar ${ disableFixableRulesComment } ` ;
238
255
239
256
// Replaces programs that start with "foo" with invalid syntax
240
- linter . defineRule ( "test-fuzzer-rule" , {
257
+ Map . prototype . set . call ( coreRules , "test-fuzzer-rule" , ( ) => ( {
241
258
meta : { fixable : "code" } ,
242
259
create : context => ( {
243
260
Program ( node ) {
@@ -262,7 +279,7 @@ describe("eslint-fuzzer", function () {
262
279
}
263
280
} ,
264
281
} ) ,
265
- } ) ;
282
+ } ) ) ;
266
283
267
284
const results = fuzz ( {
268
285
count : 1 ,
@@ -292,7 +309,7 @@ describe("eslint-fuzzer", function () {
292
309
describe ( "when a rule crashes on the second autofix pass" , ( ) => {
293
310
it ( "reports a crash error with a minimal config" , ( ) => {
294
311
// Replaces programs that start with "foo" with invalid syntax
295
- linter . defineRule ( "test-fuzzer-rule" , {
312
+ Map . prototype . set . call ( coreRules , "test-fuzzer-rule" , ( ) => ( {
296
313
meta : { fixable : "code" } ,
297
314
create : context => ( {
298
315
Program ( node ) {
@@ -313,7 +330,7 @@ describe("eslint-fuzzer", function () {
313
330
}
314
331
} ,
315
332
} ) ,
316
- } ) ;
333
+ } ) ) ;
317
334
318
335
const results = fuzz ( {
319
336
count : 1 ,
0 commit comments