Skip to content

Commit

Permalink
[eslint] fix linting issues for several packages (#30826)
Browse files Browse the repository at this point in the history
These would appear once we moved to eslint flat config. They are not
detected
currently likely due to incorrect configurations.

- Remove TextEncoder/TextDecoder declarations as they are in global
scope on our
supported platforms

- Remove URL imports as they are in global scope on our supported
platforms.

- remove --ext from linting NPM scripts

- Fix issues linting README.md files

- Suppress error about crypto. The feature of adding it to global scope
is still experimental

- Fix build error in attestation. Neither browsers nor NodeJS has a
constructor parameter for TextEncoder

-
https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder/TextEncoder

-
https://nodejs.org/docs/latest-v18.x/api/util.html#class-utiltextencoder
  • Loading branch information
jeremymeng authored Aug 21, 2024
1 parent 1294859 commit 6ea3729
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 84 deletions.
21 changes: 2 additions & 19 deletions sdk/attestation/attestation/src/utils/utf8.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

declare let TextDecoder:
| undefined
| (new () => { decode(buffer: ArrayBuffer | ArrayBufferView): string });
declare let TextEncoder: undefined | (new () => { encode(str: string): ArrayBuffer });
const decoder = typeof Buffer === "undefined" ? new TextDecoder("ascii") : undefined;

// TextDecoder and TextEncoder are in the global namespace for Node version 11 and
// higher, but before that, they were in the "util" namespace. If we're running
// under node ("Buffer" is defined), then check to see if the global namespace version
// of the decoders are present, if not, import them from the util namespace.
const decoder =
typeof Buffer === "undefined"
? // eslint-disable-next-line @typescript-eslint/no-require-imports
new (TextDecoder ?? require("util").TextDecoder)("ascii")
: undefined;

const encoder =
typeof Buffer === "undefined"
? // eslint-disable-next-line @typescript-eslint/no-require-imports
new (TextEncoder ?? require("util").TextEncoder)("ascii")
: undefined;
const encoder = typeof Buffer === "undefined" ? new TextEncoder() : undefined;

const decode: (buffer: ArrayBuffer) => string = decoder
? (buffer) => decoder.decode(buffer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { CommonClientOptions } from "@azure/core-client";
import { isDigest, readChunksFromStream, readStreamToEnd } from "../utils/helpers";
import { Readable } from "stream";
import { tracingClient } from "../tracing";
// eslint-disable-next-line @typescript-eslint/no-redeclare
import crypto from "crypto";
import { RetriableReadableStream } from "../utils/retriableReadableStream";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

// eslint-disable-next-line @typescript-eslint/no-redeclare
import crypto from "crypto";

export function calculateDigest(buffer: Buffer): Promise<string>;
Expand Down
11 changes: 0 additions & 11 deletions sdk/contentsafety/ai-content-safety-rest/.eslintrc.json

This file was deleted.

15 changes: 15 additions & 0 deletions sdk/contentsafety/ai-content-safety-rest/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import azsdkEslint from "@azure/eslint-plugin-azure-sdk";

export default [
...azsdkEslint.configs.recommended,
{
rules: {
"@azure/azure-sdk/ts-modules-only-named": "warn",
"@azure/azure-sdk/ts-apiextractor-json-types": "warn",
"@azure/azure-sdk/ts-package-json-types": "warn",
"@azure/azure-sdk/ts-package-json-engine-is-present": "warn",
"@typescript-eslint/no-redeclare": "warn",
"tsdoc/syntax": "warn",
},
},
];
4 changes: 2 additions & 2 deletions sdk/contentsafety/ai-content-safety-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"integration-test:browser": "dev-tool run test:browser",
"integration-test:node": "dev-tool run test:node-js-input -- --timeout 5000000 'dist-esm/test/**/*.spec.js'",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]",
"lint": "eslint package.json api-extractor.json src test --ext .ts",
"lint:fix": "eslint package.json api-extractor.json src test --fix --fix-type [problem,suggestion]",
"lint": "eslint package.json api-extractor.json src test",
"pack": "npm pack 2>&1",
"test:browser": "npm run clean && npm run build:test && npm run unit-test:browser",
"test:node": "npm run clean && npm run build:test && npm run unit-test:node",
Expand Down
10 changes: 0 additions & 10 deletions sdk/keyvault/keyvault-keys/.eslintrc.json

This file was deleted.

13 changes: 13 additions & 0 deletions sdk/keyvault/keyvault-keys/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import azsdkEslint from "@azure/eslint-plugin-azure-sdk";

export default [
...azsdkEslint.configs.recommended,
{
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",
},
},
];
4 changes: 2 additions & 2 deletions sdk/keyvault/keyvault-keys/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
"integration-test:node": "dev-tool run test:node-js-input -- --timeout 5000000 'dist-esm/**/*.spec.js'",
"integration-test:node:no-timeout": "dev-tool run test:node-js-input -- --timeout 9999999 'dist-esm/**/*.spec.js'",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]",
"lint": "eslint package.json api-extractor.json src test --ext .ts",
"lint:fix": "eslint package.json api-extractor.json src test --fix --fix-type [problem,suggestion]",
"lint": "eslint package.json api-extractor.json src test",
"pack": "npm pack 2>&1",
"test:browser": "npm run clean && npm run build:test && npm run unit-test:browser",
"test:node": "npm run clean && npm run build:test && npm run unit-test:node",
Expand Down
8 changes: 4 additions & 4 deletions sdk/metricsadvisor/ai-metrics-advisor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ async function configureAnomalyDetectionConfiguration(adminClient, metricId) {
},
description: "Detection configuration description",
};
return await adminClient.createDetectionConfig(anomalyConfig);
return adminClient.createDetectionConfig(anomalyConfig);
}
```

Expand Down Expand Up @@ -366,7 +366,7 @@ async function createWebhookHook(adminClient) {
},
};

return await adminClient.createHook(hook);
return adminClient.createHook(hook);
}
```

Expand Down Expand Up @@ -418,7 +418,7 @@ async function configureAlertConfiguration(adminClient, detectionConfigId, hookI
hookIds,
description: "Alerting config description",
};
return await adminClient.createAlertConfig(anomalyAlertConfig);
return adminClient.createAlertConfig(anomalyAlertConfig);
}
```

Expand Down Expand Up @@ -455,7 +455,7 @@ async function main() {
}

async function queryAlerts(client, alertConfigId, startTime, endTime) {
let alerts = [];
const alerts = [];
const iterator = client.listAlerts(alertConfigId, startTime, endTime, "AnomalyTime");
for await (const alert of iterator) {
alerts.push(alert);
Expand Down
10 changes: 5 additions & 5 deletions sdk/remoterendering/mixed-reality-remote-rendering/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDoma
Use the `ClientSecretCredential` object to perform client secret authentication.

```typescript Snippet:CreateAClientWithAAD
let credential = new ClientSecretCredential(tenantId, clientId, clientSecret, {
const credential = new ClientSecretCredential(tenantId, clientId, clientSecret, {
authorityHost: "https://login.microsoftonline.com/" + tenantId
});

Expand Down Expand Up @@ -121,7 +121,7 @@ Use the `DefaultAzureCredential` object with `includeInteractiveCredentials: tru
flow:

```typescript Snippet:CreateAClientWithAzureCredential
let credential = new DefaultAzureCredential();
const credential = new DefaultAzureCredential();

return new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, credential, {
authenticationEndpointUrl: "https://sts.mixedreality.azure.com"
Expand Down Expand Up @@ -310,14 +310,14 @@ This example shows how to query the current properties and then extend the lease
```typescript Snippet:UpdateSession
/// When the lease is within 2 minutes of expiring, extend it by 15 minutes.
let currentSession = await client.getSession(sessionId);
if (currentSession.status == "Ready") {
const currentSession = await client.getSession(sessionId);
if (currentSession.status === "Ready") {
if (
currentSession.maxLeaseTimeInMinutes -
(Date.now() - currentSession.properties.createdOn.valueOf()) / 60000 <
2
) {
let newLeaseTime = currentSession.maxLeaseTimeInMinutes + 15;
const newLeaseTime = currentSession.maxLeaseTimeInMinutes + 15;

await client.updateSession(sessionId, { maxLeaseTimeInMinutes: newLeaseTime });
}
Expand Down
14 changes: 0 additions & 14 deletions sdk/search/search-documents/.eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion sdk/search/search-documents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ const searchClient = new SearchClient(
);

async function main() {
const queryVector = [...];
const queryVector = [/*...*/];
const searchResults = await searchClient.search("*", {
vectorSearchOptions: {
queries: [
Expand Down
18 changes: 18 additions & 0 deletions sdk/search/search-documents/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import azsdkEslint from "@azure/eslint-plugin-azure-sdk";

export default [
{
ignores: ["src/shims.d.ts"],
},
...azsdkEslint.configs.recommended,
{
files: ["samples-dev/**/*.ts"],
rules: {
// Suppresses errors for the custom TSDoc syntax we use for docs
"tsdoc/syntax": "off",
// Suppresses spurious missing dependency error as ESLint thinks the sample's runtime deps
// should be runtime deps for us too
"import/no-extraneous-dependencies": "off",
},
},
];
4 changes: 2 additions & 2 deletions sdk/search/search-documents/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"integration-test:browser": "dev-tool run test:browser",
"integration-test:node": "dev-tool run test:node-js-input -- --timeout 5000000 'dist-esm/test/**/*.spec.js'",
"lint": "eslint package.json api-extractor.json src test samples-dev --ext .ts",
"lint:fix": "eslint package.json api-extractor.json src test samples-dev --ext .ts --fix --fix-type [problem,suggestion]",
"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",
"test": "npm run build:test && npm run unit-test",
"test:browser": "npm run build:test && npm run unit-test:browser",
Expand Down
4 changes: 2 additions & 2 deletions sdk/tables/data-tables/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ const serviceClient = new TableServiceClient(
);

async function main() {
let tablesIter = serviceClient.listTables();
const tablesIter = serviceClient.listTables();
let i = 1;
for await (const table of tablesIter) {
console.log(`Table${i}: ${table.name}`);
Expand Down Expand Up @@ -389,7 +389,7 @@ const credential = new AzureNamedKeyCredential(account, accountKey);
const client = new TableClient(`https://${account}.table.core.windows.net`, tableName, credential);

async function main() {
let entitiesIter = client.listEntities();
const entitiesIter = client.listEntities();
let i = 1;
for await (const entity of entitiesIter) {
console.log(`Entity${i}: PartitionKey: ${entity.partitionKey} RowKey: ${entity.rowKey}`);
Expand Down
1 change: 1 addition & 0 deletions sdk/textanalytics/ai-text-analytics/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

- Depends on the latest stable version of the @azure/core-tracing library.
- Duplicate action are no longer eagerly checked by the client before sending a batch request.
- Remove utils/url*.ts as `URL` and `URLSearchParams` are available in global scope on our supported platforms.

## 5.1.0 (2021-07-07)

Expand Down
1 change: 0 additions & 1 deletion sdk/textanalytics/ai-text-analytics/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license.

import { RestError } from "@azure/core-rest-pipeline";
import { URL, URLSearchParams } from "./utils/url";
import { logger } from "./logger";
import {
ErrorResponse,
Expand Down
7 changes: 0 additions & 7 deletions sdk/textanalytics/ai-text-analytics/src/utils/url.browser.ts

This file was deleted.

4 changes: 0 additions & 4 deletions sdk/textanalytics/ai-text-analytics/src/utils/url.ts

This file was deleted.

0 comments on commit 6ea3729

Please sign in to comment.