Skip to content

Commit

Permalink
[keyvault] Precise Typechecking (#32135)
Browse files Browse the repository at this point in the history
  • Loading branch information
deyaaeldeen authored Dec 10, 2024
1 parent 7e8d376 commit 53155a8
Show file tree
Hide file tree
Showing 69 changed files with 286 additions and 170 deletions.
1 change: 1 addition & 0 deletions sdk/appconfiguration/app-configuration/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default mergeConfig(
defineConfig({
test: {
fileParallelism: false,
hookTimeout: 60000,
include: ["test/**/*.spec.ts"],
typecheck: {
enabled: true,
Expand Down
14 changes: 10 additions & 4 deletions sdk/keyvault/keyvault-admin/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import azsdkEslint from "@azure/eslint-plugin-azure-sdk";

export default azsdkEslint.config([
{ ignores: ["src/generated"] },
{
rules: {
"@azure/azure-sdk/ts-package-json-module": "warn",
"@typescript-eslint/no-this-alias": "off",
"no-use-before-define": "warn",
"@typescript-eslint/no-empty-object-type": "warn",
"@azure/azure-sdk/ts-naming-options": "warn"
}
},
{
files: ["**/*.ts", "**/*.cts", "**/*.mts"],
languageOptions: {
parserOptions: {
project: ["./tsconfig.test.json"],
},
},
},
]);
7 changes: 4 additions & 3 deletions sdk/keyvault/keyvault-admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
"generate:client": "autorest --typescript swagger/README.md",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"integration-test:browser": "echo skipped",
"integration-test:node": "dev-tool run vendored cross-env TEST_MODE=live dev-tool run test:vitest --no-test-proxy",
"lint": "eslint package.json api-extractor.json src",
"integration-test:node": "dev-tool run vendored cross-env TEST_MODE=live dev-tool run test:vitest --no-test-proxy --esm",
"lint": "eslint README.md package.json api-extractor.json src test",
"lint:fix": "eslint package.json src --fix --fix-type [problem,suggestion]",
"pack": "npm pack 2>&1",
"test": "npm run build:test && npm run unit-test",
Expand Down Expand Up @@ -129,7 +129,8 @@
"esm",
"commonjs"
],
"selfLink": false
"selfLink": false,
"project": "./tsconfig.src.json"
},
"exports": {
"./package.json": "./package.json",
Expand Down
1 change: 0 additions & 1 deletion sdk/keyvault/keyvault-admin/src/accessControlClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export class KeyVaultAccessControlClient {
constructor(
vaultUrl: string,
credential: TokenCredential,
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
options: AccessControlClientOptions = {},
) {
this.vaultUrl = vaultUrl;
Expand Down
2 changes: 0 additions & 2 deletions sdk/keyvault/keyvault-admin/src/settingsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export class KeyVaultSettingsClient {
* @param options - options used to configure Key Vault API requests.
*/
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
constructor(vaultUrl: string, credential: TokenCredential, options: SettingsClientOptions = {}) {
this.vaultUrl = vaultUrl;

Expand Down Expand Up @@ -130,7 +129,6 @@ export class KeyVaultSettingsClient {
*
* @param options - the optional parameters.
*/
// eslint-disable-next-line @azure/azure-sdk/ts-naming-options
async getSettings(options: ListSettingsOptions = {}): Promise<ListSettingsResponse> {
const { settings } = await this.client.getSettings(this.vaultUrl, options);
return { settings: settings?.map(makeSetting) ?? [] };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import { KeyVaultAccessControlClient, KeyVaultBackupClient } from "../../src/index.js";
import { LATEST_API_VERSION } from "../../src/constants.js";
import {
PipelineRequest,
PipelineResponse,
type PipelineRequest,
type PipelineResponse,
createHttpHeaders,
HttpClient,
SendRequest,
type HttpClient,
type SendRequest,
} from "@azure/core-rest-pipeline";
import { ClientSecretCredential } from "@azure/identity";
import { env } from "@azure-tools/test-recorder";
import { URL } from "url";
import { describe, it, expect, beforeEach, afterEach, vi, MockInstance } from "vitest";
import { describe, it, expect, beforeEach, afterEach, vi, type MockInstance } from "vitest";

// Adding this to the source would change the public API.
type ApiVersions = "7.2" | "7.3";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import { KeyVaultAccessControlClient, SDK_VERSION } from "../../src/index.js";
import { TokenCredential } from "@azure/core-auth";
import type { TokenCredential } from "@azure/core-auth";
import { describe, it, expect } from "vitest";

describe("Key Vault Admin's user agent", function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { assertEnvironmentVariable, Recorder } from "@azure-tools/test-recorder";
import { assertEnvironmentVariable, type Recorder } from "@azure-tools/test-recorder";

import { KeyVaultAccessControlClient } from "../../src/index.js";
import type { KeyVaultAccessControlClient } from "../../src/index.js";
import { authenticate } from "./utils/authentication.js";
import { describe, it, beforeEach, afterEach, expect } from "vitest";
import { AbortError } from "@azure/abort-controller";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { assertEnvironmentVariable, env, Recorder } from "@azure-tools/test-recorder";
import { assertEnvironmentVariable, env, type Recorder } from "@azure-tools/test-recorder";
import { getYieldedValue, toSupportTracing } from "@azure-tools/test-utils-vitest";

import {
KeyVaultAccessControlClient,
KeyVaultPermission,
KeyVaultRoleDefinition,
type KeyVaultAccessControlClient,
type KeyVaultPermission,
type KeyVaultRoleDefinition,
KnownKeyVaultDataAction,
} from "../../src/index.js";
import { authenticate } from "./utils/authentication.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { Recorder } from "@azure-tools/test-recorder";
import type { Recorder } from "@azure-tools/test-recorder";

import { KeyVaultBackupClient } from "../../src/index.js";
import type { KeyVaultBackupClient } from "../../src/index.js";
import { authenticate } from "./utils/authentication.js";
import { testPollerProperties } from "./utils/recorder.js";
import { describe, it, beforeEach, afterEach, expect } from "vitest";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { Recorder } from "@azure-tools/test-recorder";
import { KeyVaultSettingsClient } from "../../src/settingsClient.js";
import type { Recorder } from "@azure-tools/test-recorder";
import type { KeyVaultSettingsClient } from "../../src/settingsClient.js";
import { authenticate } from "./utils/authentication.js";
import { describe, it, beforeEach, afterEach, expect } from "vitest";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
// Licensed under the MIT License.

import { createTestCredential } from "@azure-tools/test-credential";
import { env, Recorder, RecorderStartOptions, TestInfo } from "@azure-tools/test-recorder";
import {
env,
Recorder,
type RecorderStartOptions,
type TestInfo,
} from "@azure-tools/test-recorder";
import { KeyClient } from "@azure/keyvault-keys";
import {
KeyVaultAccessControlClient,
Expand Down
3 changes: 3 additions & 0 deletions sdk/keyvault/keyvault-admin/tsconfig.browser.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["./tsconfig.test.json", "../../../tsconfig.browser.base.json"]
}
23 changes: 6 additions & 17 deletions sdk/keyvault/keyvault-admin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
{
"extends": "../../../tsconfig",
"compilerOptions": {
"lib": ["dom"],
"resolveJsonModule": true,
"paths": {
"@azure/keyvault-admin": ["./src/index.js"]
},
"module": "NodeNext",
"moduleResolution": "NodeNext",
"rootDir": "."
},
"include": [
"./src/**/*.ts",
"./src/**/*.mts",
"./src/**/*.cts",
"./samples-dev/**/*.ts",
"./test/**/*.ts"
]
"references": [
{ "path": "./tsconfig.src.json" },
{ "path": "./tsconfig.samples.json" },
{ "path": "./tsconfig.test.json" }
],
"files": []
}
8 changes: 8 additions & 0 deletions sdk/keyvault/keyvault-admin/tsconfig.samples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../../tsconfig.samples.base.json",
"compilerOptions": {
"paths": {
"@azure/keyvault-admin": ["./dist/esm"]
}
}
}
3 changes: 3 additions & 0 deletions sdk/keyvault/keyvault-admin/tsconfig.src.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.lib.json"
}
3 changes: 3 additions & 0 deletions sdk/keyvault/keyvault-admin/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["./tsconfig.src.json", "../../../tsconfig.test.base.json"]
}
5 changes: 5 additions & 0 deletions sdk/keyvault/keyvault-admin/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export default mergeConfig(
defineConfig({
test: {
include: ["test/**/*.spec.ts"],
typecheck: {
enabled: true,
tsconfig: "tsconfig.test.json",
include: ["test/**/*.ts", "test/**/*.mts", "test/**/*.cts"],
},
},
}),
);
11 changes: 11 additions & 0 deletions sdk/keyvault/keyvault-admin/vitest.esm.config.ts
Original file line number Diff line number Diff line change
@@ -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
);
10 changes: 5 additions & 5 deletions sdk/keyvault/keyvault-certificates/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import azsdkEslint from "@azure/eslint-plugin-azure-sdk";

export default azsdkEslint.config([
{
rules: {
"@typescript-eslint/no-this-alias": "off",
"@azure/azure-sdk/ts-package-json-module": "warn",
"@typescript-eslint/no-redeclare": "warn",
"no-use-before-define": "warn",
files: ["**/*.ts", "**/*.cts", "**/*.mts"],
languageOptions: {
parserOptions: {
project: ["./tsconfig.test.json"],
},
},
},
]);
5 changes: 3 additions & 2 deletions sdk/keyvault/keyvault-certificates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"generate:client": "autorest --typescript swagger/README.md",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"integration-test:browser": "echo skipped",
"integration-test:node": "dev-tool run test:vitest --no-test-proxy -- --test-timeout 350000",
"integration-test:node": "dev-tool run test:vitest --no-test-proxy --esm -- --test-timeout 350000",
"lint": "eslint package.json api-extractor.json src test",
"lint:fix": "eslint package.json api-extractor.json src test --fix --fix-type [problem,suggestion]",
"pack": "npm pack 2>&1",
Expand Down Expand Up @@ -137,7 +137,8 @@
"browser",
"react-native"
],
"selfLink": false
"selfLink": false,
"project": "./tsconfig.src.json"
},
"exports": {
"./package.json": "./package.json",
Expand Down
1 change: 0 additions & 1 deletion sdk/keyvault/keyvault-certificates/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ export {
/**
* Deprecated KeyVault copy of core-lro's PollerLike.
*/
// eslint-disable-next-line no-use-before-define
export type KVPollerLike<TState extends PollOperationState<TResult>, TResult> = PollerLike<
TState,
TResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export interface KeyVaultCertificatePollOperationState<TResult>
/**
* Generates a version of the state with only public properties. At least those common for all of the Key Vault Certificates pollers.
*/
// eslint-disable-next-line no-use-before-define
export function cleanState<TState extends KeyVaultCertificatePollOperationState<TResult>, TResult>(
state: TState,
): KeyVaultCertificatePollOperationState<TResult> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ async function cancel(this: RestoreCertificateBackupPollOperation): Promise<neve
/**
* Serializes the create certificate's poll operation
*/
// eslint-disable-next-line @typescript-eslint/no-redeclare
function toString(this: RestoreCertificateBackupPollOperation): string {
return JSON.stringify({
state: this.state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export default class TestClient {
await this.client.purgeDeletedCertificate(certificateName);
}
public async flushCertificate(certificateName: string): Promise<void> {
const that = this;
const poller = await that.client.beginDeleteCertificate(certificateName, testPollerProperties);
const poller = await this.client.beginDeleteCertificate(certificateName, testPollerProperties);
await poller.pollUntilDone();
await this.purgeCertificate(certificateName);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["./tsconfig.test.json", "../../../tsconfig.browser.base.json"]
}
23 changes: 6 additions & 17 deletions sdk/keyvault/keyvault-certificates/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
{
"extends": "../../../tsconfig",
"compilerOptions": {
"lib": ["dom"],
"resolveJsonModule": true,
"paths": {
"@azure/keyvault-certificates": ["./src/index"]
},
"module": "NodeNext",
"moduleResolution": "NodeNext",
"rootDir": "."
},
"include": [
"./src/**/*.ts",
"./src/**/*.mts",
"./src/**/*.cts",
"./samples-dev/**/*.ts",
"./test/**/*.ts"
]
"references": [
{ "path": "./tsconfig.src.json" },
{ "path": "./tsconfig.samples.json" },
{ "path": "./tsconfig.test.json" }
],
"files": []
}
8 changes: 8 additions & 0 deletions sdk/keyvault/keyvault-certificates/tsconfig.samples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../../tsconfig.samples.base.json",
"compilerOptions": {
"paths": {
"@azure/keyvault-certificates": ["./dist/esm"]
}
}
}
3 changes: 3 additions & 0 deletions sdk/keyvault/keyvault-certificates/tsconfig.src.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.lib.json"
}
3 changes: 3 additions & 0 deletions sdk/keyvault/keyvault-certificates/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["./tsconfig.src.json", "../../../tsconfig.test.base.json"]
}
5 changes: 5 additions & 0 deletions sdk/keyvault/keyvault-certificates/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export default mergeConfig(
defineConfig({
test: {
include: ["test/**/*.spec.ts"],
typecheck: {
enabled: true,
tsconfig: "tsconfig.test.json",
include: ["test/**/*.ts", "test/**/*.mts", "test/**/*.cts"],
},
},
}),
);
11 changes: 11 additions & 0 deletions sdk/keyvault/keyvault-certificates/vitest.esm.config.ts
Original file line number Diff line number Diff line change
@@ -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
);
Loading

0 comments on commit 53155a8

Please sign in to comment.