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

[core-http] enable no-prototype-builtins #12717

Merged
merged 3 commits into from
Dec 2, 2020

Conversation

maorleger
Copy link
Member

What

  • Enable "no-prototype-builtins" and fix the errors
  • Fix any errors found in core-http lint report
  • Fail on lint errors

Why

  • Fixing the no-prototype rule was punted to a future commit to limit scope

  • In passing, I noticed other errors in the lint report

  • When all were fixed, I figured it would be helpful to fail with an error so the user can tell where to find the lint report. Otherwise I had to figure out why the lint errors weren't showing up like they do in other projects

  • Ran unit tests

  • Ensure the lint report is clean of errors (but not warnings to limit changes)

Fixes #8972

@@ -82,7 +82,7 @@
"integration-test:node": "echo skipped",
"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 -f html -o core-http-lintReport.html || exit 0",
"lint": "eslint package.json api-extractor.json src test --ext .ts -f html -o core-http-lintReport.html",
Copy link
Member Author

Choose a reason for hiding this comment

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

Feel free to let me know if I should revert this - it was easier for me to see the lint failure until I cleaned up the errors and then I figured it might be good to prevent future errors?

Copy link
Member

Choose a reason for hiding this comment

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

I think this was done to prevent lint from failing CI at one point, though maybe we don't need it anymore? /cc @willmtemple

@@ -49,8 +49,7 @@ class FetchHttpMock implements HttpMockFacade {

// returns the locally mocked fetch instance
getFetch(): typeof node_fetch {
/// @ts-ignore
return this._fetch as typeof node_fetch;
return (this._fetch as unknown) as typeof node_fetch;
Copy link
Member Author

Choose a reason for hiding this comment

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

Removing @ts-ignore exposed this error. I just used the editor's Code Action to auto-fix it but it seems to line up with https://microsoft.github.io/TypeScript-New-Handbook/everything/#type-assertions - maybe there's a cleaner way by updating FetchMockSandbox? I wasn't sure...

Copy link
Member

Choose a reason for hiding this comment

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

I think this one might be from when @jeremymeng did #9880

I'm fine with your solution though, casting through unknown is closer to the truth than us ignoring the line altogether.

Copy link
Member

Choose a reason for hiding this comment

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

Looks good! I spent some time trying to make the mocked type compatible with type of node_fetch but it seemed non-trivial and at the end I chose to do cast instead for testing.

Copy link
Member

@xirzec xirzec left a comment

Choose a reason for hiding this comment

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

I love it! Thanks for the beautification effort and welcome again! ❤️

@@ -82,7 +82,7 @@
"integration-test:node": "echo skipped",
"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 -f html -o core-http-lintReport.html || exit 0",
"lint": "eslint package.json api-extractor.json src test --ext .ts -f html -o core-http-lintReport.html",
Copy link
Member

Choose a reason for hiding this comment

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

I think this was done to prevent lint from failing CI at one point, though maybe we don't need it anymore? /cc @willmtemple

@@ -49,8 +49,7 @@ class FetchHttpMock implements HttpMockFacade {

// returns the locally mocked fetch instance
getFetch(): typeof node_fetch {
/// @ts-ignore
return this._fetch as typeof node_fetch;
return (this._fetch as unknown) as typeof node_fetch;
Copy link
Member

Choose a reason for hiding this comment

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

I think this one might be from when @jeremymeng did #9880

I'm fine with your solution though, casting through unknown is closer to the truth than us ignoring the line altogether.

@maorleger maorleger changed the title 8972 enable no prototype builtins 8972 enable no-prototype-builtins Nov 30, 2020
@maorleger maorleger changed the title 8972 enable no-prototype-builtins [core-http] enable no-prototype-builtins Dec 1, 2020
Co-authored-by: Deyaaeldeen Almahallawi <dealmaha@microsoft.com>
Copy link
Contributor

@willmtemple willmtemple left a comment

Choose a reason for hiding this comment

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

LGTM

@maorleger maorleger merged commit 7eb357a into Azure:master Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[core-http] Re-enable no-prototype-builtins lint rule
5 participants