From 0bbef2c7fbd03c6d9b41f93e859b23529210cf22 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Fri, 26 Apr 2024 09:15:42 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Switch=20on=20more=20eslint=20ru?= =?UTF-8?q?les=20(#4933)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **_Category:_** - [ ] ✨ Introduce new features - [ ] 📝 Add or update documentation - [ ] ✅ Add or update tests - [ ] 🐛 Fix a bug - [ ] 🏷️ Add or update types - [ ] ⚡️ Improve performance - [ ] _Other(s):_ ... **_Potential impacts:_** - [ ] Generated values - [ ] Shrink values - [ ] Performance - [ ] Typings - [ ] _Other(s):_ ... --- .yarn/versions/36811c13.yml | 8 ++++++ eslint.config.mjs | 25 +++++++++++++++++-- .../check/model/commands/ScheduledCommand.ts | 1 + .../fast-check/src/check/runner/Runner.ts | 8 +++--- packages/fast-check/src/utils/stringify.ts | 2 ++ packages/fast-check/test-types/main.ts | 1 - packages/vitest/src/internals/TestBuilder.ts | 3 +++ .../internals/TestWithPropRunnerBuilder.ts | 1 + .../src/internals/worker-pool/GlobalPool.ts | 1 + 9 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 .yarn/versions/36811c13.yml diff --git a/.yarn/versions/36811c13.yml b/.yarn/versions/36811c13.yml new file mode 100644 index 00000000000..ffa688c0846 --- /dev/null +++ b/.yarn/versions/36811c13.yml @@ -0,0 +1,8 @@ +releases: + "@fast-check/vitest": patch + "@fast-check/worker": patch + fast-check: patch + +declined: + - "@fast-check/ava" + - "@fast-check/jest" diff --git a/eslint.config.mjs b/eslint.config.mjs index ad8a5a560f2..b189835c086 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -7,7 +7,7 @@ import globals from 'globals'; /** @type {import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigFile} */ export default [ js.configs.recommended, - ...tseslint.configs.recommended, + ...tseslint.configs.recommendedTypeChecked, eslintConfigPrettier, { languageOptions: { @@ -34,6 +34,16 @@ export default [ '@typescript-eslint/no-non-null-assertion': 'error', '@typescript-eslint/ban-types': 'error', 'require-atomic-updates': 'error', + '@typescript-eslint/no-redundant-type-constituents': 'off', + '@typescript-eslint/no-unnecessary-type-assertion': 'off', + '@typescript-eslint/no-unsafe-argument': 'off', + '@typescript-eslint/no-unsafe-assignment': 'off', + '@typescript-eslint/no-unsafe-call': 'off', + '@typescript-eslint/no-unsafe-member-access': 'off', + '@typescript-eslint/no-unsafe-return': 'off', + '@typescript-eslint/restrict-plus-operands': 'off', + '@typescript-eslint/restrict-template-expressions': 'off', + '@typescript-eslint/unbound-method': 'off', }, }, { @@ -46,6 +56,7 @@ export default [ }, rules: { '@typescript-eslint/no-var-requires': 'off', + ...tseslint.configs.disableTypeChecked.rules, }, }, { @@ -55,13 +66,23 @@ export default [ ...globals.node, }, }, + rules: { + ...tseslint.configs.disableTypeChecked.rules, + }, }, { - files: ['**/*.spec.ts', '**/test/unit/**/*.ts', '**/test/e2e/**/*.ts'], + files: [ + '**/*.spec.ts', + '**/test/unit/**/*.ts', + '**/test/e2e/**/*.ts', + '**/test-types/**/*.ts', + '**/test-types/**/*.mts', + ], rules: { '@typescript-eslint/no-empty-function': 'off', '@typescript-eslint/no-use-before-define': 'off', '@typescript-eslint/no-non-null-assertion': 'off', + ...tseslint.configs.disableTypeChecked.rules, }, }, { diff --git a/packages/fast-check/src/check/model/commands/ScheduledCommand.ts b/packages/fast-check/src/check/model/commands/ScheduledCommand.ts index b9edffaa93e..bab77fcce24 100644 --- a/packages/fast-check/src/check/model/commands/ScheduledCommand.ts +++ b/packages/fast-check/src/check/model/commands/ScheduledCommand.ts @@ -41,6 +41,7 @@ export class ScheduledCommand { try { + // eslint-disable-next-line @typescript-eslint/await-thenable await this.cmd.run(m, r); } catch (err) { error = err; diff --git a/packages/fast-check/src/check/runner/Runner.ts b/packages/fast-check/src/check/runner/Runner.ts index 97f87884870..f487d46c1c7 100644 --- a/packages/fast-check/src/check/runner/Runner.ts +++ b/packages/fast-check/src/check/runner/Runner.ts @@ -31,13 +31,11 @@ function runIt( const runner = new RunnerIterator(sourceValues, shrink, verbose, interruptedAsFailure); for (const v of runner) { if (isModernProperty) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - property.runBeforeEach!(); + (property.runBeforeEach as () => void)(); } const out = property.run(v, isModernProperty) as PreconditionFailure | PropertyFailure | null; if (isModernProperty) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - property.runAfterEach!(); + (property.runAfterEach as () => void)(); } runner.handleResult(out); } @@ -191,7 +189,7 @@ function assert(property: IRawProperty, params?: Parameters): Promis function assert(property: IRawProperty, params?: Parameters): unknown { const out = check(property, params); if (property.isAsync()) return (out as Promise>).then(asyncReportRunDetails); - else reportRunDetails(out as RunDetails); + else reportRunDetails(out as RunDetails) as void; } export { check, assert }; diff --git a/packages/fast-check/src/utils/stringify.ts b/packages/fast-check/src/utils/stringify.ts index 57b688e6869..677330ac8c6 100644 --- a/packages/fast-check/src/utils/stringify.ts +++ b/packages/fast-check/src/utils/stringify.ts @@ -123,6 +123,7 @@ function stringifyNumber(numValue: number) { /** @internal */ function isSparseArray(arr: unknown[]): boolean { let previousNumberedIndex = -1; + // eslint-disable-next-line @typescript-eslint/no-for-in-array for (const index in arr) { const numberedIndex = Number(index); if (numberedIndex !== previousNumberedIndex + 1) return true; // we've got a hole @@ -168,6 +169,7 @@ export function stringifyInternal( const assignments: string[] = []; // Discarded: map then join will still show holes // Discarded: forEach is very long on large sparse arrays, but only iterates on non-holes integer keys + // eslint-disable-next-line @typescript-eslint/no-for-in-array for (const index in arr) { if (!safeNumberIsNaN(Number(index))) safePush(assignments, `${index}:${stringifyInternal(arr[index], currentValues, getAsyncContent)}`); diff --git a/packages/fast-check/test-types/main.ts b/packages/fast-check/test-types/main.ts index ed24ccf14f6..b852c5ed69e 100644 --- a/packages/fast-check/test-types/main.ts +++ b/packages/fast-check/test-types/main.ts @@ -1,5 +1,4 @@ /* eslint-disable @typescript-eslint/ban-types */ -/* eslint-disable @typescript-eslint/no-empty-function */ // Just a simple property, compiling a snippet importing fast-check // should be enough to ensure that typings will not raise errors regarding incompatible // and unknown syntaxes at build time diff --git a/packages/vitest/src/internals/TestBuilder.ts b/packages/vitest/src/internals/TestBuilder.ts index a939942939f..0e5789a1f07 100644 --- a/packages/vitest/src/internals/TestBuilder.ts +++ b/packages/vitest/src/internals/TestBuilder.ts @@ -72,14 +72,17 @@ function adaptRunDetailsForRecord( * @param testFn - The source `{it,test}.*` */ function buildTestProp( + // eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents testFn: It | It['only' | 'skip' | 'concurrent'] | It['concurrent']['only' | 'skip'], fc: FcExtra, ): TestPropTuple; function buildTestProp( + // eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents testFn: It | It['only' | 'skip' | 'concurrent'] | It['concurrent']['only' | 'skip'], fc: FcExtra, ): TestPropRecord; function buildTestProp( + // eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents testFn: It | It['only' | 'skip' | 'concurrent'] | It['concurrent']['only' | 'skip'], fc: FcExtra, ): TestPropTuple | TestPropRecord { diff --git a/packages/vitest/src/internals/TestWithPropRunnerBuilder.ts b/packages/vitest/src/internals/TestWithPropRunnerBuilder.ts index d8bc9909dd0..6d7dba9d518 100644 --- a/packages/vitest/src/internals/TestWithPropRunnerBuilder.ts +++ b/packages/vitest/src/internals/TestWithPropRunnerBuilder.ts @@ -8,6 +8,7 @@ function wrapProp(prop: Prop): PromiseProp { } export function buildTestWithPropRunner( + // eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents testFn: It | It['only' | 'skip' | 'concurrent'] | It['concurrent']['only' | 'skip'], label: string, arbitraries: ArbitraryTuple, diff --git a/packages/worker/src/internals/worker-pool/GlobalPool.ts b/packages/worker/src/internals/worker-pool/GlobalPool.ts index 31467e3af26..ff35ae7d10c 100644 --- a/packages/worker/src/internals/worker-pool/GlobalPool.ts +++ b/packages/worker/src/internals/worker-pool/GlobalPool.ts @@ -51,6 +51,7 @@ export class GlobalPool implements IWorkerPool { + // eslint-disable-next-line @typescript-eslint/no-floating-promises this.internalPool.terminateAllWorkers(); }, 0), );