From 6dd18d81d412cbcdc6134129424275709d15f72f Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Thu, 27 Jul 2023 16:36:01 +0200 Subject: [PATCH] Enabled `no-explicit-any` for majority of packages refs https://github.com/TryGhost/DevOps/issues/50 - we should default to keeping the rule on and so I've excluded lines that currently use `any` to avoid the need to go and fix them all up --- apps/signup-form/.eslintrc.cjs | 8 +++++--- apps/signup-form/src/App.tsx | 1 + apps/signup-form/src/AppContext.ts | 2 ++ apps/signup-form/src/Preview.stories.tsx | 2 ++ apps/signup-form/src/components/IFrame.tsx | 1 + apps/signup-form/test/e2e/attribution.test.ts | 1 + apps/signup-form/test/utils/e2e.ts | 2 ++ ghost/collections/.eslintrc.js | 6 +----- ghost/collections/src/Collection.ts | 3 +++ ghost/collections/src/CollectionRepository.ts | 1 + ghost/collections/src/CollectionsRepositoryInMemory.ts | 1 + ghost/collections/src/CollectionsService.ts | 8 ++++++++ ghost/collections/src/events/PostAddedEvent.ts | 1 + ghost/collections/src/events/PostDeletedEvent.ts | 2 ++ ghost/collections/src/events/PostEditedEvent.ts | 2 ++ ghost/collections/src/events/TagDeletedEvent.ts | 1 + ghost/in-memory-repository/.eslintrc.js | 6 +----- ghost/in-memory-repository/src/InMemoryRepository.ts | 2 ++ ghost/mail-events/.eslintrc.js | 6 +----- ghost/mail-events/src/MailEventService.ts | 1 + ghost/model-to-domain-event-interceptor/.eslintrc.js | 6 +----- .../src/ModelToDomainEventInterceptor.ts | 7 +++++++ ghost/post-revisions/.eslintrc.js | 5 +---- ghost/post-revisions/src/PostRevisions.ts | 3 +++ 24 files changed, 51 insertions(+), 27 deletions(-) diff --git a/apps/signup-form/.eslintrc.cjs b/apps/signup-form/.eslintrc.cjs index 8d4e6ed35f..2ae5fe04f8 100644 --- a/apps/signup-form/.eslintrc.cjs +++ b/apps/signup-form/.eslintrc.cjs @@ -9,15 +9,17 @@ module.exports = { 'ghost', 'tailwindcss' ], + settings: { + react: { + version: 'detect' + } + }, rules: { // sort multiple import lines into alphabetical groups 'ghost/sort-imports-es6-autofix/sort-imports-es6': ['error', { memberSyntaxSortOrder: ['none', 'all', 'single', 'multiple'] }], - // TODO: fix + remove this - '@typescript-eslint/no-explicit-any': 'warn', - // suppress errors for missing 'import React' in JSX files, as we don't need it 'react/react-in-jsx-scope': 'off', // ignore prop-types for now diff --git a/apps/signup-form/src/App.tsx b/apps/signup-form/src/App.tsx index 1b92a12d18..56f9e4b2ac 100644 --- a/apps/signup-form/src/App.tsx +++ b/apps/signup-form/src/App.tsx @@ -41,6 +41,7 @@ const App: React.FC = ({scriptTag}) => { }; const PageComponent = pages[page.name]; + // eslint-disable-next-line @typescript-eslint/no-explicit-any const data = page.data as any; // issue with TypeScript understanding the type here when passing it to the component return ( <> diff --git a/apps/signup-form/src/AppContext.ts b/apps/signup-form/src/AppContext.ts index 4d466a3ab6..73cb00b939 100644 --- a/apps/signup-form/src/AppContext.ts +++ b/apps/signup-form/src/AppContext.ts @@ -21,10 +21,12 @@ export type AppContextType = { setPage: (name: T, data: ComponentProps) => void, options: SignupFormOptions, api: GhostApi, + // eslint-disable-next-line @typescript-eslint/no-explicit-any t: any, scriptTag: HTMLElement } +// eslint-disable-next-line @typescript-eslint/no-explicit-any const AppContext = React.createContext({} as any); export const AppContextProvider = AppContext.Provider; diff --git a/apps/signup-form/src/Preview.stories.tsx b/apps/signup-form/src/Preview.stories.tsx index 26123ee28a..3274bed9da 100644 --- a/apps/signup-form/src/Preview.stories.tsx +++ b/apps/signup-form/src/Preview.stories.tsx @@ -16,6 +16,7 @@ const Preview: React.FC { setPage(() => ({ name, @@ -24,6 +25,7 @@ const Preview: React.FC { let id; diff --git a/ghost/collections/src/CollectionRepository.ts b/ghost/collections/src/CollectionRepository.ts index 4f7be160ae..1dd88b5933 100644 --- a/ghost/collections/src/CollectionRepository.ts +++ b/ghost/collections/src/CollectionRepository.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import {Collection} from './Collection'; export interface CollectionRepository { diff --git a/ghost/collections/src/CollectionsRepositoryInMemory.ts b/ghost/collections/src/CollectionsRepositoryInMemory.ts index c6d0ff91eb..1a0b74e083 100644 --- a/ghost/collections/src/CollectionsRepositoryInMemory.ts +++ b/ghost/collections/src/CollectionsRepositoryInMemory.ts @@ -6,6 +6,7 @@ export class CollectionsRepositoryInMemory extends InMemoryRepository Promise): Promise { return cb(null); } diff --git a/ghost/collections/src/CollectionsService.ts b/ghost/collections/src/CollectionsService.ts index f8e52e947e..56508cde4a 100644 --- a/ghost/collections/src/CollectionsService.ts +++ b/ghost/collections/src/CollectionsService.ts @@ -22,6 +22,7 @@ const messages = { }; interface SlugService { + // eslint-disable-next-line @typescript-eslint/no-explicit-any generate(desired: string, options: {transaction: any}): Promise; } @@ -30,6 +31,7 @@ type CollectionsServiceDeps = { postsRepository: PostsRepository; slugService: SlugService; DomainEvents: { + // eslint-disable-next-line @typescript-eslint/no-explicit-any subscribe: (event: any, handler: (e: any) => void) => void; }; }; @@ -92,6 +94,7 @@ type QueryOptions = { include?: string; page?: number; limit?: number; + // eslint-disable-next-line @typescript-eslint/no-explicit-any transaction?: any; } @@ -103,6 +106,7 @@ export class CollectionsService { private collectionsRepository: CollectionRepository; private postsRepository: PostsRepository; private DomainEvents: { + // eslint-disable-next-line @typescript-eslint/no-explicit-any subscribe: (event: any, handler: (e: any) => void) => void; }; private uniqueChecker: RepositoryUniqueChecker; @@ -134,7 +138,9 @@ export class CollectionsService { }; } + // eslint-disable-next-line @typescript-eslint/no-explicit-any private fromDTO(data: any): any { + // eslint-disable-next-line @typescript-eslint/no-explicit-any const mappedDTO: {[index: string]:any} = { title: data.title, slug: data.slug, @@ -308,6 +314,7 @@ export class CollectionsService { }); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any async edit(data: any): Promise { return await this.collectionsRepository.createTransaction(async (transaction) => { const collection = await this.collectionsRepository.getById(data.id, {transaction}); @@ -352,6 +359,7 @@ export class CollectionsService { return await this.collectionsRepository.getBySlug(slug); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any async getAll(options?: QueryOptions): Promise<{data: CollectionDTO[], meta: any}> { const collections = await this.collectionsRepository.getAll(options); diff --git a/ghost/collections/src/events/PostAddedEvent.ts b/ghost/collections/src/events/PostAddedEvent.ts index 1d00bf6a86..d714661966 100644 --- a/ghost/collections/src/events/PostAddedEvent.ts +++ b/ghost/collections/src/events/PostAddedEvent.ts @@ -16,6 +16,7 @@ export class PostAddedEvent { this.timestamp = timestamp; } + // eslint-disable-next-line @typescript-eslint/no-explicit-any static create(data: any, timestamp = new Date()) { return new PostAddedEvent(data, timestamp); } diff --git a/ghost/collections/src/events/PostDeletedEvent.ts b/ghost/collections/src/events/PostDeletedEvent.ts index dfeed88449..113fc9ac68 100644 --- a/ghost/collections/src/events/PostDeletedEvent.ts +++ b/ghost/collections/src/events/PostDeletedEvent.ts @@ -1,5 +1,6 @@ export class PostDeletedEvent { id: string; + // eslint-disable-next-line @typescript-eslint/no-explicit-any data: any; timestamp: Date; @@ -9,6 +10,7 @@ export class PostDeletedEvent { this.timestamp = timestamp; } + // eslint-disable-next-line @typescript-eslint/no-explicit-any static create(data: any, timestamp = new Date()) { return new PostDeletedEvent(data, timestamp); } diff --git a/ghost/collections/src/events/PostEditedEvent.ts b/ghost/collections/src/events/PostEditedEvent.ts index 1711d6f89d..1f5c7c37da 100644 --- a/ghost/collections/src/events/PostEditedEvent.ts +++ b/ghost/collections/src/events/PostEditedEvent.ts @@ -23,12 +23,14 @@ export class PostEditedEvent { data: PostEditData; timestamp: Date; + // eslint-disable-next-line @typescript-eslint/no-explicit-any constructor(data: any, timestamp: Date) { this.id = data.id; this.data = data; this.timestamp = timestamp; } + // eslint-disable-next-line @typescript-eslint/no-explicit-any static create(data: any, timestamp = new Date()) { return new PostEditedEvent(data, timestamp); } diff --git a/ghost/collections/src/events/TagDeletedEvent.ts b/ghost/collections/src/events/TagDeletedEvent.ts index b460147610..a0161e3f6f 100644 --- a/ghost/collections/src/events/TagDeletedEvent.ts +++ b/ghost/collections/src/events/TagDeletedEvent.ts @@ -9,6 +9,7 @@ export class TagDeletedEvent { this.timestamp = timestamp; } + // eslint-disable-next-line @typescript-eslint/no-explicit-any static create(data: any, timestamp = new Date()) { return new TagDeletedEvent(data, timestamp); } diff --git a/ghost/in-memory-repository/.eslintrc.js b/ghost/in-memory-repository/.eslintrc.js index 40fd4300ae..cb690be63f 100644 --- a/ghost/in-memory-repository/.eslintrc.js +++ b/ghost/in-memory-repository/.eslintrc.js @@ -2,9 +2,5 @@ module.exports = { plugins: ['ghost'], extends: [ 'plugin:ghost/ts' - ], - rules: { - // TODO: fix + remove this - '@typescript-eslint/no-explicit-any': 'warn', - } + ] }; diff --git a/ghost/in-memory-repository/src/InMemoryRepository.ts b/ghost/in-memory-repository/src/InMemoryRepository.ts index f7fa2d33eb..60d92615af 100644 --- a/ghost/in-memory-repository/src/InMemoryRepository.ts +++ b/ghost/in-memory-repository/src/InMemoryRepository.ts @@ -10,6 +10,7 @@ type Order = { direction: 'asc' | 'desc'; } +// eslint-disable-next-line @typescript-eslint/no-explicit-any type OrderOption> = Order[]; export abstract class InMemoryRepository> { @@ -51,6 +52,7 @@ export abstract class InMemoryRepository> { for (const order of options.order) { results.sort((a, b) => { if (order.direction === 'asc') { + // eslint-disable-next-line @typescript-eslint/no-explicit-any return a[order.field] as any > (b[order.field] as any) ? 1 : -1; } else { return a[order.field] < b[order.field] ? 1 : -1; diff --git a/ghost/mail-events/.eslintrc.js b/ghost/mail-events/.eslintrc.js index 40fd4300ae..cb690be63f 100644 --- a/ghost/mail-events/.eslintrc.js +++ b/ghost/mail-events/.eslintrc.js @@ -2,9 +2,5 @@ module.exports = { plugins: ['ghost'], extends: [ 'plugin:ghost/ts' - ], - rules: { - // TODO: fix + remove this - '@typescript-eslint/no-explicit-any': 'warn', - } + ] }; diff --git a/ghost/mail-events/src/MailEventService.ts b/ghost/mail-events/src/MailEventService.ts index 39f893c96e..8c10d07deb 100644 --- a/ghost/mail-events/src/MailEventService.ts +++ b/ghost/mail-events/src/MailEventService.ts @@ -39,6 +39,7 @@ interface Labs { } interface Config { + // eslint-disable-next-line @typescript-eslint/no-explicit-any get(key: string): any; } diff --git a/ghost/model-to-domain-event-interceptor/.eslintrc.js b/ghost/model-to-domain-event-interceptor/.eslintrc.js index 40fd4300ae..cb690be63f 100644 --- a/ghost/model-to-domain-event-interceptor/.eslintrc.js +++ b/ghost/model-to-domain-event-interceptor/.eslintrc.js @@ -2,9 +2,5 @@ module.exports = { plugins: ['ghost'], extends: [ 'plugin:ghost/ts' - ], - rules: { - // TODO: fix + remove this - '@typescript-eslint/no-explicit-any': 'warn', - } + ] }; diff --git a/ghost/model-to-domain-event-interceptor/src/ModelToDomainEventInterceptor.ts b/ghost/model-to-domain-event-interceptor/src/ModelToDomainEventInterceptor.ts index c8b9e5618a..59f7abcb1f 100644 --- a/ghost/model-to-domain-event-interceptor/src/ModelToDomainEventInterceptor.ts +++ b/ghost/model-to-domain-event-interceptor/src/ModelToDomainEventInterceptor.ts @@ -2,10 +2,13 @@ import { PostDeletedEvent, PostAddedEvent, PostEditedEvent, TagDeletedEvent } fr type ModelToDomainEventInterceptorDeps = { ModelEvents: { + // eslint-disable-next-line @typescript-eslint/no-explicit-any hasRegisteredListener: (event: any, listenerName: string) => boolean; + // eslint-disable-next-line @typescript-eslint/no-explicit-any on: (eventName: string, callback: (data: any) => void) => void; }, DomainEvents: { + // eslint-disable-next-line @typescript-eslint/no-explicit-any dispatch: (event: any) => void; } } @@ -32,6 +35,7 @@ export class ModelToDomainEventInterceptor { for (const modelEventName of ghostModelUpdateEvents) { if (!this.ModelEvents.hasRegisteredListener(modelEventName, 'collectionListener')) { const dispatcher = this.domainEventDispatcher.bind(this); + // eslint-disable-next-line @typescript-eslint/no-explicit-any const listener = function (data: any) { dispatcher(modelEventName, data); }; @@ -42,6 +46,7 @@ export class ModelToDomainEventInterceptor { } } + // eslint-disable-next-line @typescript-eslint/no-explicit-any domainEventDispatcher(modelEventName: string, data: any) { let event; @@ -66,6 +71,7 @@ export class ModelToDomainEventInterceptor { status: data.attributes.status, featured: data.attributes.featured, published_at: data.attributes.published_at, + // eslint-disable-next-line @typescript-eslint/no-explicit-any tags: data.relations?.tags?.models.map((tag: any) => ({ slug: tag.get('slug') })) @@ -78,6 +84,7 @@ export class ModelToDomainEventInterceptor { status: data._previousAttributes?.status, featured: data._previousAttributes?.featured, published_at: data._previousAttributes?.published_at, + // eslint-disable-next-line @typescript-eslint/no-explicit-any tags: data._previousRelations?.tags?.models.map((tag: any) => ({ slug: tag.get('slug') })) diff --git a/ghost/post-revisions/.eslintrc.js b/ghost/post-revisions/.eslintrc.js index 3ef82e1d78..cb690be63f 100644 --- a/ghost/post-revisions/.eslintrc.js +++ b/ghost/post-revisions/.eslintrc.js @@ -2,8 +2,5 @@ module.exports = { plugins: ['ghost'], extends: [ 'plugin:ghost/ts' - ], - rules: { - '@typescript-eslint/no-explicit-any': 'warn', - } + ] }; diff --git a/ghost/post-revisions/src/PostRevisions.ts b/ghost/post-revisions/src/PostRevisions.ts index 28c41310bf..e6536f47c7 100644 --- a/ghost/post-revisions/src/PostRevisions.ts +++ b/ghost/post-revisions/src/PostRevisions.ts @@ -29,6 +29,7 @@ type PostRevisionsDeps = { max_revisions: number; revision_interval_ms: number; }, + // eslint-disable-next-line @typescript-eslint/no-explicit-any model: any } @@ -41,6 +42,7 @@ type RevisionResult = { export class PostRevisions { config: PostRevisionsDeps['config']; + // eslint-disable-next-line @typescript-eslint/no-explicit-any model: any; constructor(deps: PostRevisionsDeps) { @@ -122,6 +124,7 @@ export class PostRevisions { }; } + // eslint-disable-next-line @typescript-eslint/no-explicit-any async removeAuthorFromRevisions(authorId: string, options: any): Promise { const revisions = await this.model.findAll({ filter: `author_id:${authorId}`,