From 65e171e8fbedc216016c14b7747e06a153d0e86f Mon Sep 17 00:00:00 2001 From: bbrusniak <56491690+bbrusniak@users.noreply.github.com> Date: Mon, 22 Nov 2021 10:52:24 -0800 Subject: [PATCH] [eslint-plugin-azure-sdk] Replaced redundant custom rule ts-no-namespaces with typescript-eslint/no-namespace (#18676) * Removed ts-no-namespaces and replaced with typescript-eslint/no-namespace * Fixed README.md Co-authored-by: bbrusniak --- .../tools/eslint-plugin-azure-sdk/README.md | 1 - .../docs/rules/ts-no-namespaces.md | 21 -------- .../src/configs/azure-sdk-base.ts | 2 +- .../src/configs/index.ts | 1 - .../src/rules/index.ts | 2 - .../src/rules/ts-no-namespaces.ts | 30 ------------ .../tests/rules/ts-no-namespaces.ts | 48 ------------------- .../attestation/src/jsrsasign.d.ts | 2 +- .../src/utils/base64.browser.ts | 2 +- sdk/core/core-client/src/base64.browser.ts | 2 +- .../core-http/src/httpOperationResponse.ts | 2 +- .../core-lro/test/utils/router/paramRoutes.ts | 6 +-- .../event-hubs/src/connectionContext.ts | 2 +- .../node/interactiveBrowserCredential.spec.ts | 2 +- 14 files changed, 10 insertions(+), 113 deletions(-) delete mode 100644 common/tools/eslint-plugin-azure-sdk/docs/rules/ts-no-namespaces.md delete mode 100644 common/tools/eslint-plugin-azure-sdk/src/rules/ts-no-namespaces.ts delete mode 100644 common/tools/eslint-plugin-azure-sdk/tests/rules/ts-no-namespaces.ts diff --git a/common/tools/eslint-plugin-azure-sdk/README.md b/common/tools/eslint-plugin-azure-sdk/README.md index 997d564d3d6c..bcec2d711e68 100644 --- a/common/tools/eslint-plugin-azure-sdk/README.md +++ b/common/tools/eslint-plugin-azure-sdk/README.md @@ -113,7 +113,6 @@ Some rules (see table below) are fixable using the `--fix` ESLint option (added | [**ts-naming-subclients**](https://github.com/Azure/azure-sdk-for-js/blob/main/common/tools/eslint-plugin-azure-sdk/docs/rules/ts-naming-subclients.md) | :triangular_flag_on_post: | :x: | `1.2.0` | | [**ts-no-const-enums**](https://github.com/Azure/azure-sdk-for-js/blob/main/common/tools/eslint-plugin-azure-sdk/docs/rules/ts-no-const-enums.md) | :warning: | :heavy_check_mark: | `1.1.0` | | [**ts-no-window**](https://github.com/Azure/azure-sdk-for-js/blob/main/common/tools/eslint-plugin-azure-sdk/docs/rules/ts-no-window.md) | :triangular_flag_on_post: | :heavy_check_mark: | `3.1.0` | -| [**ts-no-namespaces**](https://github.com/Azure/azure-sdk-for-js/blob/main/common/tools/eslint-plugin-azure-sdk/docs/rules/ts-no-namespaces.md) | :triangular_flag_on_post: | :x: | `1.2.0` | | [**ts-package-json-author**](https://github.com/Azure/azure-sdk-for-js/blob/main/common/tools/eslint-plugin-azure-sdk/docs/rules/ts-package-json-author.md) | :triangular_flag_on_post: | :heavy_check_mark: | `1.0.0` | | [**ts-package-json-bugs**](https://github.com/Azure/azure-sdk-for-js/blob/main/common/tools/eslint-plugin-azure-sdk/docs/rules/ts-package-json-bugs.md) | :triangular_flag_on_post: | :heavy_check_mark: | `1.0.0` | | [**ts-package-json-engine-is-present**](https://github.com/Azure/azure-sdk-for-js/blob/main/common/tools/eslint-plugin-azure-sdk/docs/rules/ts-package-json-engine-is-present.md) | :triangular_flag_on_post: | :heavy_check_mark: | `1.1.0` | diff --git a/common/tools/eslint-plugin-azure-sdk/docs/rules/ts-no-namespaces.md b/common/tools/eslint-plugin-azure-sdk/docs/rules/ts-no-namespaces.md deleted file mode 100644 index 682da4debfdb..000000000000 --- a/common/tools/eslint-plugin-azure-sdk/docs/rules/ts-no-namespaces.md +++ /dev/null @@ -1,21 +0,0 @@ -# ts-no-namespaces - -Forbids the usage of TypeScript namespaces. - -## Examples - -### Bad - -```ts -namespace Example {} -``` - -```ts -module Example {} -``` - -## When to turn off - -Only if the rule breaks. - -## [Source](https://azure.github.io/azure-sdk/typescript_design.html#ts-no-namespaces) diff --git a/common/tools/eslint-plugin-azure-sdk/src/configs/azure-sdk-base.ts b/common/tools/eslint-plugin-azure-sdk/src/configs/azure-sdk-base.ts index 04e0253a360b..a742e20d0eeb 100644 --- a/common/tools/eslint-plugin-azure-sdk/src/configs/azure-sdk-base.ts +++ b/common/tools/eslint-plugin-azure-sdk/src/configs/azure-sdk-base.ts @@ -88,7 +88,7 @@ export default { "@typescript-eslint/no-inferrable-types": "off", // We use empty extends and empty interface for shimming and renaming extensively "@typescript-eslint/no-empty-interface": "off", - "@typescript-eslint/no-namespace": "off", + "@typescript-eslint/no-namespace": "error", "@typescript-eslint/no-non-null-assertion": "off", "@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }], "@typescript-eslint/no-useless-constructor": "error", diff --git a/common/tools/eslint-plugin-azure-sdk/src/configs/index.ts b/common/tools/eslint-plugin-azure-sdk/src/configs/index.ts index 277f9ed0ad8e..aa70dcea7b73 100644 --- a/common/tools/eslint-plugin-azure-sdk/src/configs/index.ts +++ b/common/tools/eslint-plugin-azure-sdk/src/configs/index.ts @@ -47,7 +47,6 @@ export = { "@azure/azure-sdk/ts-naming-options": "error", "@azure/azure-sdk/ts-naming-subclients": "error", "@azure/azure-sdk/ts-no-const-enums": "warn", - "@azure/azure-sdk/ts-no-namespaces": "error", "@azure/azure-sdk/ts-no-window": "error", "@azure/azure-sdk/ts-package-json-author": "error", "@azure/azure-sdk/ts-package-json-bugs": "error", diff --git a/common/tools/eslint-plugin-azure-sdk/src/rules/index.ts b/common/tools/eslint-plugin-azure-sdk/src/rules/index.ts index e27a8b4ca41c..53f50d6d66f4 100644 --- a/common/tools/eslint-plugin-azure-sdk/src/rules/index.ts +++ b/common/tools/eslint-plugin-azure-sdk/src/rules/index.ts @@ -31,7 +31,6 @@ import tsNamingDropNoun from "./ts-naming-drop-noun"; import tsNamingOptions from "./ts-naming-options"; import tsNamingSubclients from "./ts-naming-subclients"; import tsNoConstEnums from "./ts-no-const-enums"; -import tsNoNamespaces from "./ts-no-namespaces"; import tsNoWindow from "./ts-no-window"; import tsPackageJsonAuthor from "./ts-package-json-author"; import tsPackageJsonBugs from "./ts-package-json-bugs"; @@ -82,7 +81,6 @@ export = { "ts-naming-options": tsNamingOptions, "ts-naming-subclients": tsNamingSubclients, "ts-no-const-enums": tsNoConstEnums, - "ts-no-namespaces": tsNoNamespaces, "ts-no-window": tsNoWindow, "ts-package-json-author": tsPackageJsonAuthor, "ts-package-json-bugs": tsPackageJsonBugs, diff --git a/common/tools/eslint-plugin-azure-sdk/src/rules/ts-no-namespaces.ts b/common/tools/eslint-plugin-azure-sdk/src/rules/ts-no-namespaces.ts deleted file mode 100644 index ff25e8baeadd..000000000000 --- a/common/tools/eslint-plugin-azure-sdk/src/rules/ts-no-namespaces.ts +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -/** - * @file Rule to forbid usage of TypeScript namespaces. - * @author Arpan Laha - */ - -import { Rule } from "eslint"; -import { getRuleMetaData } from "../utils"; - -//------------------------------------------------------------------------------ -// Rule Definition -//------------------------------------------------------------------------------ - -export = { - meta: getRuleMetaData("ts-no-namespaces", "forbid usage of TypeScript namespaces"), - create: (context: Rule.RuleContext): Rule.RuleListener => - ({ - // callback functions - - // report on any TSModuleDeclarations - TSModuleDeclaration: (node: any): void => { - context.report({ - node: node, - message: "TypeScript namespaces should not be used" - }); - } - } as Rule.RuleListener) -}; diff --git a/common/tools/eslint-plugin-azure-sdk/tests/rules/ts-no-namespaces.ts b/common/tools/eslint-plugin-azure-sdk/tests/rules/ts-no-namespaces.ts deleted file mode 100644 index 3e3f3b79b6ec..000000000000 --- a/common/tools/eslint-plugin-azure-sdk/tests/rules/ts-no-namespaces.ts +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -/** - * @file Testing the ts-no-namespaces rule. - * @author Arpan Laha - */ - -import rule from "../../src/rules/ts-no-namespaces"; -import { RuleTester } from "eslint"; - -//------------------------------------------------------------------------------ -// Tests -//------------------------------------------------------------------------------ - -const ruleTester = new RuleTester({ - parser: require.resolve("@typescript-eslint/parser"), - parserOptions: { - createDefaultProgram: true, - project: "./tsconfig.json", - sourceType: "module" - }, - settings: { - main: "test.ts" - } -}); - -ruleTester.run("ts-no-namespaces", rule, { - valid: [], - invalid: [ - { - code: "namespace Test {}", - errors: [ - { - message: "TypeScript namespaces should not be used" - } - ] - }, - { - code: "module Test {}", - errors: [ - { - message: "TypeScript namespaces should not be used" - } - ] - } - ] -}); diff --git a/sdk/attestation/attestation/src/jsrsasign.d.ts b/sdk/attestation/attestation/src/jsrsasign.d.ts index efe75f3bf5e8..0dbc24387264 100644 --- a/sdk/attestation/attestation/src/jsrsasign.d.ts +++ b/sdk/attestation/attestation/src/jsrsasign.d.ts @@ -1,5 +1,5 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// eslint-disable-next-line @azure/azure-sdk/ts-no-namespaces +// eslint-disable-next-line @typescript-eslint/no-namespace declare module 'jsrsasign'; diff --git a/sdk/containerregistry/container-registry/src/utils/base64.browser.ts b/sdk/containerregistry/container-registry/src/utils/base64.browser.ts index 20b910118e2c..fe0bb1ecad53 100644 --- a/sdk/containerregistry/container-registry/src/utils/base64.browser.ts +++ b/sdk/containerregistry/container-registry/src/utils/base64.browser.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// eslint-disable-next-line @azure/azure-sdk/ts-no-namespaces +// eslint-disable-next-line @typescript-eslint/no-namespace declare global { function atob(input: string): string; } diff --git a/sdk/core/core-client/src/base64.browser.ts b/sdk/core/core-client/src/base64.browser.ts index 70f0fdb02292..8185bd2f8f03 100644 --- a/sdk/core/core-client/src/base64.browser.ts +++ b/sdk/core/core-client/src/base64.browser.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// eslint-disable-next-line @azure/azure-sdk/ts-no-namespaces +// eslint-disable-next-line @typescript-eslint/no-namespace declare global { // stub these out for the browser function btoa(input: string): string; diff --git a/sdk/core/core-http/src/httpOperationResponse.ts b/sdk/core/core-http/src/httpOperationResponse.ts index 8e59db5f3d6e..56546cd09470 100644 --- a/sdk/core/core-http/src/httpOperationResponse.ts +++ b/sdk/core/core-http/src/httpOperationResponse.ts @@ -24,7 +24,7 @@ export interface HttpResponse { headers: HttpHeadersLike; } -// eslint-disable-next-line @azure/azure-sdk/ts-no-namespaces +// eslint-disable-next-line @typescript-eslint/no-namespace declare global { /** * Stub declaration of the browser-only Blob type. diff --git a/sdk/core/core-lro/test/utils/router/paramRoutes.ts b/sdk/core/core-lro/test/utils/router/paramRoutes.ts index cc0bc6406538..c0905f198e2e 100644 --- a/sdk/core/core-lro/test/utils/router/paramRoutes.ts +++ b/sdk/core/core-lro/test/utils/router/paramRoutes.ts @@ -224,7 +224,7 @@ function deleteasyncRetry(request: PipelineRequest): PipelineResponse | undefine return undefined; } -// eslint-disable-next-line @azure/azure-sdk/ts-no-namespaces +// eslint-disable-next-line @typescript-eslint/no-namespace namespace deleteasyncRetry { export let internalCounter: number = 1; // eslint-disable-line prefer-const } @@ -293,7 +293,7 @@ function putasyncRetry(request: PipelineRequest): PipelineResponse | undefined { return undefined; } -// eslint-disable-next-line @azure/azure-sdk/ts-no-namespaces +// eslint-disable-next-line @typescript-eslint/no-namespace namespace putasyncRetry { export let internalCounter: number = 1; // eslint-disable-line prefer-const } @@ -369,7 +369,7 @@ function postasyncRetry(request: PipelineRequest): PipelineResponse | undefined return undefined; } -// eslint-disable-next-line @azure/azure-sdk/ts-no-namespaces +// eslint-disable-next-line @typescript-eslint/no-namespace namespace postasyncRetry { export let internalCounter: number = 1; // eslint-disable-line prefer-const } diff --git a/sdk/eventhub/event-hubs/src/connectionContext.ts b/sdk/eventhub/event-hubs/src/connectionContext.ts index dfeae5920112..e03a67b686bc 100644 --- a/sdk/eventhub/event-hubs/src/connectionContext.ts +++ b/sdk/eventhub/event-hubs/src/connectionContext.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -/* eslint-disable @azure/azure-sdk/ts-no-namespaces */ +/* eslint-disable @typescript-eslint/no-namespace */ /* eslint-disable no-inner-declarations */ import { logger, logErrorStackTrace } from "./log"; diff --git a/sdk/identity/identity/test/internal/node/interactiveBrowserCredential.spec.ts b/sdk/identity/identity/test/internal/node/interactiveBrowserCredential.spec.ts index 3576e1cabcaf..6d4d594133c7 100644 --- a/sdk/identity/identity/test/internal/node/interactiveBrowserCredential.spec.ts +++ b/sdk/identity/identity/test/internal/node/interactiveBrowserCredential.spec.ts @@ -2,7 +2,7 @@ // Licensed under the MIT license. /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */ -/* eslint-disable @azure/azure-sdk/ts-no-namespaces */ +/* eslint-disable @typescript-eslint/no-namespace */ import Sinon from "sinon"; import { assert } from "chai";