@@ -9,6 +9,7 @@ const eslint = require("../..");
99const espree = require ( "espree" ) ;
1010const sinon = require ( "sinon" ) ;
1111const configRule = require ( "../../tools/config-rule" ) ;
12+ const coreRules = require ( "../../lib/rules" ) ;
1213
1314//------------------------------------------------------------------------------
1415// Tests
@@ -23,8 +24,7 @@ describe("eslint-fuzzer", function () {
2324 */
2425 this . timeout ( 15000 ) ; // eslint-disable-line no-invalid-this -- Mocha timeout
2526
26- const linter = new eslint . Linter ( { configType : "eslintrc" } ) ;
27- const coreRules = linter . getRules ( ) ;
27+ const linter = new eslint . Linter ( ) ;
2828 const fixableRuleNames = Array . from ( coreRules )
2929 . filter ( rulePair => rulePair [ 1 ] . meta && rulePair [ 1 ] . meta . fixable )
3030 . map ( rulePair => rulePair [ 0 ] ) ;
@@ -50,18 +50,33 @@ describe("eslint-fuzzer", function () {
5050 configRule . createCoreRuleConfigs . restore ( ) ;
5151 } ) ;
5252
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+
5368 describe ( "when running in crash-only mode" , ( ) => {
5469 describe ( "when a rule crashes on the given input" , ( ) => {
5570 it ( "should report the crash with a minimal config" , ( ) => {
56- linter . defineRule ( "test-fuzzer-rule" , {
71+ Map . prototype . set . call ( coreRules , "test-fuzzer-rule" , ( ) => ( {
5772 create : context => ( {
5873 Program ( ) {
5974 if ( context . sourceCode . text === "foo" ) {
6075 throw CRASH_BUG ;
6176 }
6277 } ,
6378 } ) ,
64- } ) ;
79+ } ) ) ;
6580
6681 const results = fuzz ( {
6782 count : 1 ,
@@ -82,7 +97,9 @@ describe("eslint-fuzzer", function () {
8297
8398 describe ( "when no rules crash" , ( ) => {
8499 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+ } ) ) ;
86103
87104 assert . deepStrictEqual (
88105 fuzz ( {
@@ -109,15 +126,15 @@ describe("eslint-fuzzer", function () {
109126
110127 describe ( "when a rule crashes on the given input" , ( ) => {
111128 it ( "should report the crash with a minimal config" , ( ) => {
112- linter . defineRule ( "test-fuzzer-rule" , {
129+ Map . prototype . set . call ( coreRules , "test-fuzzer-rule" , ( ) => ( {
113130 create : context => ( {
114131 Program ( ) {
115132 if ( context . sourceCode . text === "foo" ) {
116133 throw CRASH_BUG ;
117134 }
118135 } ,
119136 } ) ,
120- } ) ;
137+ } ) ) ;
121138
122139 const results = fuzz ( {
123140 count : 1 ,
@@ -139,7 +156,7 @@ describe("eslint-fuzzer", function () {
139156 describe ( "when a rule's autofix produces valid syntax" , ( ) => {
140157 it ( "does not report any errors" , ( ) => {
141158 // Replaces programs that start with "foo" with "bar"
142- linter . defineRule ( "test-fuzzer-rule" , {
159+ Map . prototype . set . call ( coreRules , "test-fuzzer-rule" , ( ) => ( {
143160 meta : { fixable : "code" } ,
144161 create : context => ( {
145162 Program ( node ) {
@@ -159,7 +176,7 @@ describe("eslint-fuzzer", function () {
159176 }
160177 } ,
161178 } ) ,
162- } ) ;
179+ } ) ) ;
163180
164181 const results = fuzz ( {
165182 count : 1 ,
@@ -180,7 +197,7 @@ describe("eslint-fuzzer", function () {
180197 describe ( "when a rule's autofix produces invalid syntax on the first pass" , ( ) => {
181198 it ( "reports an autofix error with a minimal config" , ( ) => {
182199 // Replaces programs that start with "foo" with invalid syntax
183- linter . defineRule ( "test-fuzzer-rule" , {
200+ Map . prototype . set . call ( coreRules , "test-fuzzer-rule" , ( ) => ( {
184201 meta : { fixable : "code" } ,
185202 create : context => ( {
186203 Program ( node ) {
@@ -202,7 +219,7 @@ describe("eslint-fuzzer", function () {
202219 }
203220 } ,
204221 } ) ,
205- } ) ;
222+ } ) ) ;
206223
207224 const results = fuzz ( {
208225 count : 1 ,
@@ -237,7 +254,7 @@ describe("eslint-fuzzer", function () {
237254 const intermediateCode = `bar ${ disableFixableRulesComment } ` ;
238255
239256 // Replaces programs that start with "foo" with invalid syntax
240- linter . defineRule ( "test-fuzzer-rule" , {
257+ Map . prototype . set . call ( coreRules , "test-fuzzer-rule" , ( ) => ( {
241258 meta : { fixable : "code" } ,
242259 create : context => ( {
243260 Program ( node ) {
@@ -262,7 +279,7 @@ describe("eslint-fuzzer", function () {
262279 }
263280 } ,
264281 } ) ,
265- } ) ;
282+ } ) ) ;
266283
267284 const results = fuzz ( {
268285 count : 1 ,
@@ -292,7 +309,7 @@ describe("eslint-fuzzer", function () {
292309 describe ( "when a rule crashes on the second autofix pass" , ( ) => {
293310 it ( "reports a crash error with a minimal config" , ( ) => {
294311 // Replaces programs that start with "foo" with invalid syntax
295- linter . defineRule ( "test-fuzzer-rule" , {
312+ Map . prototype . set . call ( coreRules , "test-fuzzer-rule" , ( ) => ( {
296313 meta : { fixable : "code" } ,
297314 create : context => ( {
298315 Program ( node ) {
@@ -313,7 +330,7 @@ describe("eslint-fuzzer", function () {
313330 }
314331 } ,
315332 } ) ,
316- } ) ;
333+ } ) ) ;
317334
318335 const results = fuzz ( {
319336 count : 1 ,
0 commit comments