Skip to content

Commit 27549bc

Browse files
authored
chore: update fuzz testing to not error if code sample minimizer fails (#20252)
1 parent 10b995c commit 27549bc

File tree

1 file changed

+47
-32
lines changed

1 file changed

+47
-32
lines changed

tools/eslint-fuzzer.js

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -203,24 +203,32 @@ function fuzz(options) {
203203
? isolateBadAutofixPass(text, config)
204204
: text;
205205
const smallConfig = isolateBadConfig(lastGoodText, config, "crash");
206-
const smallText = sampleMinimizer({
207-
sourceText: lastGoodText,
208-
parser: { parse: getParser(smallConfig) },
209-
predicate(reducedText) {
210-
try {
211-
linter.verify(reducedText, smallConfig);
212-
return false;
213-
} catch {
214-
return true;
215-
}
216-
},
217-
});
206+
let smallText = lastGoodText;
207+
let sampleMinimizerError = null;
208+
209+
try {
210+
smallText = sampleMinimizer({
211+
sourceText: lastGoodText,
212+
parser: { parse: getParser(smallConfig) },
213+
predicate(reducedText) {
214+
try {
215+
linter.verify(reducedText, smallConfig);
216+
return false;
217+
} catch {
218+
return true;
219+
}
220+
},
221+
});
222+
} catch (e) {
223+
sampleMinimizerError = e.stack;
224+
}
218225

219226
problems.push({
220227
type: "crash",
221228
text: smallText,
222229
config: smallConfig,
223230
error: err.stack,
231+
sampleMinimizerError,
224232
});
225233

226234
continue;
@@ -238,32 +246,39 @@ function fuzz(options) {
238246
config,
239247
"autofix",
240248
);
241-
const smallText = sampleMinimizer({
242-
sourceText: lastGoodText,
243-
parser: { parse: getParser(smallConfig) },
244-
predicate(reducedText) {
245-
try {
246-
const smallFixResult = linter.verifyAndFix(
247-
reducedText,
248-
smallConfig,
249-
);
250-
251-
return (
252-
smallFixResult.fixed &&
253-
smallFixResult.messages.length === 1 &&
254-
smallFixResult.messages[0].fatal
255-
);
256-
} catch {
257-
return false;
258-
}
259-
},
260-
});
249+
let smallText = lastGoodText;
250+
let sampleMinimizerError = null;
251+
try {
252+
smallText = sampleMinimizer({
253+
sourceText: lastGoodText,
254+
parser: { parse: getParser(smallConfig) },
255+
predicate(reducedText) {
256+
try {
257+
const smallFixResult = linter.verifyAndFix(
258+
reducedText,
259+
smallConfig,
260+
);
261+
262+
return (
263+
smallFixResult.fixed &&
264+
smallFixResult.messages.length === 1 &&
265+
smallFixResult.messages[0].fatal
266+
);
267+
} catch {
268+
return false;
269+
}
270+
},
271+
});
272+
} catch (e) {
273+
sampleMinimizerError = e.stack;
274+
}
261275

262276
problems.push({
263277
type: "autofix",
264278
text: smallText,
265279
config: smallConfig,
266280
error: autofixResult.messages[0],
281+
sampleMinimizerError,
267282
});
268283
}
269284
}

0 commit comments

Comments
 (0)