Skip to content

Commit

Permalink
🔨 Switch on more eslint rules (#4933)
Browse files Browse the repository at this point in the history
<!-- Context of the PR: short description and potentially linked issues
-->

<!-- ...a few words to describe the content of this PR... -->
<!-- ... -->

<!-- Type of PR: [ ] unchecked / [ ] checked -->

**_Category:_**

- [ ] ✨ Introduce new features
- [ ] 📝 Add or update documentation
- [ ] ✅ Add or update tests
- [ ] 🐛 Fix a bug
- [ ] 🏷️ Add or update types
- [ ] ⚡️ Improve performance
- [ ] _Other(s):_ ...
  <!-- Don't forget to add the gitmoji icon in the name of the PR -->
  <!-- See: https://gitmoji.dev/                                  -->

<!-- Fixing bugs, adding features... may impact existing ones -->
<!-- in order to track potential issues that could be related to your PR
-->
<!-- please check the impacts and describe more precisely what to expect
-->

**_Potential impacts:_**

<!-- 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?
-->

- [ ] Generated values
- [ ] Shrink values
- [ ] Performance
- [ ] Typings
- [ ] _Other(s):_ ...
  • Loading branch information
dubzzz authored Apr 26, 2024
1 parent cdcc5fd commit 0bbef2c
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 8 deletions.
8 changes: 8 additions & 0 deletions .yarn/versions/36811c13.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
releases:
"@fast-check/vitest": patch
"@fast-check/worker": patch
fast-check: patch

declined:
- "@fast-check/ava"
- "@fast-check/jest"
25 changes: 23 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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',
},
},
{
Expand All @@ -46,6 +56,7 @@ export default [
},
rules: {
'@typescript-eslint/no-var-requires': 'off',
...tseslint.configs.disableTypeChecked.rules,
},
},
{
Expand All @@ -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,
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class ScheduledCommand<Model extends object, Real, RunResult, CheckAsync
label: `run@${this.cmd.toString()}`,
builder: async () => {
try {
// eslint-disable-next-line @typescript-eslint/await-thenable
await this.cmd.run(m, r);
} catch (err) {
error = err;
Expand Down
8 changes: 3 additions & 5 deletions packages/fast-check/src/check/runner/Runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ function runIt<Ts>(
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);
}
Expand Down Expand Up @@ -191,7 +189,7 @@ function assert<Ts>(property: IRawProperty<Ts>, params?: Parameters<Ts>): Promis
function assert<Ts>(property: IRawProperty<Ts>, params?: Parameters<Ts>): unknown {
const out = check(property, params);
if (property.isAsync()) return (out as Promise<RunDetails<Ts>>).then(asyncReportRunDetails);
else reportRunDetails(out as RunDetails<Ts>);
else reportRunDetails(out as RunDetails<Ts>) as void;
}

export { check, assert };
2 changes: 2 additions & 0 deletions packages/fast-check/src/utils/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -168,6 +169,7 @@ export function stringifyInternal<Ts>(
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)}`);
Expand Down
1 change: 0 additions & 1 deletion packages/fast-check/test-types/main.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions packages/vitest/src/internals/TestBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,17 @@ function adaptRunDetailsForRecord<Ts>(
* @param testFn - The source `{it,test}.*`
*/
function buildTestProp<Ts extends [any] | any[], TsParameters extends Ts = Ts>(
// eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents
testFn: It | It['only' | 'skip' | 'concurrent'] | It['concurrent']['only' | 'skip'],
fc: FcExtra,
): TestPropTuple<Ts, TsParameters>;
function buildTestProp<Ts, TsParameters extends Ts = Ts>(
// eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents
testFn: It | It['only' | 'skip' | 'concurrent'] | It['concurrent']['only' | 'skip'],
fc: FcExtra,
): TestPropRecord<Ts, TsParameters>;
function buildTestProp<Ts extends [any] | any[], TsParameters extends Ts = Ts>(
// eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents
testFn: It | It['only' | 'skip' | 'concurrent'] | It['concurrent']['only' | 'skip'],
fc: FcExtra,
): TestPropTuple<Ts, TsParameters> | TestPropRecord<Ts, TsParameters> {
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/internals/TestWithPropRunnerBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function wrapProp<Ts extends [any] | any[]>(prop: Prop<Ts>): PromiseProp<Ts> {
}

export function buildTestWithPropRunner<Ts extends [any] | any[], TsParameters extends Ts = Ts>(
// eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents
testFn: It | It['only' | 'skip' | 'concurrent'] | It['concurrent']['only' | 'skip'],
label: string,
arbitraries: ArbitraryTuple<Ts>,
Expand Down
1 change: 1 addition & 0 deletions packages/worker/src/internals/worker-pool/GlobalPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class GlobalPool<TSuccess, TPayload> implements IWorkerPool<TSuccess, TPa
pendingTerminationPerFile.set(
this.workerFileUrl.toString(),
setTimeout(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.internalPool.terminateAllWorkers();
}, 0),
);
Expand Down

0 comments on commit 0bbef2c

Please sign in to comment.