Skip to content

Commit

Permalink
🔥 Drop unneeded catch param (#5284)
Browse files Browse the repository at this point in the history
**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?
-->
  • Loading branch information
dubzzz authored Sep 23, 2024
1 parent 2d1c4cd commit a883da5
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function computeCandidateString(
let candidate: string[];
try {
candidate = stringSplitter(dangerous);
} catch (err) {
} catch {
// No split found for `dangerous`, `dangerous` cannot be shrunk by arrays made of `charArbitrary`
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class MapArbitrary<T, U> extends Arbitrary<U> {
try {
const unmapped = this.unmapper(value);
return this.arb.canShrinkWithoutContext(unmapped);
} catch (_err) {
} catch {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/fast-check/src/utils/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function safeExtractApply<T, TArgs extends unknown[], TReturn>(
): ((thisArg: T) => TReturn) | undefined {
try {
return f.apply;
} catch (err) {
} catch {
return undefined;
}
}
Expand Down
48 changes: 24 additions & 24 deletions packages/fast-check/src/utils/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,77 +65,77 @@ const untouchedEvery = Array.prototype.every;
function extractForEach(instance: unknown[]) {
try {
return instance.forEach;
} catch (err) {
} catch {
return undefined;
}
}
function extractIndexOf(instance: readonly unknown[]) {
try {
return instance.indexOf;
} catch (err) {
} catch {
return undefined;
}
}
function extractJoin(instance: unknown[]) {
try {
return instance.join;
} catch (err) {
} catch {
return undefined;
}
}
function extractMap(instance: unknown[]) {
try {
return instance.map;
} catch (err) {
} catch {
return undefined;
}
}
function extractFilter(instance: unknown[]) {
try {
return instance.filter;
} catch (err) {
} catch {
return undefined;
}
}
function extractPush(instance: unknown[]) {
try {
return instance.push;
} catch (err) {
} catch {
return undefined;
}
}
function extractPop(instance: unknown[]) {
try {
return instance.pop;
} catch (err) {
} catch {
return undefined;
}
}
function extractSplice(instance: unknown[]) {
try {
return instance.splice;
} catch (err) {
} catch {
return undefined;
}
}
function extractSlice(instance: unknown[]) {
try {
return instance.slice;
} catch (err) {
} catch {
return undefined;
}
}
function extractSort(instance: unknown[]) {
try {
return instance.sort;
} catch (err) {
} catch {
return undefined;
}
}
function extractEvery(instance: unknown[]) {
try {
return instance.every;
} catch (err) {
} catch {
return undefined;
}
}
Expand Down Expand Up @@ -219,14 +219,14 @@ const untouchedToISOString = Date.prototype.toISOString;
function extractGetTime(instance: Date) {
try {
return instance.getTime;
} catch (err) {
} catch {
return undefined;
}
}
function extractToISOString(instance: Date) {
try {
return instance.toISOString;
} catch (err) {
} catch {
return undefined;
}
}
Expand All @@ -249,7 +249,7 @@ const untouchedAdd = Set.prototype.add;
function extractAdd(instance: Set<unknown>) {
try {
return instance.add;
} catch (err) {
} catch {
return undefined;
}
}
Expand All @@ -274,63 +274,63 @@ const untouchedReplace: (pattern: RegExp | string, replacement: string) => strin
function extractSplit(instance: string) {
try {
return instance.split;
} catch (err) {
} catch {
return undefined;
}
}
function extractStartsWith(instance: string) {
try {
return instance.startsWith;
} catch (err) {
} catch {
return undefined;
}
}
function extractEndsWith(instance: string) {
try {
return instance.endsWith;
} catch (err) {
} catch {
return undefined;
}
}
function extractSubstring(instance: string) {
try {
return instance.substring;
} catch (err) {
} catch {
return undefined;
}
}
function extractToLowerCase(instance: string) {
try {
return instance.toLowerCase;
} catch (err) {
} catch {
return undefined;
}
}
function extractToUpperCase(instance: string) {
try {
return instance.toUpperCase;
} catch (err) {
} catch {
return undefined;
}
}
function extractPadStart(instance: string) {
try {
return instance.padStart;
} catch (err) {
} catch {
return undefined;
}
}
function extractCharCodeAt(instance: string) {
try {
return instance.charCodeAt;
} catch (err) {
} catch {
return undefined;
}
}
function extractReplace(instance: string) {
try {
return instance.replace;
} catch (err) {
} catch {
return undefined;
}
}
Expand Down Expand Up @@ -404,7 +404,7 @@ const untouchedNumberToString = Number.prototype.toString;
function extractNumberToString(instance: number) {
try {
return instance.toString;
} catch (err) {
} catch {
return undefined;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/fast-check/src/utils/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function stringifyInternal<Ts>(
// if user defined custom sync serialization function, we use it before next ones
try {
return value[toStringMethod]();
} catch (err) {
} catch {
// fallback to defaults...
}
}
Expand Down Expand Up @@ -212,7 +212,7 @@ function stringifyInternal<Ts>(
// Instance (or one of its parent prototypes) overrides the default toString of Object
return (value as any).toString(); // <-- Can throw
}
} catch (err) {
} catch {
// Only return what would have been the default toString on Object
return '[object Object]';
}
Expand Down
2 changes: 1 addition & 1 deletion packages/fast-check/test/e2e/NoRegression.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ describe(`NoRegression`, () => {
try {
fc.modelRun(setup, cmds);
return true;
} catch (err) {
} catch {
return false;
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const computeMaximalStackSize = () => {
};
try {
f();
} catch (_err) {
} catch {
// throws 'RangeError: Maximum call stack size exceeded'
}
return depth;
Expand Down
2 changes: 1 addition & 1 deletion packages/fast-check/test/e2e/Poisoning.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function dropAllFromObj(obj: unknown): (() => void)[] {
const descriptor = safeObjectGetOwnPropertyDescriptor(obj, k)!;
delete (obj as any)[k];
restores.push(() => safeObjectDefineProperty(obj, k, descriptor));
} catch (err) {
} catch {
// Object.prototype cannot be deleted, and others might too
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/fast-check/test/e2e/ReplayFailures.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe(`ReplayFailures (seed: ${seed})`, () => {
expect(data).toEqual(out.counterexample![0]);
validCallIndex = numCalls;
++numValidCalls;
} catch (err) {
} catch {
// noop
}
++numCalls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe(`ObjectArbitrary (seed: ${seed})`, () => {
try {
JSON.parse(revJson(json));
return false;
} catch (err) {
} catch {
return true;
}
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export function assertProduceSomeSpecificValues<T, U = never>(
// We default numRuns to 1000, but let user override it whenever needed
assertParameters: { numRuns: 1000, ...options.assertParameters, endOnFailure: true },
});
} catch (err) {
} catch {
// no-op
}
expect(foundOne).toBe(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ function isStringified(v: unknown): boolean {
try {
eval(v);
return true; // the string was correctly parsed
} catch (err) {
} catch {
return false; // not a valid representation
}
}
Expand All @@ -237,7 +237,7 @@ function isStringifiedAsKeys(v: unknown): boolean {
try {
eval(key);
return true; // the string used as key the string representation of a JavaScript instance
} catch (err) {
} catch {
// not a valid representation
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/fast-check/test/unit/arbitrary/commands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('commands (integration)', () => {
if (!c.check(model)) continue;
try {
c.run(model, real);
} catch (err) {
} catch {
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function regexBasedOnChunks(): fc.Arbitrary<Extra> {
try {
new RegExp('.', 'd'); // Not supported in Node 14
return true;
} catch (err) {
} catch {
return false;
}
})();
Expand Down
2 changes: 1 addition & 1 deletion packages/fast-check/test/unit/utils/stringify.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const checkEqual = (a: any, b: any): boolean => {
try {
expect(a).toEqual(b);
return true;
} catch (err) {
} catch {
return false;
}
};
Expand Down
2 changes: 1 addition & 1 deletion packages/poisoning/test/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('assertNoPoisoning', () => {
// @ts-ignore
delete obj[k];
++numDeleted;
} catch (err) {
} catch {
// Object.prototype cannot be deleted, and others might too
}
}
Expand Down

0 comments on commit a883da5

Please sign in to comment.