Skip to content

[Linter] Update linter rule to check if sdk-type exists in package.json#18597

Merged
maorleger merged 8 commits intoAzure:mainfrom
bzhang0:issue-13214
Nov 10, 2021
Merged

[Linter] Update linter rule to check if sdk-type exists in package.json#18597
maorleger merged 8 commits intoAzure:mainfrom
bzhang0:issue-13214

Conversation

@bzhang0
Copy link
Copy Markdown
Contributor

@bzhang0 bzhang0 commented Nov 9, 2021

This fixes #13214. This PR is an update from a past PR, #18565.

What's new?

  • I updated ts-package-json-sdktype.ts to enforce the existence ofsdk-type and that it is either client or mgmt. If it does not, then the linter will throw an error.
  • I added/updated appropriate tests and verified the entire repository using rush lint
  • I also put the rules in the correct files (src/configs/index.ts, src/rules/index.ts, and tests/plugin.ts)
  • I have written a docs file to put in docs/rules which are now included in the commit!
  • I do need to still update the actual README.md file, but I'm not sure what the actual version is (hopefully this isn't too much trouble)

Let me know if there's anything I missed!

@ghost ghost added KeyVault eslint plugin customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Nov 9, 2021
@ghost
Copy link
Copy Markdown

ghost commented Nov 9, 2021

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

Copy link
Copy Markdown
Member

@maorleger maorleger left a comment

Choose a reason for hiding this comment

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

🚀 this looks fine to me. For the README update I think 3.1.0 is fine, this is the latest version we used when adding ts-no-window and this isn't actually released to npm anymore

Thanks for helping out!

@bzhang0 I can merge this after the README is updated

Copy link
Copy Markdown
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!

if (!["client", "mgmt"].includes(strValue)) {
context.report({
node: node.value,
message: "sdk-type is not set to `client` or `mgmt`"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps it could be useful to print the unrecognized value too?

Suggested change
message: "sdk-type is not set to `client` or `mgmt`"
message: `unrecognized sdk-type value: ${strValue}. Expected `client` or `mgmt` instead.`

Please note the error messages in the tests will need to be updated too.

@bzhang0
Copy link
Copy Markdown
Contributor Author

bzhang0 commented Nov 9, 2021

@maorleger @deyaaeldeen I'll have these changes done!

Copy link
Copy Markdown
Member

@jeremymeng jeremymeng left a comment

Choose a reason for hiding this comment

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

Looks good! just one comment


const strValue = stripPath(value.value);

if (!["client", "mgmt"].includes(strValue)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add "utility" into the allowed list. It was just added earlier in #18402.

@maorleger maorleger merged commit 41018c3 into Azure:main Nov 10, 2021
@bzhang0 bzhang0 deleted the issue-13214 branch November 18, 2021 00:27
maorleger added a commit that referenced this pull request Nov 22, 2021
It looks like ts-package-json-sdktype rule entry was duplicated in #18597 -
which causes the "number of rules should match the expected value" to report an
error.

This PR fixes the issue by removing the duplicated entry. I also went ahead and
sorted the entries to make these things easier to spot in the future (although
there is no guarantee sort will be preserved).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

customer-reported Issues that are reported by GitHub users external to the Azure organization. eslint plugin KeyVault

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ESLint plugin] Check if sdk-type exists in package.json

4 participants