From 2e4f955af460ec7244923f02e02bc2699cf388c2 Mon Sep 17 00:00:00 2001 From: Deyaaeldeen Almahallawi Date: Wed, 11 Dec 2024 21:16:34 -0800 Subject: [PATCH] [search] Precise Typechecking (#32160) ### Packages impacted by this PR - @azure/search-documents ### Issues associated with this PR N/A ### Describe the problem that is addressed by this PR Tests are not being typechecked and linting isn't configured correctly. This PR migrates those libraries to precise typechecking setup introduced in https://github.com/Azure/azure-sdk-for-js/pull/31786 ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ N/A ### Provide a list of related PRs _(if any)_ https://github.com/Azure/azure-sdk-for-js/pull/31786 ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [x] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary) --- sdk/search/search-documents/eslint.config.mjs | 13 ++++------ sdk/search/search-documents/package.json | 5 ++-- .../search-documents/samples-dev/setup.ts | 1 - .../search-documents/src/serviceModels.ts | 2 -- .../search-documents/src/serviceUtils.ts | 2 +- .../search-documents/test/narrowedTypes.ts | 2 -- .../test/public/node/searchClient.spec.ts | 6 ++--- .../test/public/typeDefinitions.ts | 2 -- .../test/public/utils/setup.ts | 6 ----- .../tsconfig.browser.config.json | 8 +++---- sdk/search/search-documents/tsconfig.json | 24 +++++-------------- .../search-documents/tsconfig.samples.json | 14 +++++++++++ sdk/search/search-documents/tsconfig.src.json | 3 +++ .../search-documents/tsconfig.test.json | 9 +++++++ sdk/search/search-documents/vitest.config.ts | 5 ++++ .../search-documents/vitest.esm.config.ts | 11 +++++++++ 16 files changed, 63 insertions(+), 50 deletions(-) create mode 100644 sdk/search/search-documents/tsconfig.samples.json create mode 100644 sdk/search/search-documents/tsconfig.src.json create mode 100644 sdk/search/search-documents/tsconfig.test.json create mode 100644 sdk/search/search-documents/vitest.esm.config.ts diff --git a/sdk/search/search-documents/eslint.config.mjs b/sdk/search/search-documents/eslint.config.mjs index 4254a8e285d0..197f0c237a9d 100644 --- a/sdk/search/search-documents/eslint.config.mjs +++ b/sdk/search/search-documents/eslint.config.mjs @@ -2,14 +2,11 @@ import azsdkEslint from "@azure/eslint-plugin-azure-sdk"; export default azsdkEslint.config([ { - ignores: ["src/shims.d.ts"], - }, - { - files: ["samples-dev/**/*.ts"], - rules: { - "@azure/azure-sdk/ts-naming-options": "warn", - // Suppresses errors for the custom TSDoc syntax we use for docs - "tsdoc/syntax": "off", + files: ["**/*.ts", "**/*.cts", "**/*.mts"], + languageOptions: { + parserOptions: { + project: ["./tsconfig.test.json", "./tsconfig.samples.json"], + }, }, }, ]); diff --git a/sdk/search/search-documents/package.json b/sdk/search/search-documents/package.json index 37e390b2d670..f3226e218afd 100644 --- a/sdk/search/search-documents/package.json +++ b/sdk/search/search-documents/package.json @@ -21,7 +21,7 @@ "generate:embeddings": "ts-node scripts/generateSampleEmbeddings.ts", "integration-test": "npm run integration-test:node && npm run integration-test:browser", "integration-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser", - "integration-test:node": "dev-tool run test:vitest", + "integration-test:node": "dev-tool run test:vitest --esm", "lint": "eslint package.json api-extractor.json src test samples-dev", "lint:fix": "eslint package.json api-extractor.json src test samples-dev --fix --fix-type [problem,suggestion]", "pack": "npm pack 2>&1", @@ -133,7 +133,8 @@ "browser", "react-native" ], - "selfLink": false + "selfLink": false, + "project": "./tsconfig.src.json" }, "exports": { "./package.json": "./package.json", diff --git a/sdk/search/search-documents/samples-dev/setup.ts b/sdk/search/search-documents/samples-dev/setup.ts index e08846b1732f..8a80b0904e5d 100644 --- a/sdk/search/search-documents/samples-dev/setup.ts +++ b/sdk/search/search-documents/samples-dev/setup.ts @@ -27,7 +27,6 @@ export function delay(timeInMs: number): Promise { return new Promise((resolve) => setTimeout(resolve, timeInMs)); } -// eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters export async function createIndex(client: SearchIndexClient, name: string): Promise { const hotelIndex: SearchIndex = { name, diff --git a/sdk/search/search-documents/src/serviceModels.ts b/sdk/search/search-documents/src/serviceModels.ts index ec50bfc58649..120dc03bc027 100644 --- a/sdk/search/search-documents/src/serviceModels.ts +++ b/sdk/search/search-documents/src/serviceModels.ts @@ -1443,12 +1443,10 @@ export enum KnownTokenizerNames { /** * Divides text using language-specific rules. */ - // eslint-disable-next-line @typescript-eslint/no-shadow MicrosoftLanguageTokenizer = "microsoft_language_tokenizer", /** * Divides text using language-specific rules and reduces words to their base forms. */ - // eslint-disable-next-line @typescript-eslint/no-shadow MicrosoftLanguageStemmingTokenizer = "microsoft_language_stemming_tokenizer", /** * Tokenizes the input into n-grams of the given size(s). See diff --git a/sdk/search/search-documents/src/serviceUtils.ts b/sdk/search/search-documents/src/serviceUtils.ts index d81e73ba6576..0c71e1fb177d 100644 --- a/sdk/search/search-documents/src/serviceUtils.ts +++ b/sdk/search/search-documents/src/serviceUtils.ts @@ -555,7 +555,7 @@ export function generatedVectorSearchVectorizerToPublicVectorizer( return vectorizer; }, }; - const defaultDeserializer = () => { + const defaultDeserializer = (): any => { logger.warning(`Unsupported vectorizer kind: ${(generatedVectorizer as any).kind}`); return generatedVectorizer as any; }; diff --git a/sdk/search/search-documents/test/narrowedTypes.ts b/sdk/search/search-documents/test/narrowedTypes.ts index b0718e2bffe9..dc7bde20c216 100644 --- a/sdk/search/search-documents/test/narrowedTypes.ts +++ b/sdk/search/search-documents/test/narrowedTypes.ts @@ -2,10 +2,8 @@ // Licensed under the MIT License. /* eslint-disable no-unused-expressions */ -/* eslint-disable no-constant-condition */ /* eslint-disable @typescript-eslint/ban-ts-comment */ /* eslint-disable @typescript-eslint/explicit-function-return-type */ -/* eslint-disable @typescript-eslint/no-unused-vars */ import type { SelectFields } from "../src/index.js"; import { SearchClient } from "../src/index.js"; diff --git a/sdk/search/search-documents/test/public/node/searchClient.spec.ts b/sdk/search/search-documents/test/public/node/searchClient.spec.ts index 37bdedb8a171..718ab5cb247a 100644 --- a/sdk/search/search-documents/test/public/node/searchClient.spec.ts +++ b/sdk/search/search-documents/test/public/node/searchClient.spec.ts @@ -529,7 +529,7 @@ describe("SearchClient", { timeout: 20_000 }, () => { assert.deepEqual(["1"], resultIds); }); - it("search with vector", async () => { + it("search with vector", async (ctx) => { // This live test is disabled due to temporary limitations with the new OpenAI service if (isLiveMode()) { ctx.skip(); @@ -563,7 +563,7 @@ describe("SearchClient", { timeout: 20_000 }, () => { assert.deepEqual(resultIds, ["1", "3", "4"]); }); - it("multi-vector search", async () => { + it("multi-vector search", async (ctx) => { // This live test is disabled due to temporary limitations with the new OpenAI service if (isLiveMode()) { ctx.skip(); @@ -603,7 +603,7 @@ describe("SearchClient", { timeout: 20_000 }, () => { assert.deepEqual(resultIds, ["1", "3", "4"]); }); - it("oversampling compressed vectors", async () => { + it("oversampling compressed vectors", async (ctx) => { // This live test is disabled due to temporary limitations with the new OpenAI service if (isLiveMode()) { ctx.skip(); diff --git a/sdk/search/search-documents/test/public/typeDefinitions.ts b/sdk/search/search-documents/test/public/typeDefinitions.ts index 9a341a64851e..7bb7816d0255 100644 --- a/sdk/search/search-documents/test/public/typeDefinitions.ts +++ b/sdk/search/search-documents/test/public/typeDefinitions.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -/* eslint-disable @typescript-eslint/no-unused-vars */ - import type { KnownSemanticErrorMode, KnownSemanticErrorReason, diff --git a/sdk/search/search-documents/test/public/utils/setup.ts b/sdk/search/search-documents/test/public/utils/setup.ts index 584d20caeb2e..fbe9553aa5ee 100644 --- a/sdk/search/search-documents/test/public/utils/setup.ts +++ b/sdk/search/search-documents/test/public/utils/setup.ts @@ -21,7 +21,6 @@ import { assert } from "vitest"; export const WAIT_TIME = isPlaybackMode() ? 0 : 4000; -// eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters export async function createIndex( client: SearchIndexClient, name: string, @@ -344,7 +343,6 @@ export async function createIndex( return client.createIndex(hotelIndex); } -// eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters export async function populateIndex( client: SearchClient, openAIClient: OpenAIClient, @@ -585,14 +583,12 @@ async function addVectorDescriptions( }); } -// eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters export async function deleteDataSourceConnections(client: SearchIndexerClient): Promise { for (let i = 1; i <= 2; i++) { await client.deleteDataSourceConnection(`my-data-source-${i}`); } } -// eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters export async function createSkillsets(client: SearchIndexerClient): Promise { const testCaseNames: string[] = ["my-azureblob-skillset-1", "my-azureblob-skillset-2"]; const skillSetNames: string[] = await client.listSkillsetsNames(); @@ -644,14 +640,12 @@ export async function createSkillsets(client: SearchIndexerClient): Promise { for (let i = 1; i <= 2; i++) { await client.deleteSkillset(`my-azureblob-skillset-${i}`); } } -// eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters export async function createIndexers( client: SearchIndexerClient, targetIndexName: string, diff --git a/sdk/search/search-documents/tsconfig.browser.config.json b/sdk/search/search-documents/tsconfig.browser.config.json index f772e6eb3b76..3d7eb005c032 100644 --- a/sdk/search/search-documents/tsconfig.browser.config.json +++ b/sdk/search/search-documents/tsconfig.browser.config.json @@ -1,10 +1,8 @@ { - "extends": "./.tshy/build.json", - "include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.spec.ts", "./test/**/*.mts"], - "exclude": ["./test/**/node/**/*.ts"], + "extends": ["./tsconfig.test.json"], + "exclude": ["./test/**/node", "./test/stress", "./test/snippets.spec.ts"], "compilerOptions": { "outDir": "./dist-test/browser", - "rootDir": ".", - "skipLibCheck": true + "noEmit": false } } diff --git a/sdk/search/search-documents/tsconfig.json b/sdk/search/search-documents/tsconfig.json index dc4a35f6696d..b186a5a177d8 100644 --- a/sdk/search/search-documents/tsconfig.json +++ b/sdk/search/search-documents/tsconfig.json @@ -1,21 +1,9 @@ { "extends": "../../../tsconfig", - "compilerOptions": { - "paths": { - "@azure/search-documents": ["./src/index"] - }, - "skipLibCheck": true, - "module": "NodeNext", - "moduleResolution": "NodeNext", - "rootDir": "." - }, - "include": [ - "src/**/*.ts", - "src/**/*.mts", - "src/**/*.cts", - "samples-dev/**/*.ts", - "test/**/*.ts", - "test/**/*.mts", - "test/**/*.cts" - ] + "references": [ + { "path": "./tsconfig.src.json" }, + { "path": "./tsconfig.samples.json" }, + { "path": "./tsconfig.test.json" } + ], + "files": [] } diff --git a/sdk/search/search-documents/tsconfig.samples.json b/sdk/search/search-documents/tsconfig.samples.json new file mode 100644 index 000000000000..9e2fa97da615 --- /dev/null +++ b/sdk/search/search-documents/tsconfig.samples.json @@ -0,0 +1,14 @@ +{ + "extends": "../../../tsconfig", + "compilerOptions": { + "paths": { + "@azure/openai": ["./dist/esm"] + }, + "target": "ES2022", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "noEmit": true, + "composite": true + }, + "include": ["./samples-dev"] +} diff --git a/sdk/search/search-documents/tsconfig.src.json b/sdk/search/search-documents/tsconfig.src.json new file mode 100644 index 000000000000..bae70752dd38 --- /dev/null +++ b/sdk/search/search-documents/tsconfig.src.json @@ -0,0 +1,3 @@ +{ + "extends": "../../../tsconfig.lib.json" +} diff --git a/sdk/search/search-documents/tsconfig.test.json b/sdk/search/search-documents/tsconfig.test.json new file mode 100644 index 000000000000..48db94673987 --- /dev/null +++ b/sdk/search/search-documents/tsconfig.test.json @@ -0,0 +1,9 @@ +{ + "extends": ["./tsconfig.src.json"], + "compilerOptions": { + "skipLibCheck": true, + "target": "ES2022", + "noEmit": true + }, + "include": ["./test", "./src"] +} diff --git a/sdk/search/search-documents/vitest.config.ts b/sdk/search/search-documents/vitest.config.ts index d01fdec8ac69..3e9caaad8e0c 100644 --- a/sdk/search/search-documents/vitest.config.ts +++ b/sdk/search/search-documents/vitest.config.ts @@ -11,6 +11,11 @@ export default mergeConfig( include: ["test/**/*.spec.ts"], hookTimeout: 5000000, testTimeout: 5000000, + typecheck: { + enabled: true, + tsconfig: "tsconfig.test.json", + include: ["test/**/*.ts", "test/**/*.mts", "test/**/*.cts"], + }, }, }), ); diff --git a/sdk/search/search-documents/vitest.esm.config.ts b/sdk/search/search-documents/vitest.esm.config.ts new file mode 100644 index 000000000000..2f6e757a54f7 --- /dev/null +++ b/sdk/search/search-documents/vitest.esm.config.ts @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { mergeConfig } from "vitest/config"; +import vitestConfig from "./vitest.config.ts"; +import vitestEsmConfig from "../../../vitest.esm.shared.config.ts"; + +export default mergeConfig( + vitestConfig, + vitestEsmConfig +);