Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[eslint-plugin-azure-sdk] Replaced redundant custom rule ts-no-namespaces with typescript-eslint/no-namespace #18676

Merged
merged 3 commits into from
Nov 22, 2021

Conversation

bbrusniak
Copy link
Contributor

@bbrusniak bbrusniak commented Nov 14, 2021

This fixes #8717 I deleted the files implementing the ts-no-namespaces rule and enabled the typescript-eslint/no-namespace rule in the base config file. Also, updated files which reference ts-no-namespaces. Here is specifically what I did:

  • Removed the source file, test file, and documentation file for the ts-no-namespaces rule:
    • common/tools/eslint-plugin-azure-sdk/src/rules/ts-no-namespaces.ts
    • common/tools/eslint-plugin-azure-sdk/tests/rules/ts-no-namespaces.ts
    • common/tools/eslint-plugin-azure-sdk/docs/rules/ts-no-namespaces.md
  • Removed the reference to the rule in common/tools/eslint-plugin-azure-sdk/README.md
  • Removed references to the rule in index.ts files
    • common/tools/eslint-plugin-azure-sdk/src/configs/index.ts
    • common/tools/eslint-plugin-azure-sdk/src/rules/index.ts
  • Enabled the typescript-eslint/no-namespace rule in the base config file: common/tools/eslint-plugin-azure-sdk/src/configs/azure-sdk-base.ts
  • Updated various files that were disabling the previous ts-no-namespaces rule to instead disable the typescript-eslint/no-namespace rule.

Let me know if I've missed anything in the removal of this rule as I am new to this code base!

@ghost
Copy link

ghost commented Nov 14, 2021

Thank you for your contribution bbrusniak! We will review the pull request and get back to you soon.

@ghost
Copy link

ghost commented Nov 14, 2021

CLA assistant check
All CLA requirements met.

Copy link
Member

@witemple-msft witemple-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Can we turn on allowDeclarations in the rule's options? A lot of the places in the code where we disable this rule are not places where we're creating namespaces, but places where we're declaring types for modules or declaring global type definitions.

So I think declare global { ... } and declare module "foo" { ... } should be fine. We would only invoke these if there were things in the environment that we actually want to describe. I'm also fine with just requiring that we disable the rule in the rare cases that we want to use them, but I'm not sure if there are any cases where we would use a declare in error. @deyaaeldeen WDYT?

Comment on lines 228 to 230
namespace deleteasyncRetry {
export let internalCounter: number = 1; // eslint-disable-line prefer-const
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is neither here nor there for this PR but the namespaces in these files are the only namespace declarations that actually stick out to me. CC @sadasant and @deyaaeldeen should we file an issue to rework these?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to mimic static variables based on this recommendation: microsoft/TypeScript#8419 (comment) and did not want to change the whole setup of routes logic as functions to accommodate stateful ones.

I am fine with opening an issue though to track updating this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see the purpose of the pattern now is to let the namespace merge with the function and bind those static fields to it that way. It would be nice to find a different way to bind these to instances of the function (using Object.assign and explicitly giving the function's name an extended type might work, or even a class that extends Function), but it doesn't matter too much.

@witemple-msft
Copy link
Member

/azp run js - identity - ci

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@deyaaeldeen deyaaeldeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks a lot!

@@ -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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why it was turned off in the first place? but this is a question to the team :) @witemple-msft and @sadasant do you know?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had our own namespace rule which this PR removes in favor of this built-in one.

In the history of our eslint plugin, it was basically developed in 1:1 correspondence with the guidelines, and at that time the eslint/tslint/typescript-eslint story was not as set in stone as it is now where pretty much everyone is using eslint with the typescript plugin.

Comment on lines 228 to 230
namespace deleteasyncRetry {
export let internalCounter: number = 1; // eslint-disable-line prefer-const
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to mimic static variables based on this recommendation: microsoft/TypeScript#8419 (comment) and did not want to change the whole setup of routes logic as functions to accommodate stateful ones.

I am fine with opening an issue though to track updating this.

@deyaaeldeen deyaaeldeen merged commit 65e171e into Azure:main Nov 22, 2021
@jeremymeng
Copy link
Member

Nice. Can we turn on allowDeclarations in the rule's options? A lot of the places in the code where we disable this rule are not places where we're creating namespaces, but places where we're declaring types for modules or declaring global type definitions.

I will log an issue for this

@jeremymeng
Copy link
Member

#18774

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[eslint-plugin-azure-sdk] Rule "@azure/azure-sdk/ts-no-namespaces" is redundant
4 participants