Skip to content

Commit a883da5

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 2d1c4cd commit a883da5

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
@@ -38,7 +38,7 @@ function computeCandidateString(
3838
let candidate: string[];
3939
try {
4040
candidate = stringSplitter(dangerous);
41-
} catch (err) {
41+
} catch {
4242
// No split found for `dangerous`, `dangerous` cannot be shrunk by arrays made of `charArbitrary`
4343
return undefined;
4444
}

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
}
@@ -249,7 +249,7 @@ const untouchedAdd = Set.prototype.add;
249249
function extractAdd(instance: Set<unknown>) {
250250
try {
251251
return instance.add;
252-
} catch (err) {
252+
} catch {
253253
return undefined;
254254
}
255255
}
@@ -274,63 +274,63 @@ const untouchedReplace: (pattern: RegExp | string, replacement: string) => strin
274274
function extractSplit(instance: string) {
275275
try {
276276
return instance.split;
277-
} catch (err) {
277+
} catch {
278278
return undefined;
279279
}
280280
}
281281
function extractStartsWith(instance: string) {
282282
try {
283283
return instance.startsWith;
284-
} catch (err) {
284+
} catch {
285285
return undefined;
286286
}
287287
}
288288
function extractEndsWith(instance: string) {
289289
try {
290290
return instance.endsWith;
291-
} catch (err) {
291+
} catch {
292292
return undefined;
293293
}
294294
}
295295
function extractSubstring(instance: string) {
296296
try {
297297
return instance.substring;
298-
} catch (err) {
298+
} catch {
299299
return undefined;
300300
}
301301
}
302302
function extractToLowerCase(instance: string) {
303303
try {
304304
return instance.toLowerCase;
305-
} catch (err) {
305+
} catch {
306306
return undefined;
307307
}
308308
}
309309
function extractToUpperCase(instance: string) {
310310
try {
311311
return instance.toUpperCase;
312-
} catch (err) {
312+
} catch {
313313
return undefined;
314314
}
315315
}
316316
function extractPadStart(instance: string) {
317317
try {
318318
return instance.padStart;
319-
} catch (err) {
319+
} catch {
320320
return undefined;
321321
}
322322
}
323323
function extractCharCodeAt(instance: string) {
324324
try {
325325
return instance.charCodeAt;
326-
} catch (err) {
326+
} catch {
327327
return undefined;
328328
}
329329
}
330330
function extractReplace(instance: string) {
331331
try {
332332
return instance.replace;
333-
} catch (err) {
333+
} catch {
334334
return undefined;
335335
}
336336
}
@@ -404,7 +404,7 @@ const untouchedNumberToString = Number.prototype.toString;
404404
function extractNumberToString(instance: number) {
405405
try {
406406
return instance.toString;
407-
} catch (err) {
407+
} catch {
408408
return undefined;
409409
}
410410
}

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
@@ -224,7 +224,7 @@ function isStringified(v: unknown): boolean {
224224
try {
225225
eval(v);
226226
return true; // the string was correctly parsed
227-
} catch (err) {
227+
} catch {
228228
return false; // not a valid representation
229229
}
230230
}
@@ -237,7 +237,7 @@ function isStringifiedAsKeys(v: unknown): boolean {
237237
try {
238238
eval(key);
239239
return true; // the string used as key the string representation of a JavaScript instance
240-
} catch (err) {
240+
} catch {
241241
// not a valid representation
242242
}
243243
}

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
@@ -119,7 +119,7 @@ describe('assertNoPoisoning', () => {
119119
// @ts-ignore
120120
delete obj[k];
121121
++numDeleted;
122-
} catch (err) {
122+
} catch {
123123
// Object.prototype cannot be deleted, and others might too
124124
}
125125
}

0 commit comments

Comments
 (0)