From b228007250f400312d4c5b7bce0a8ae901917b37 Mon Sep 17 00:00:00 2001 From: Kevin Scott <151596+thekevinscott@users.noreply.github.com> Date: Fri, 15 Sep 2023 11:54:53 -0400 Subject: [PATCH] Address deepsource complaints --- internals/cli/src/commands/write/docs/api.ts | 16 +++---- .../cli/src/commands/write/docs/guides.ts | 32 ++++++++++---- .../cli/src/commands/write/docs/index.ts | 5 +++ .../cli/src/commands/write/docs/models.ts | 42 +++++++++++-------- internals/cli/src/lib/cli/start-watch.ts | 4 +- .../get-all-declaration-reflections-test.ts | 16 +++---- ...aration-reflections-from-packages.test.ts} | 5 ++- .../get-definitions/get-definitions.test.ts | 16 +++---- .../get-package-as-tree.test.ts | 4 +- ...m-platform-specific-upscaler-files.test.ts | 7 ++-- ...s-from-platform-specific-upscaler-files.ts | 4 +- .../get-sorted-methods-for-writing.test.ts | 4 +- .../get-content-for-method.ts | 9 +--- .../get-matching-type.test.ts | 18 ++++---- .../get-return-type.ts | 8 ++-- .../get-url-from-sources.test.ts | 1 - .../write-api-documentation-files.test.ts | 2 +- .../write-api-documentation-files.ts | 2 +- .../write-parameter.ts | 7 ++-- .../rollup-configs/models-rollup-config.ts | 2 +- .../upscalerjs-rollup-config.ts | 2 +- 21 files changed, 116 insertions(+), 90 deletions(-) rename internals/cli/src/lib/commands/write/docs/api/get-definitions/{get-declaration-reflections-form-packages.test.ts => get-declaration-reflections-from-packages.test.ts} (89%) diff --git a/internals/cli/src/commands/write/docs/api.ts b/internals/cli/src/commands/write/docs/api.ts index 567d52b82..bd60f6249 100644 --- a/internals/cli/src/commands/write/docs/api.ts +++ b/internals/cli/src/commands/write/docs/api.ts @@ -1,20 +1,15 @@ import { Command } from '@commander-js/extra-typings'; import path from 'path'; -import { CLI_DIR, CORE_DIR, DOCS_DIR, UPSCALER_DIR } from '@internals/common/constants'; +import { CORE_DIR, DOCS_DIR, UPSCALER_DIR } from '@internals/common/constants'; import { mkdirp } from '@internals/common/fs'; import { writeAPIDocs } from '../../../lib/commands/write/docs/api/index.js'; import { clearOutMarkdownFiles } from '../../../lib/utils/clear-out-markdown-files.js'; import { startWatch } from '../../../lib/cli/start-watch.js'; import { info, verbose } from '@internals/common/logger'; -import { exec, spawn } from 'child_process'; +import { Opts } from './index.js'; const EXAMPLES_DOCS_DEST = path.resolve(DOCS_DIR, 'docs/documentation/api'); -interface Opts { - shouldClearMarkdown?: boolean; - watch?: boolean; -} - const writeAPIDocumentation = async ({ shouldClearMarkdown }: Pick) => { info('Writing API documentation'); await mkdirp(EXAMPLES_DOCS_DEST); @@ -23,12 +18,12 @@ const writeAPIDocumentation = async ({ shouldClearMarkdown }: Pick program.command('api') .description('Write API documentation') - .action(async ({ watch, shouldClearMarkdown }: Opts) => { + .action(({ watch, shouldClearMarkdown }: Opts) => { if (watch) { return startWatch( `pnpm cli write docs api ${shouldClearMarkdown ? '-c' : ''}`, @@ -39,7 +34,6 @@ export default (program: Command) => program.command('api') ignored: path.join(UPSCALER_DIR, '**/*.generated.ts'), persistent: true, }); - } else { - writeAPIDocumentation({ shouldClearMarkdown }); } + return writeAPIDocumentation({ shouldClearMarkdown }); }); diff --git a/internals/cli/src/commands/write/docs/guides.ts b/internals/cli/src/commands/write/docs/guides.ts index 280583fd3..4fe2094d4 100644 --- a/internals/cli/src/commands/write/docs/guides.ts +++ b/internals/cli/src/commands/write/docs/guides.ts @@ -1,19 +1,37 @@ import { Command } from '@commander-js/extra-typings'; import path from 'path'; -import { DOCS_DIR } from '@internals/common/constants'; +import { DOCS_DIR, EXAMPLES_DIR } from '@internals/common/constants'; import { mkdirp } from '@internals/common/fs'; import { clearOutMarkdownFiles } from '../../../lib/utils/clear-out-markdown-files.js'; import { writeGuideDocs } from '../../../lib/commands/write/docs/guides.js'; +import { Opts } from './index.js'; +import { info, verbose } from '@internals/common/logger'; +import { startWatch } from '../../../lib/cli/start-watch.js'; const EXAMPLES_DOCS_DEST = path.resolve(DOCS_DIR, 'docs/documentation/guides'); +const writeGuideDocumentation = async ({ shouldClearMarkdown }: Pick) => { + info('Writing guides documentation'); + await mkdirp(EXAMPLES_DOCS_DEST); + if (shouldClearMarkdown) { + verbose(`Clearing out markdown files in ${EXAMPLES_DOCS_DEST}`) + await clearOutMarkdownFiles(EXAMPLES_DOCS_DEST); + } + + return writeGuideDocs(EXAMPLES_DOCS_DEST); +}; + export default (program: Command) => program.command('guides') .description('Write Guides documentation') - .action(async (opts) => { - await mkdirp(EXAMPLES_DOCS_DEST); - if ('shouldClearMarkdown' in opts && opts.shouldClearMarkdown) { - await clearOutMarkdownFiles(EXAMPLES_DOCS_DEST); + .action(async ({ watch, shouldClearMarkdown }: Opts) => { + if (watch) { + return startWatch( + `pnpm cli write docs model ${shouldClearMarkdown ? '-c' : ''}`, + [ + path.join(EXAMPLES_DIR, '**/*.md'), + ], { + persistent: true, + }); } - - return await writeGuideDocs(EXAMPLES_DOCS_DEST); + return writeGuideDocumentation({ shouldClearMarkdown }) }); diff --git a/internals/cli/src/commands/write/docs/index.ts b/internals/cli/src/commands/write/docs/index.ts index d1666fb2a..f40b0d82d 100644 --- a/internals/cli/src/commands/write/docs/index.ts +++ b/internals/cli/src/commands/write/docs/index.ts @@ -7,3 +7,8 @@ export default (program: Command) => program.command('docs') export const postProcess = (program: Command) => program .option('-c, --should-clear-markdown', 'Whether to clear markdown files or not', false) .option('-w, --watch', 'Whether to run in watch mode or not', false) + +export interface Opts { + shouldClearMarkdown?: boolean; + watch?: boolean; +} diff --git a/internals/cli/src/commands/write/docs/models.ts b/internals/cli/src/commands/write/docs/models.ts index e4bf8efd0..4ec08271d 100644 --- a/internals/cli/src/commands/write/docs/models.ts +++ b/internals/cli/src/commands/write/docs/models.ts @@ -1,33 +1,39 @@ import { Command } from '@commander-js/extra-typings'; import path from 'path'; -import { DOCS_DIR } from '@internals/common/constants'; +import { CORE_DIR, DOCS_DIR, MODELS_DIR, UPSCALER_DIR } from '@internals/common/constants'; import { mkdirp } from '@internals/common/fs'; import { clearOutMarkdownFiles } from '../../../lib/utils/clear-out-markdown-files.js'; import { writeModelReadmes } from '../../../lib/commands/write/docs/models.js'; -import chokidar from 'chokidar'; +import { startWatch } from '../../../lib/cli/start-watch.js'; +import { Opts } from './index.js'; +import { verbose } from '@internals/common/logger'; +import { info } from 'console'; const targetDocDir = path.resolve(DOCS_DIR, 'docs/models/available'); +const writeModelsDocumentation = async ({ shouldClearMarkdown }: Pick) => { + info('Writing models documentation'); + await mkdirp(targetDocDir); + if (shouldClearMarkdown) { + verbose(`Clearing out markdown files in ${targetDocDir}`) + await clearOutMarkdownFiles(targetDocDir); + } + + return writeModelReadmes(targetDocDir); +}; + export default (program: Command) => program.command('models') .description('Write Model readme documentation') - .action(async (opts) => { - await mkdirp(targetDocDir); - if ('shouldClearMarkdown' in opts && opts.shouldClearMarkdown) { - await clearOutMarkdownFiles(targetDocDir); - } - - if ('watch' in opts && opts.watch) { - const watcher = chokidar.watch([ - '../packages/core/**/*', - '../packages/upscalerjs/**/*', - '../internals/cli/src/lib/write/docs/api/**/*', - ], { - ignored: '../packages/upscalerjs/**/*.generated.ts', + .action(({ watch, shouldClearMarkdown }: Opts) => { + if (watch) { + return startWatch( + `pnpm cli write docs model ${shouldClearMarkdown ? '-c' : ''}`, + [ + path.join(MODELS_DIR, '**/*.md'), + ], { persistent: true, }); - watcher.on('all', () => writeModelReadmes(targetDocDir)); - } else { - return await writeModelReadmes(targetDocDir); } + return writeModelsDocumentation({ shouldClearMarkdown }); }); diff --git a/internals/cli/src/lib/cli/start-watch.ts b/internals/cli/src/lib/cli/start-watch.ts index 18c797c2e..48907a838 100644 --- a/internals/cli/src/lib/cli/start-watch.ts +++ b/internals/cli/src/lib/cli/start-watch.ts @@ -1,6 +1,6 @@ import chokidar from 'chokidar'; import { error, verbose } from '@internals/common/logger'; -import { ChildProcess, spawn } from 'child_process'; +import { ChildProcess } from 'child_process'; import path from 'path'; import { CLI_DIR, ROOT_DIR } from '@internals/common/constants'; import { SpawnError, spawnProcess } from './spawn-process.js'; @@ -22,7 +22,7 @@ export const startWatch = ( let last: number; let iterations = 0; let spawnedProcess: ChildProcess | undefined; - watcher.on('all', async (event, file, stats) => { + watcher.on('all', (event, file) => { console.clear(); if (spawnedProcess) { verbose(`>> Killing previous spawned process ${spawnedProcess.pid}`); diff --git a/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-all-declaration-reflections-test.ts b/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-all-declaration-reflections-test.ts index 70439ab2e..2e8afae52 100644 --- a/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-all-declaration-reflections-test.ts +++ b/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-all-declaration-reflections-test.ts @@ -1,14 +1,16 @@ +import { PlatformSpecificFileDeclarationReflection } from "../types.js"; import { getAllDeclarationReflections } from "./get-all-declaration-reflections.js"; import { getDeclarationReflectionsFromPackages } from "./get-declaration-reflections-from-packages.js"; import { getTypesFromPlatformSpecificUpscalerFiles } from "./get-types-from-platform-specific-upscaler-files.js"; +import { DeclarationReflection } from "typedoc"; -vi.mock('./get-declaration-reflections-from-packages.js'), () => ({ +vi.mock('./get-declaration-reflections-from-packages.js', () => ({ getDeclarationReflectionsFromPackages: vi.fn(), -}); +})); -vi.mock('./get-types-from-platform-specific-upscaler-files.js'), () => ({ +vi.mock('./get-types-from-platform-specific-upscaler-files.js', () => ({ getTypesFromPlatformSpecificUpscalerFiles: vi.fn(), -}) +})); describe('getAllDeclarationReflections()', () => { afterEach(() => { @@ -18,13 +20,13 @@ describe('getAllDeclarationReflections()', () => { vi.mocked(getDeclarationReflectionsFromPackages).mockImplementation(() => { return [ 'foo', - ] as any; + ] as unknown as DeclarationReflection[]; }); vi.mocked(getTypesFromPlatformSpecificUpscalerFiles).mockImplementation(() => { - return [ + return Promise.resolve([ 'bar', - ] as any; + ] as unknown as PlatformSpecificFileDeclarationReflection[]); }); const results = await getAllDeclarationReflections(); diff --git a/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-declaration-reflections-form-packages.test.ts b/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-declaration-reflections-from-packages.test.ts similarity index 89% rename from internals/cli/src/lib/commands/write/docs/api/get-definitions/get-declaration-reflections-form-packages.test.ts rename to internals/cli/src/lib/commands/write/docs/api/get-definitions/get-declaration-reflections-from-packages.test.ts index 57ba72445..3c6e0fe9b 100644 --- a/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-declaration-reflections-form-packages.test.ts +++ b/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-declaration-reflections-from-packages.test.ts @@ -1,3 +1,4 @@ +import { ProjectReflection } from "typedoc"; import { getDeclarationReflectionsFromPackages } from "./get-declaration-reflections-from-packages.js"; import { getPackageAsTree } from "./get-package-as-tree.js"; @@ -18,7 +19,7 @@ describe('getDeclarationReflectionsFromPackages', () => { 'foo', 'bar', ], - } as any; + } as unknown as ProjectReflection; }); expect(getDeclarationReflectionsFromPackages([ { @@ -32,7 +33,7 @@ describe('getDeclarationReflectionsFromPackages', () => { vi.mocked(getPackageAsTree).mockImplementation(() => { return { children: [], - } as any; + } as unknown as ProjectReflection; }); expect(() => getDeclarationReflectionsFromPackages([ { diff --git a/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-definitions.test.ts b/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-definitions.test.ts index 4e49060d6..38e4b7ab5 100644 --- a/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-definitions.test.ts +++ b/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-definitions.test.ts @@ -1,6 +1,8 @@ import { getDefinitions } from "./get-definitions.js"; import { getAllDeclarationReflections } from "./get-all-declaration-reflections.js"; -import { ReflectionKind } from "typedoc"; +import { DeclarationReference, DeclarationReflection, ReflectionKind } from "typedoc"; +import { Declaration } from "@schemastore/package"; +import { PlatformSpecificFileDeclarationReflection } from "../types.js"; vi.mock('./get-all-declaration-reflections.js', () => ({ getAllDeclarationReflections: vi.fn(), @@ -13,14 +15,14 @@ describe('getDefinitions()', () => { it('throws if given a bad "kind"', async () => { vi.mocked(getAllDeclarationReflections).mockImplementation(() => { - return [ + return Promise.resolve([ { kind: 'foo', } - ] as any; + ] as unknown as (DeclarationReflection | PlatformSpecificFileDeclarationReflection)[]); }); - expect(() => getDefinitions()).rejects.toThrow(); + await expect(() => getDefinitions()).rejects.toThrow(); }); it('gets definitions', async () => { @@ -61,7 +63,7 @@ describe('getDefinitions()', () => { node: {}, }; vi.mocked(getAllDeclarationReflections).mockImplementation(() => { - return [ + return Promise.resolve([ PlatformSpecific, Constructor, Method, @@ -70,7 +72,7 @@ describe('getDefinitions()', () => { Class, Function, Enum, - ] as any; + ] as (DeclarationReflection | PlatformSpecificFileDeclarationReflection)[]); }); const result = await getDefinitions(); @@ -92,7 +94,7 @@ describe('getDefinitions()', () => { Interface, }, classes: { - Class: Class, + Class, }, enums: { Enum, diff --git a/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-package-as-tree.test.ts b/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-package-as-tree.test.ts index 13de271c5..66e22d7c1 100644 --- a/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-package-as-tree.test.ts +++ b/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-package-as-tree.test.ts @@ -33,7 +33,7 @@ describe('getPackageAsTree', () => { }, bootstrap: vi.fn(), convert: vi.fn(), - } as any; + } as unknown as typedoc.Application; }); await expect(async () => { await getPackageAsTree('entryPoint', 'tsconfig', 'projectRoot') @@ -52,7 +52,7 @@ describe('getPackageAsTree', () => { serializer: { projectToObject, } - } as any; + } as unknown as typedoc.Application; }); const result = await getPackageAsTree('entryPoint', 'tsconfig', 'projectRoot'); expect(result).toEqual('projectToObject'); diff --git a/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-types-from-platform-specific-upscaler-files.test.ts b/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-types-from-platform-specific-upscaler-files.test.ts index 0b03798be..742b3e8d1 100644 --- a/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-types-from-platform-specific-upscaler-files.test.ts +++ b/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-types-from-platform-specific-upscaler-files.test.ts @@ -1,4 +1,4 @@ -import { DeclarationReflection, LiteralType, ProjectReflection, ReflectionKind, SomeType } from "typedoc"; +import { DeclarationReflection, ProjectReflection, ReflectionKind, SomeType } from "typedoc"; import { getPlatformSpecificUpscalerDeclarationReflections, getTypesFromPlatformSpecificUpscalerFile, @@ -112,11 +112,12 @@ describe('getTypesFromPlatformSpecificFiles', () => { }); const result = await getTypesFromPlatformSpecificUpscalerFiles([{ fileName: 'file1', - typeName: typeName, + typeName, }, { fileName: 'file2', - typeName: typeName, + typeName, }]); + expect(result).toEqual([ expect.objectContaining({ declarationReflection: expect.any(DeclarationReflection), diff --git a/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-types-from-platform-specific-upscaler-files.ts b/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-types-from-platform-specific-upscaler-files.ts index 152f03b8f..030972be1 100644 --- a/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-types-from-platform-specific-upscaler-files.ts +++ b/internals/cli/src/lib/commands/write/docs/api/get-definitions/get-types-from-platform-specific-upscaler-files.ts @@ -3,7 +3,7 @@ import { DeclarationReflection, ReflectionKind, SomeType } from "typedoc"; import { getPackageAsTree } from "./get-package-as-tree.js"; import { UPSCALER_DIR } from "@internals/common/constants"; import path from "path"; -import { Definitions, PlatformSpecificFileDeclarationReflection } from "../types.js"; +import { PlatformSpecificFileDeclarationReflection } from "../types.js"; export interface PlatformSpecificFileDefinition { fileName: string; @@ -89,6 +89,6 @@ export const getTypesFromPlatformSpecificUpscalerFile = ({ fileName, typeName }: }; }; -export const getTypesFromPlatformSpecificUpscalerFiles = async ( +export const getTypesFromPlatformSpecificUpscalerFiles = ( fileNames: PlatformSpecificFileDefinition[] ): Promise => Promise.all(fileNames.map(getTypesFromPlatformSpecificUpscalerFile)); diff --git a/internals/cli/src/lib/commands/write/docs/api/get-sorted-methods-for-writing.test.ts b/internals/cli/src/lib/commands/write/docs/api/get-sorted-methods-for-writing.test.ts index f706f758f..d8cb2216a 100644 --- a/internals/cli/src/lib/commands/write/docs/api/get-sorted-methods-for-writing.test.ts +++ b/internals/cli/src/lib/commands/write/docs/api/get-sorted-methods-for-writing.test.ts @@ -11,7 +11,7 @@ describe('getSortedMethodsForWriting()', () => { } as unknown as DecRef; const definitions = { classes: { - Class: Class, + Class, }, } as unknown as Definitions; expect(getSortedMethodsForWriting(definitions)).toEqual([ ]) @@ -37,7 +37,7 @@ describe('getSortedMethodsForWriting()', () => { } as unknown as DecRef; const definitions = { classes: { - Class: Class, + Class, }, } as unknown as Definitions; expect(getSortedMethodsForWriting(definitions)).toEqual([ diff --git a/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/get-content-for-method.ts b/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/get-content-for-method.ts index c6c8e6c24..f457fa0db 100644 --- a/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/get-content-for-method.ts +++ b/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/get-content-for-method.ts @@ -49,19 +49,14 @@ export const getContentForMethod = async (method: DeclarationReflection, definit throw new Error(`No sources found for ${name}`); } if (!signatures?.length) { - const { type: _type, ...m } = method; + const { type: _type } = method; throw new Error(`No signatures found in ${name}`); } const signature = signatures[0] as SignatureReflection & { typeParameter?: TypeParameterReflection[] }; const { comment, parameters, typeParameter: typeParameters } = signature; const { description, codeSnippet, blockTags } = getTextSummary(name, comment); - let source; - try { - source = await getSource(sources); - } catch(e) { - throw e; - } + const source = await getSource(sources); const content = [ [ diff --git a/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/get-matching-type.test.ts b/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/get-matching-type.test.ts index e0fc981be..5dbcd9b76 100644 --- a/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/get-matching-type.test.ts +++ b/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/get-matching-type.test.ts @@ -1,4 +1,4 @@ -import { ArrayType, DeclarationReflection, Reflection, ReflectionKind, TypeParameterReflection } from "typedoc"; +import { ArrayType, DeclarationReflection, ReflectionKind } from "typedoc"; import { getMatchingType } from "./get-matching-type.js"; import { getReferenceTypeOfParameter } from "./get-reference-type-of-parameter.js"; import * as constants from "../constants.js"; @@ -82,7 +82,7 @@ const mockDefinitions = (): Definitions => { Interface, }, classes: { - Class: Class, + Class, }, enums: { Enum, @@ -106,8 +106,8 @@ describe('getMatchingType', () => { constants.INTRINSIC_TYPES.push('foo'); vi.mocked(getReferenceTypeOfParameter).mockImplementation(() => ({ name: 'foo', - type: 'literal' as 'literal', - })); + type: 'literal', + }) as ReturnType); expect(getMatchingType(parameter, definitions, {})).toEqual(undefined); }); @@ -118,7 +118,7 @@ describe('getMatchingType', () => { vi.mocked(getReferenceTypeOfParameter).mockImplementation(() => ({ name: 'foo', type: 'literal' as 'literal', - })); + }) as ReturnType); expect(getMatchingType(parameter, definitions, {})).toEqual(undefined); }); @@ -129,7 +129,7 @@ describe('getMatchingType', () => { vi.mocked(getReferenceTypeOfParameter).mockImplementation(() => ({ name: 'foo', type: 'literal' as 'literal', - })); + }) as ReturnType); vi.mocked(isLiteralType).mockImplementation(() => true) expect(getMatchingType(parameter, definitions, {})).toEqual(undefined); }); @@ -145,7 +145,7 @@ describe('getMatchingType', () => { vi.mocked(getReferenceTypeOfParameter).mockImplementation(() => ({ name: 'Foo', type: 'literal' as 'literal', - })); + }) as ReturnType); expect(getMatchingType(parameter, definitions, {})).toEqual(externalType); }); @@ -156,7 +156,7 @@ describe('getMatchingType', () => { vi.mocked(getReferenceTypeOfParameter).mockImplementation(() => ({ name: Interface.name, type: 'literal' as 'literal', - })); + }) as ReturnType); expect(getMatchingType(parameter, definitions, {})).toEqual(Interface); }); @@ -167,7 +167,7 @@ describe('getMatchingType', () => { vi.mocked(getReferenceTypeOfParameter).mockImplementation(() => ({ name: TypeAlias.name, type: 'literal' as 'literal', - })); + }) as ReturnType); expect(getMatchingType(parameter, definitions, {})).toEqual(TypeAlias); }); diff --git a/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/get-return-type.ts b/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/get-return-type.ts index e54586e3d..9c75fcb5f 100644 --- a/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/get-return-type.ts +++ b/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/get-return-type.ts @@ -28,15 +28,17 @@ export const getReturnType = (signatures: (SignatureReflection & { typeParameter throw new Error(`Return Type function not yet implemented for type ${type.type}`) } - let comment: Comment; + // let comment: Comment; + let commentSeen = false; const validReturnTypes = new Set(); let returnType = ''; signatures.forEach(signature => { if (signature.comment) { - if (comment !== undefined) { + if (commentSeen) { throw new Error('Multiple comments defined for return signatures'); } - comment = signature.comment as any; + commentSeen = true; + // comment = signature.comment; } const { type } = signature; if (type === undefined) { diff --git a/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/get-url-from-sources.test.ts b/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/get-url-from-sources.test.ts index 1a9487521..97d765b4e 100644 --- a/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/get-url-from-sources.test.ts +++ b/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/get-url-from-sources.test.ts @@ -1,7 +1,6 @@ import { DeclarationReflection, SourceReference } from "typedoc"; import { DecRef } from "../types.js"; import { getURLFromSources, rewriteURL } from "./get-url-from-sources.js"; -import { REPO_ROOT } from "../constants.js"; describe('rewriteURL', () => { it('rewrites the URL', () => { diff --git a/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/write-api-documentation-files.test.ts b/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/write-api-documentation-files.test.ts index 7afbc9dc2..ca01e040d 100644 --- a/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/write-api-documentation-files.test.ts +++ b/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/write-api-documentation-files.test.ts @@ -42,7 +42,7 @@ describe('writeAPIDocumentationFiles', () => { it('it to throw if no content is returned', async () => { vi.mocked(getContentForMethod).mockReturnValue(''); - expect(() => writeAPIDocumentationFiles('/out', [{ + await expect(() => writeAPIDocumentationFiles('/out', [{ name: 'foo' }, { name: 'bar', diff --git a/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/write-api-documentation-files.ts b/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/write-api-documentation-files.ts index 08f8b5717..c9183e8af 100644 --- a/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/write-api-documentation-files.ts +++ b/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/write-api-documentation-files.ts @@ -3,7 +3,7 @@ import { mkdirp, writeFile } from '@internals/common/fs'; import { getContentForMethod } from './get-content-for-method.js'; import { Definitions } from '../types.js'; import { DeclarationReflection } from 'typedoc'; -import { info, verbose } from '@internals/common/logger'; +import { verbose } from '@internals/common/logger'; export const writeAPIDocumentationFiles = async (dest: string, methods: DeclarationReflection[], definitions: Definitions) => { await Promise.all(methods.map(async (method, i) => { diff --git a/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/write-parameter.ts b/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/write-parameter.ts index 9316c81fd..6bc3732aa 100644 --- a/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/write-parameter.ts +++ b/internals/cli/src/lib/commands/write/docs/api/write-api-documentation-files/write-parameter.ts @@ -1,4 +1,4 @@ -import { DeclarationReflection, ParameterReflection, TypeParameterReflection } from "typedoc"; +import { Comment, DeclarationReflection, ParameterReflection, TypeParameterReflection } from "typedoc"; import { DecRef, Definitions, PlatformSpecificFileDeclarationReflection, isDeclarationReflection, isPlatformSpecificFileDeclarationReflection } from "../types.js"; import { getReferenceTypeOfParameter } from "./get-reference-type-of-parameter.js"; import { getURLFromSources } from "./get-url-from-sources.js"; @@ -6,7 +6,7 @@ import { sortChildrenByLineNumber } from "../sort-children-by-line-number.js"; import { getMatchingType } from "./get-matching-type.js"; import { TYPES_TO_EXPAND } from "../constants.js"; -export const getSummary = (comment?: any) => comment?.summary.map(({ text }: any) => text).join(''); +export const getSummary = (comment?: Comment) => comment?.summary.map(({ text }) => text).join(''); type MatchingType = undefined | DecRef | TypeParameterReflection; type Parameter = ParameterReflection | DeclarationReflection; @@ -39,7 +39,7 @@ const writeParameter = ( }; const writePlatformSpecificParameter = (platform: string, parameter: DeclarationReflection, definitions: Definitions) => { - const comment = getSummary(parameter.comment as any); + const comment = getSummary(parameter.comment); const { type, name } = getReferenceTypeOfParameter(parameter.type, definitions); const url = getURLFromSources(parameter); const parsedName = `${name}${type === 'array' ? '[]' : ''}`; @@ -85,5 +85,6 @@ export const getParameters = ( childParameters, ].filter(Boolean).map(line => Array(depth * 2).fill(' ').join('') + line).join('\n'); } + return undefined; }).filter(Boolean).join('\n'); }; diff --git a/internals/cli/src/lib/rollup-configs/models-rollup-config.ts b/internals/cli/src/lib/rollup-configs/models-rollup-config.ts index 1dca82d31..d3a7def83 100644 --- a/internals/cli/src/lib/rollup-configs/models-rollup-config.ts +++ b/internals/cli/src/lib/rollup-configs/models-rollup-config.ts @@ -15,7 +15,7 @@ export const inputOptions: InputOptions = { /^(?!.*(@tensorflow\/tfjs))/, ], }), - (commonjs as any)(), + (commonjs as any)(), // skipcq: js-0323 ], }; diff --git a/internals/cli/src/lib/rollup-configs/upscalerjs-rollup-config.ts b/internals/cli/src/lib/rollup-configs/upscalerjs-rollup-config.ts index 446a7b885..d000b59ab 100644 --- a/internals/cli/src/lib/rollup-configs/upscalerjs-rollup-config.ts +++ b/internals/cli/src/lib/rollup-configs/upscalerjs-rollup-config.ts @@ -28,7 +28,7 @@ export const inputOptions: InputOptions = { /^(?!.*(@tensorflow\/tfjs-core))/, //skipcq: js-0113 ], }), - (commonjs as any)(), + (commonjs as any)(), // skipcq: js-0323 ], };