Skip to content

Commit d2090e6

Browse files
authored
🔥 Drop unneeded catch param (#5634)
**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 and ES2019. 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
1 parent ae44641 commit d2090e6

File tree

18 files changed

+47
-42
lines changed

18 files changed

+47
-42
lines changed

.changeset/lazy-sloths-turn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"fast-check": major
3+
---
4+
5+
🔥 Drop unneeded catch param

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,77 +69,77 @@ const untouchedEvery = Array.prototype.every;
6969
function extractForEach(instance: unknown[]) {
7070
try {
7171
return instance.forEach;
72-
} catch (err) {
72+
} catch {
7373
return undefined;
7474
}
7575
}
7676
function extractIndexOf(instance: readonly unknown[]) {
7777
try {
7878
return instance.indexOf;
79-
} catch (err) {
79+
} catch {
8080
return undefined;
8181
}
8282
}
8383
function extractJoin(instance: unknown[]) {
8484
try {
8585
return instance.join;
86-
} catch (err) {
86+
} catch {
8787
return undefined;
8888
}
8989
}
9090
function extractMap(instance: unknown[]) {
9191
try {
9292
return instance.map;
93-
} catch (err) {
93+
} catch {
9494
return undefined;
9595
}
9696
}
9797
function extractFilter(instance: unknown[]) {
9898
try {
9999
return instance.filter;
100-
} catch (err) {
100+
} catch {
101101
return undefined;
102102
}
103103
}
104104
function extractPush(instance: unknown[]) {
105105
try {
106106
return instance.push;
107-
} catch (err) {
107+
} catch {
108108
return undefined;
109109
}
110110
}
111111
function extractPop(instance: unknown[]) {
112112
try {
113113
return instance.pop;
114-
} catch (err) {
114+
} catch {
115115
return undefined;
116116
}
117117
}
118118
function extractSplice(instance: unknown[]) {
119119
try {
120120
return instance.splice;
121-
} catch (err) {
121+
} catch {
122122
return undefined;
123123
}
124124
}
125125
function extractSlice(instance: unknown[]) {
126126
try {
127127
return instance.slice;
128-
} catch (err) {
128+
} catch {
129129
return undefined;
130130
}
131131
}
132132
function extractSort(instance: unknown[]) {
133133
try {
134134
return instance.sort;
135-
} catch (err) {
135+
} catch {
136136
return undefined;
137137
}
138138
}
139139
function extractEvery(instance: unknown[]) {
140140
try {
141141
return instance.every;
142-
} catch (err) {
142+
} catch {
143143
return undefined;
144144
}
145145
}
@@ -223,14 +223,14 @@ const untouchedToISOString = Date.prototype.toISOString;
223223
function extractGetTime(instance: Date) {
224224
try {
225225
return instance.getTime;
226-
} catch (err) {
226+
} catch {
227227
return undefined;
228228
}
229229
}
230230
function extractToISOString(instance: Date) {
231231
try {
232232
return instance.toISOString;
233-
} catch (err) {
233+
} catch {
234234
return undefined;
235235
}
236236
}
@@ -254,7 +254,7 @@ const untouchedHas = Set.prototype.has;
254254
function extractAdd(instance: Set<unknown>) {
255255
try {
256256
return instance.add;
257-
} catch (err) {
257+
} catch {
258258
return undefined;
259259
}
260260
}
@@ -355,56 +355,56 @@ const untouchedReplace: (pattern: RegExp | string, replacement: string) => strin
355355
function extractSplit(instance: string) {
356356
try {
357357
return instance.split;
358-
} catch (err) {
358+
} catch {
359359
return undefined;
360360
}
361361
}
362362
function extractStartsWith(instance: string) {
363363
try {
364364
return instance.startsWith;
365-
} catch (err) {
365+
} catch {
366366
return undefined;
367367
}
368368
}
369369
function extractEndsWith(instance: string) {
370370
try {
371371
return instance.endsWith;
372-
} catch (err) {
372+
} catch {
373373
return undefined;
374374
}
375375
}
376376
function extractSubstring(instance: string) {
377377
try {
378378
return instance.substring;
379-
} catch (err) {
379+
} catch {
380380
return undefined;
381381
}
382382
}
383383
function extractToLowerCase(instance: string) {
384384
try {
385385
return instance.toLowerCase;
386-
} catch (err) {
386+
} catch {
387387
return undefined;
388388
}
389389
}
390390
function extractToUpperCase(instance: string) {
391391
try {
392392
return instance.toUpperCase;
393-
} catch (err) {
393+
} catch {
394394
return undefined;
395395
}
396396
}
397397
function extractPadStart(instance: string) {
398398
try {
399399
return instance.padStart;
400-
} catch (err) {
400+
} catch {
401401
return undefined;
402402
}
403403
}
404404
function extractCharCodeAt(instance: string) {
405405
try {
406406
return instance.charCodeAt;
407-
} catch (err) {
407+
} catch {
408408
return undefined;
409409
}
410410
}
@@ -418,7 +418,7 @@ function extractNormalize(instance: string) {
418418
function extractReplace(instance: string) {
419419
try {
420420
return instance.replace;
421-
} catch (err) {
421+
} catch {
422422
return undefined;
423423
}
424424
}
@@ -498,7 +498,7 @@ const untouchedNumberToString = Number.prototype.toString;
498498
function extractNumberToString(instance: number) {
499499
try {
500500
return instance.toString;
501-
} catch (err) {
501+
} catch {
502502
return undefined;
503503
}
504504
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export function stringifyInternal<Ts>(
159159
// if user defined custom sync serialization function, we use it before next ones
160160
try {
161161
return value[toStringMethod]();
162-
} catch (err) {
162+
} catch {
163163
// fallback to defaults...
164164
}
165165
}
@@ -214,7 +214,7 @@ export function stringifyInternal<Ts>(
214214
// Instance (or one of its parent prototypes) overrides the default toString of Object
215215
return (value as any).toString(); // <-- Can throw
216216
}
217-
} catch (err) {
217+
} catch {
218218
// Only return what would have been the default toString on Object
219219
return '[object Object]';
220220
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ describe(`NoRegression`, () => {
798798
try {
799799
fc.modelRun(setup, cmds);
800800
return true;
801-
} catch (err) {
801+
} catch {
802802
return false;
803803
}
804804
},

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function dropAllFromObj(obj: unknown): (() => void)[] {
178178
const descriptor = safeObjectGetOwnPropertyDescriptor(obj, k)!;
179179
delete (obj as any)[k];
180180
restores.push(() => safeObjectDefineProperty(obj, k, descriptor));
181-
} catch (err) {
181+
} catch {
182182
// Object.prototype cannot be deleted, and others might too
183183
}
184184
}

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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
}

website/docs/migration/from-3.x-to-4.x.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Simple migration guide to fast-check v4 starting from fast-check v3
1515
| ECMAScript specification | ES2020 | ES2017 |
1616
| TypeScript _(optional)_ | ≥5.0 | ≥4.1 |
1717

18-
Related pull requests: [#5577](https://github.com/dubzzz/fast-check/pull/5577), [#5605](https://github.com/dubzzz/fast-check/pull/5605), [#5617](https://github.com/dubzzz/fast-check/pull/5617)
18+
Related pull requests: [#5577](https://github.com/dubzzz/fast-check/pull/5577), [#5605](https://github.com/dubzzz/fast-check/pull/5605), [#5617](https://github.com/dubzzz/fast-check/pull/5617), [#5634](https://github.com/dubzzz/fast-check/pull/5634)
1919

2020
## Update to latest v3.x
2121

0 commit comments

Comments
 (0)