Skip to content

Commit f5658a7

Browse files
authored
🔥 Drop unneeded catch param (#5284)
**Description** <!-- Please provide a short description and potentially linked issues justifying the need for this PR --> There is no more need to specify anything when catching an error without treating it. Let's adopt "Optional catch binding" in our codebase! Available since Node 10. Related to #5282 **Important** - Once reaching next-3.23.0, we should add back the eslint configuration: `'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', caughtErrors: 'none' }],`. <!-- * Your PR is fixing a bug or regression? Check for existing issues related to this bug and link them --> <!-- * Your PR is adding a new feature? Make sure there is a related issue or discussion attached to it --> <!-- You can provide any additional context to help into understanding what's this PR is attempting to solve: reproduction of a bug, code snippets... --> **Checklist** — _Don't delete this checklist and make sure you do the following before opening the PR_ - [x] The name of my PR follows [gitmoji](https://gitmoji.dev/) specification - [x] My PR references one of several related issues (if any) - [x] New features or breaking changes must come with an associated Issue or Discussion - [x] My PR does not add any new dependency without an associated Issue or Discussion - [x] My PR includes bumps details, please run `yarn bump` and flag the impacts properly - [x] My PR adds relevant tests and they would have failed without my PR (when applicable) <!-- More about contributing at https://github.com/dubzzz/fast-check/blob/main/CONTRIBUTING.md --> **Advanced** <!-- How to fill the advanced section is detailed below! --> - [x] Category: Shorter code/readability - [x] Impacts: Require node >=10 <!-- [Category] Please use one of the categories below, it will help us into better understanding the urgency of the PR --> <!-- * ✨ Introduce new features --> <!-- * 📝 Add or update documentation --> <!-- * ✅ Add or update tests --> <!-- * 🐛 Fix a bug --> <!-- * 🏷️ Add or update types --> <!-- * ⚡️ Improve performance --> <!-- * _Other(s):_ ... --> <!-- [Impacts] Please provide a comma separated list of the potential impacts that might be introduced by this change --> <!-- * Generated values: Can your change impact any of the existing generators in terms of generated values, if so which ones? when? --> <!-- * Shrink values: Can your change impact any of the existing generators in terms of shrink values, if so which ones? when? --> <!-- * Performance: Can it require some typings changes on user side? Please give more details --> <!-- * Typings: Is there a potential performance impact? In which cases? -->
1 parent e2b7e77 commit f5658a7

File tree

16 files changed

+41
-41
lines changed

16 files changed

+41
-41
lines changed

packages/fast-check/src/arbitrary/_internals/helpers/SlicesForStringBuilder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function computeCandidateStringLegacy(
4242
let candidate: string[];
4343
try {
4444
candidate = stringSplitter(dangerous);
45-
} catch (err) {
45+
} catch {
4646
// No split found for `dangerous`, `dangerous` cannot be shrunk by arrays made of `charArbitrary`
4747
return undefined;
4848
}

packages/fast-check/src/check/arbitrary/definition/Arbitrary.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ class MapArbitrary<T, U> extends Arbitrary<U> {
273273
try {
274274
const unmapped = this.unmapper(value);
275275
return this.arb.canShrinkWithoutContext(unmapped);
276-
} catch (_err) {
276+
} catch {
277277
return false;
278278
}
279279
}

packages/fast-check/src/utils/apply.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function safeExtractApply<T, TArgs extends unknown[], TReturn>(
1111
): ((thisArg: T) => TReturn) | undefined {
1212
try {
1313
return f.apply;
14-
} catch (err) {
14+
} catch {
1515
return undefined;
1616
}
1717
}

packages/fast-check/src/utils/globals.ts

+24-24
Original file line numberDiff line numberDiff line change
@@ -65,77 +65,77 @@ const untouchedEvery = Array.prototype.every;
6565
function extractForEach(instance: unknown[]) {
6666
try {
6767
return instance.forEach;
68-
} catch (err) {
68+
} catch {
6969
return undefined;
7070
}
7171
}
7272
function extractIndexOf(instance: readonly unknown[]) {
7373
try {
7474
return instance.indexOf;
75-
} catch (err) {
75+
} catch {
7676
return undefined;
7777
}
7878
}
7979
function extractJoin(instance: unknown[]) {
8080
try {
8181
return instance.join;
82-
} catch (err) {
82+
} catch {
8383
return undefined;
8484
}
8585
}
8686
function extractMap(instance: unknown[]) {
8787
try {
8888
return instance.map;
89-
} catch (err) {
89+
} catch {
9090
return undefined;
9191
}
9292
}
9393
function extractFilter(instance: unknown[]) {
9494
try {
9595
return instance.filter;
96-
} catch (err) {
96+
} catch {
9797
return undefined;
9898
}
9999
}
100100
function extractPush(instance: unknown[]) {
101101
try {
102102
return instance.push;
103-
} catch (err) {
103+
} catch {
104104
return undefined;
105105
}
106106
}
107107
function extractPop(instance: unknown[]) {
108108
try {
109109
return instance.pop;
110-
} catch (err) {
110+
} catch {
111111
return undefined;
112112
}
113113
}
114114
function extractSplice(instance: unknown[]) {
115115
try {
116116
return instance.splice;
117-
} catch (err) {
117+
} catch {
118118
return undefined;
119119
}
120120
}
121121
function extractSlice(instance: unknown[]) {
122122
try {
123123
return instance.slice;
124-
} catch (err) {
124+
} catch {
125125
return undefined;
126126
}
127127
}
128128
function extractSort(instance: unknown[]) {
129129
try {
130130
return instance.sort;
131-
} catch (err) {
131+
} catch {
132132
return undefined;
133133
}
134134
}
135135
function extractEvery(instance: unknown[]) {
136136
try {
137137
return instance.every;
138-
} catch (err) {
138+
} catch {
139139
return undefined;
140140
}
141141
}
@@ -219,14 +219,14 @@ const untouchedToISOString = Date.prototype.toISOString;
219219
function extractGetTime(instance: Date) {
220220
try {
221221
return instance.getTime;
222-
} catch (err) {
222+
} catch {
223223
return undefined;
224224
}
225225
}
226226
function extractToISOString(instance: Date) {
227227
try {
228228
return instance.toISOString;
229-
} catch (err) {
229+
} catch {
230230
return undefined;
231231
}
232232
}
@@ -250,7 +250,7 @@ const untouchedHas = Set.prototype.has;
250250
function extractAdd(instance: Set<unknown>) {
251251
try {
252252
return instance.add;
253-
} catch (err) {
253+
} catch {
254254
return undefined;
255255
}
256256
}
@@ -351,56 +351,56 @@ const untouchedReplace: (pattern: RegExp | string, replacement: string) => strin
351351
function extractSplit(instance: string) {
352352
try {
353353
return instance.split;
354-
} catch (err) {
354+
} catch {
355355
return undefined;
356356
}
357357
}
358358
function extractStartsWith(instance: string) {
359359
try {
360360
return instance.startsWith;
361-
} catch (err) {
361+
} catch {
362362
return undefined;
363363
}
364364
}
365365
function extractEndsWith(instance: string) {
366366
try {
367367
return instance.endsWith;
368-
} catch (err) {
368+
} catch {
369369
return undefined;
370370
}
371371
}
372372
function extractSubstring(instance: string) {
373373
try {
374374
return instance.substring;
375-
} catch (err) {
375+
} catch {
376376
return undefined;
377377
}
378378
}
379379
function extractToLowerCase(instance: string) {
380380
try {
381381
return instance.toLowerCase;
382-
} catch (err) {
382+
} catch {
383383
return undefined;
384384
}
385385
}
386386
function extractToUpperCase(instance: string) {
387387
try {
388388
return instance.toUpperCase;
389-
} catch (err) {
389+
} catch {
390390
return undefined;
391391
}
392392
}
393393
function extractPadStart(instance: string) {
394394
try {
395395
return instance.padStart;
396-
} catch (err) {
396+
} catch {
397397
return undefined;
398398
}
399399
}
400400
function extractCharCodeAt(instance: string) {
401401
try {
402402
return instance.charCodeAt;
403-
} catch (err) {
403+
} catch {
404404
return undefined;
405405
}
406406
}
@@ -414,7 +414,7 @@ function extractNormalize(instance: string) {
414414
function extractReplace(instance: string) {
415415
try {
416416
return instance.replace;
417-
} catch (err) {
417+
} catch {
418418
return undefined;
419419
}
420420
}
@@ -494,7 +494,7 @@ const untouchedNumberToString = Number.prototype.toString;
494494
function extractNumberToString(instance: number) {
495495
try {
496496
return instance.toString;
497-
} catch (err) {
497+
} catch {
498498
return undefined;
499499
}
500500
}

packages/fast-check/src/utils/stringify.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ function stringifyInternal<Ts>(
157157
// if user defined custom sync serialization function, we use it before next ones
158158
try {
159159
return value[toStringMethod]();
160-
} catch (err) {
160+
} catch {
161161
// fallback to defaults...
162162
}
163163
}
@@ -212,7 +212,7 @@ function stringifyInternal<Ts>(
212212
// Instance (or one of its parent prototypes) overrides the default toString of Object
213213
return (value as any).toString(); // <-- Can throw
214214
}
215-
} catch (err) {
215+
} catch {
216216
// Only return what would have been the default toString on Object
217217
return '[object Object]';
218218
}

packages/fast-check/test/e2e/NoRegression.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ describe(`NoRegression`, () => {
778778
try {
779779
fc.modelRun(setup, cmds);
780780
return true;
781-
} catch (err) {
781+
} catch {
782782
return false;
783783
}
784784
},

packages/fast-check/test/e2e/NoStackOverflowOnShrink.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const computeMaximalStackSize = () => {
1212
};
1313
try {
1414
f();
15-
} catch (_err) {
15+
} catch {
1616
// throws 'RangeError: Maximum call stack size exceeded'
1717
}
1818
return depth;

packages/fast-check/test/e2e/Poisoning.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ function dropAllFromObj(obj: unknown): (() => void)[] {
173173
const descriptor = safeObjectGetOwnPropertyDescriptor(obj, k)!;
174174
delete (obj as any)[k];
175175
restores.push(() => safeObjectDefineProperty(obj, k, descriptor));
176-
} catch (err) {
176+
} catch {
177177
// Object.prototype cannot be deleted, and others might too
178178
}
179179
}

packages/fast-check/test/e2e/ReplayFailures.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe(`ReplayFailures (seed: ${seed})`, () => {
6060
expect(data).toEqual(out.counterexample![0]);
6161
validCallIndex = numCalls;
6262
++numValidCalls;
63-
} catch (err) {
63+
} catch {
6464
// noop
6565
}
6666
++numCalls;

packages/fast-check/test/e2e/arbitraries/ObjectArbitrary.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe(`ObjectArbitrary (seed: ${seed})`, () => {
3030
try {
3131
JSON.parse(revJson(json));
3232
return false;
33-
} catch (err) {
33+
} catch {
3434
return true;
3535
}
3636
}),

packages/fast-check/test/unit/arbitrary/__test-helpers__/ArbitraryAssertions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export function assertProduceSomeSpecificValues<T, U = never>(
234234
// We default numRuns to 1000, but let user override it whenever needed
235235
assertParameters: { numRuns: 1000, ...options.assertParameters, endOnFailure: true },
236236
});
237-
} catch (err) {
237+
} catch {
238238
// no-op
239239
}
240240
expect(foundOne).toBe(true);

packages/fast-check/test/unit/arbitrary/_internals/builders/AnyArbitraryBuilder.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ function isStringified(v: unknown): boolean {
231231
try {
232232
eval(v);
233233
return true; // the string was correctly parsed
234-
} catch (err) {
234+
} catch {
235235
return false; // not a valid representation
236236
}
237237
}
@@ -244,7 +244,7 @@ function isStringifiedAsKeys(v: unknown): boolean {
244244
try {
245245
eval(key);
246246
return true; // the string used as key the string representation of a JavaScript instance
247-
} catch (err) {
247+
} catch {
248248
// not a valid representation
249249
}
250250
}

packages/fast-check/test/unit/arbitrary/commands.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('commands (integration)', () => {
2525
if (!c.check(model)) continue;
2626
try {
2727
c.run(model, real);
28-
} catch (err) {
28+
} catch {
2929
return;
3030
}
3131
}

packages/fast-check/test/unit/arbitrary/stringMatching.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function regexBasedOnChunks(): fc.Arbitrary<Extra> {
7777
try {
7878
new RegExp('.', 'd'); // Not supported in Node 14
7979
return true;
80-
} catch (err) {
80+
} catch {
8181
return false;
8282
}
8383
})();

packages/fast-check/test/unit/utils/stringify.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const checkEqual = (a: any, b: any): boolean => {
1919
try {
2020
expect(a).toEqual(b);
2121
return true;
22-
} catch (err) {
22+
} catch {
2323
return false;
2424
}
2525
};

packages/poisoning/test/main.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ describe('assertNoPoisoning', () => {
121121
// @ts-ignore
122122
delete obj[k];
123123
++numDeleted;
124-
} catch (err) {
124+
} catch {
125125
// Object.prototype cannot be deleted, and others might too
126126
}
127127
}

0 commit comments

Comments
 (0)