From 94bda7dd0c725b106987cf7405ee390af10be706 Mon Sep 17 00:00:00 2001 From: Valentin Agachi Date: Thu, 9 Jan 2025 10:35:36 +0000 Subject: [PATCH] fixup! chore: Upgrade eslint monorepo to v9.17.0 --- eslint.config.js | 1 - package.json | 2 +- src/__tests__/schema.test.ts | 62 ++++++++++++++++++------------------ src/index.ts | 2 -- src/model.ts | 1 - 5 files changed, 32 insertions(+), 36 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 4d65a3f2b..c3829cb0c 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -96,7 +96,6 @@ export default typescriptEslint.config( '@typescript-eslint/no-extra-semi': 'error', '@typescript-eslint/no-extraneous-class': 'error', '@typescript-eslint/no-restricted-types': 'warn', - '@typescript-eslint/no-unnecessary-condition': 'error', '@typescript-eslint/no-unnecessary-type-arguments': 'error', '@typescript-eslint/no-unsafe-argument': 'warn', '@typescript-eslint/no-unsafe-assignment': 'warn', diff --git a/package.json b/package.json index c02298c31..45cb7b5af 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "docs": "pnpm build:docs && docsify serve ./docs", "benchmark": "pnpm build && node --experimental-specifier-resolution=node ./benchmark/run.js", "lint:ci": "./tests/build.sh && eslint .", - "lint": "eslint .", + "lint": "eslint --report-unused-disable-directives .", "postpack": "pinst --enable", "prepack": "pinst --disable && pnpm build", "prepare": "husky", diff --git a/src/__tests__/schema.test.ts b/src/__tests__/schema.test.ts index 40fa47df5..bab6e8c32 100644 --- a/src/__tests__/schema.test.ts +++ b/src/__tests__/schema.test.ts @@ -48,8 +48,8 @@ describe('schema', () => { {}, ] >(value); - expectType(value[0]._id); - expectType(value[0].foo); + expectType(value[0]?._id); + expectType(value[0]?.foo); expectType<(typeof value)[0]>({ _id: new ObjectId(), bar: 123, @@ -104,8 +104,8 @@ describe('schema', () => { }, ] >(value); - expectType(value[0]._id); - expectType(value[0].foo); + expectType(value[0]?._id); + expectType(value[0]?.foo); expectType<(typeof value)[0]>({ _id: new ObjectId(), bar: 123, @@ -180,9 +180,9 @@ describe('schema', () => { }, ] >(value); - expectType(value[0]._id); - expectType<'baz' | 'ham' | undefined>(value[0].enumConstOptional); - expectType<'baz' | 'ham'>(value[0].enumConstRequired); + expectType(value[0]?._id); + expectType<'baz' | 'ham' | undefined>(value[0]?.enumConstOptional); + expectType<'baz' | 'ham'>(value[0]?.enumConstRequired); expectType<(typeof value)[0]>({ _id: new ObjectId(), enumConstOptional: 'ham', @@ -242,10 +242,10 @@ describe('schema', () => { { timestamps: boolean }, ] >(value); - expectType(value[0]._id); - expectType(value[0].foo); - expectType(value[0].createdAt); - expectType(value[0].updatedAt); + expectType(value[0]?._id); + expectType(value[0]?.foo); + expectType(value[0]?.createdAt); + expectType(value[0]?.updatedAt); expectType<(typeof value)[0]>({ _id: new ObjectId(), createdAt: new Date(), @@ -289,10 +289,10 @@ describe('schema', () => { { timestamps: boolean }, ] >(value); - expectType(value[0]._id); - expectType(value[0].foo); + expectType(value[0]?._id); + expectType(value[0]?.foo); // @ts-expect-error `createdAt` is undefined here - value[0].createdAt; + value[0]?.createdAt; expectType<(typeof value)[0]>({ _id: new ObjectId(), foo: true, @@ -354,14 +354,14 @@ describe('schema', () => { }, ] >(value); - expectType(value[0]._id); - expectType(value[0].foo); - expectType(value[0]._createdDate); - expectType(value[0]._updatedDate); + expectType(value[0]?._id); + expectType(value[0]?.foo); + expectType(value[0]?._createdDate); + expectType(value[0]?._updatedDate); // @ts-expect-error `createdAt` is undefined here - value[0].createdAt; + value[0]?.createdAt; // @ts-expect-error `updatedAt` is undefined here - value[0].updatedAt; + value[0]?.updatedAt; expectType<(typeof value)[0]>({ _createdDate: new Date(), _id: new ObjectId(), @@ -422,12 +422,12 @@ describe('schema', () => { }, ] >(value); - expectType(value[0]._id); - expectType(value[0].foo); - expectType(value[0]._createdDate); - expectType(value[0].updatedAt); + expectType(value[0]?._id); + expectType(value[0]?.foo); + expectType(value[0]?._createdDate); + expectType(value[0]?.updatedAt); // @ts-expect-error `createdAt` is undefined here - value[0].createdAt; + value[0]?.createdAt; expectType<(typeof value)[0]>({ _createdDate: new Date(), _id: new ObjectId(), @@ -469,7 +469,7 @@ describe('schema', () => { {}, ] >(value); - expectType(value[0]._id); + expectType(value[0]?._id); expectType<(typeof value)[0]>({ _id: 'first', foo: 123, @@ -512,7 +512,7 @@ describe('schema', () => { {}, ] >(value); - expectType(value[0]._id); + expectType(value[0]?._id); expectType<(typeof value)[0]>({ _id: 123, foo: 'first', @@ -857,7 +857,7 @@ describe('schema', () => { validationAction: typeof VALIDATION_ACTIONS.WARN; validationLevel: typeof VALIDATION_LEVEL.MODERATE; }>(value[1]); - expectType(value[0]._id); + expectType(value[0]?._id); }); test('explicit optional - simple', () => { @@ -896,8 +896,8 @@ describe('schema', () => { {}, ] >(value); - expectType(value[0]._id); - expectType(value[0].foo); + expectType(value[0]?._id); + expectType(value[0]?.foo); expectType<(typeof value)[0]>({ _id: new ObjectId(), bar: 123, @@ -1219,6 +1219,6 @@ describe('schema', () => { validationAction: typeof VALIDATION_ACTIONS.WARN; validationLevel: typeof VALIDATION_LEVEL.MODERATE; }>(value[1]); - expectType(value[0]._id); + expectType(value[0]?._id); }); }); diff --git a/src/index.ts b/src/index.ts index cbcacfdd2..b3ae416a8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -60,7 +60,6 @@ export default class Papr { // If we have models defined before initializing a database, we build them now for (const [collectionName, collectionSchema] of this.schemas.entries()) { const model = this.models.get(collectionName); - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (model && !model.collection) { build(collectionSchema, model, this.db.collection(collectionName), this.options); } @@ -114,7 +113,6 @@ export default class Papr { if (!this.db) { throw new Error('The DB is not connected'); } - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (!model.collection) { throw new Error('The model collection is not initialized'); } diff --git a/src/model.ts b/src/model.ts index 7d4b69371..9db1a907b 100644 --- a/src/model.ts +++ b/src/model.ts @@ -267,7 +267,6 @@ export function build