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

Upgrade ESLint to v8 #3984

Merged
merged 14 commits into from
Nov 3, 2021
Merged

Upgrade ESLint to v8 #3984

merged 14 commits into from
Nov 3, 2021

Conversation

willdurand
Copy link
Member

@willdurand willdurand commented Oct 23, 2021

Fixes #3985
Fixes #3062
Fixes #3741
Fixes #3960


This PR upgrades eslint to v8, which will allow us to support the 2022 syntax.

TODO

@willdurand
Copy link
Member Author

Sadly, we seem blocked by the ESLint config for this project (-dev deps).I think it is because we enable the browser env in our config. Not all ESlint plugins support v8 yet.

I am wondering if we could fix our config to avoid relying on some browser (e.g. react) plugins.

@willdurand
Copy link
Member Author

I am wondering if we could fix our config to avoid relying on some browser (e.g. react) plugins.

That has been fixed. We don't prevent the installation of some (useless) packages but they are not loaded so there won't be any error, except some npm warnings about peer deps. It is fine, we use a shared config to avoid requiring/updating too many packages in too many repos.

@willdurand
Copy link
Member Author

test-alternate fails because eslint-plugin-no-unsanitized does not support ESLint v8.

"rules":{
"no-console": 0,
// Inherited from airbnb via eslint-config-amo
"function-paren-newline": 0
Copy link
Member Author

Choose a reason for hiding this comment

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

This is (and always was) part of the base config.

"function-paren-newline": 0
"rules": {
// This project uses `console.log()`.
"no-console": "off"
Copy link
Member Author

Choose a reason for hiding this comment

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

I find off a bit easier to understand than 0. I thought we didn't need this rule but we do so I added a comment.

Copy link
Member

Choose a reason for hiding this comment

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

👌 I also prefer the more explicit "off"

"extends": ["amo"],
"parser": "babel-eslint",
"extends": ["amo/base"],
"parser": "@babel/eslint-parser",
Copy link
Member Author

Choose a reason for hiding this comment

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

Ha, yeah. That babel-eslint parser is no longer maintained and it has moved to the babel monorepo. That shouldn't change anything except that we use a maintained version of the same parser.

"@mdn/browser-compat-data": "4.0.7",
"addons-moz-compare": "1.2.0",
"addons-scanner-utils": "5.0.0",
"addons-scanner-utils": "6.1.0",
Copy link
Member Author

Choose a reason for hiding this comment

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

Needed to configure ESLint with ES 2022.

"babel-gettext-extractor": "4.1.3",
"babel-jest": "27.3.1",
"babel-loader": "8.2.3",
"codecov": "3.8.3",
"comment-json": "4.1.1",
"doctoc": "2.1.0",
"eslint-config-amo": "4.11.0",
"eslint-config-amo": "5.1.0",
Copy link
Member Author

Choose a reason for hiding this comment

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

Needed to use amo/base instead of amo.

"expect",
"sinon.assert.*",
"assertHasMatchingError",
"checkMinNodeVersion",
Copy link
Member Author

Choose a reason for hiding this comment

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

I thought I'd go ahead and mute some more warnings. We only have 3 warnings (due to excluded files) now.

Copy link
Member

Choose a reason for hiding this comment

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

ah, Thank you for taking care of this! ❤️

I did notice those warnings not long time ago and they were kind of bothering me but didn't had the time to look into them.

@@ -2978,11 +2978,13 @@ describe('ManifestJSONParser', () => {
];

for (const invalidUrl of testInvalidUrls) {
// eslint-disable-next-line jest/expect-expect
Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't update the eslint config for these test cases because testHomepageUrl is fairly specific to this describe block.

Copy link
Member

Choose a reason for hiding this comment

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

sgtm

// See: https://github.com/tc39/proposal-class-fields
// eslint-disable-next-line jest/no-disabled-tests
it.skip('should support public class fields', async () => {
it('should support public class fields', async () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

🔥

@@ -681,7 +681,7 @@ describe('Linter.textOutput()', () => {
addonLinter.textOutput(uselesslyTinyTerminalWidth);
expect(addonLinter.output.summary.errors).toEqual(1);
} catch (e) {
// eslint-disable-next-line jest/no-conditional-expect, jest/no-try-expect
// eslint-disable-next-line jest/no-conditional-expect
Copy link
Member Author

Choose a reason for hiding this comment

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

@willdurand
Copy link
Member Author

test-alternate fails because eslint-plugin-no-unsanitized does not support ESLint v8.

I filed an issue for that: mozilla/eslint-plugin-no-unsanitized#185

@willdurand willdurand marked this pull request as ready for review October 25, 2021 08:15
@willdurand willdurand requested a review from rpl October 25, 2021 08:15
@willdurand
Copy link
Member Author

@rpl I know test-alternate is failing but the rest of the patch is ready for a review.

@rpl
Copy link
Member

rpl commented Oct 27, 2021

@rpl I know test-alternate is failing but the rest of the patch is ready for a review.

I looked the PR and it looks in a pretty good shape.
and I see that the test-alternate failure is due to the eslint-plugin-no-unsanitized issue.

I filed an issue for that: mozilla/eslint-plugin-no-unsanitized#185

Yesterday I give it a very quick try to that locally before going afk, eslint-plugin-no-unsanitized tests were failing while running on eslint v8, but I haven't looked closely yet to the failures.
I'll try to take a more deeper look to those asap (if Freddy doesn't get to it first).

"eslint-plugin-async-await": "0.0.0",
"eslint-plugin-promise": "5.1.1",
Copy link
Member Author

@willdurand willdurand Nov 2, 2021

Choose a reason for hiding this comment

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

not used it seems?

Edit: it is used for the tests actually, and it is likely coming from addons-frontend, see: https://github.com/mozilla/addons-frontend/issues/2065. I'll revert this change.

package.json Outdated
"babel-gettext-extractor": "4.1.3",
"babel-jest": "27.3.1",
"babel-loader": "8.2.3",
"comment-json": "4.1.1",
"doctoc": "2.1.0",
"eslint-config-amo": "4.11.0",
"eslint-config-amo": "5.1.0",
"eslint-plugin-async-await": "0.0.0",
Copy link
Member Author

Choose a reason for hiding this comment

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

I am questioning the usefulness of this plugin: I don't think it is used in most of the other projects and we do use async/await everywhere now. I would like to remove this dev dependency: WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

@willdurand it looks that it does only provides two "code formatting" rules, which I would guess that prettier may also be taking care of. Also the package version is v0.0.0 and last release 5 years ago, definitely 👍 on my side on getting rid of it.

@codecov
Copy link

codecov bot commented Nov 2, 2021

Codecov Report

Merging #3984 (1454334) into master (95d2bac) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    mozilla/addons-frontend#3984   +/-   ##
=======================================
  Coverage   98.71%   98.71%           
=======================================
  Files          52       52           
  Lines        2652     2652           
  Branches      799      799           
=======================================
  Hits         2618     2618           
  Misses         34       34           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 95d2bac...1454334. Read the comment docs.

@willdurand
Copy link
Member Author

The last commit about removing eslint-plugin-promise shows that pinning the eslint-plugin-no-unsanitized version (using a git commit) fixes the issue for this project (i.e. eslint-plugin-no-unsanitized with ESLint v8 support works as intended here).

Removing eslint-plugin-promise was "needed" because this plugin does not support ESLint v8 yet and npm fails in some cases because of the peer dependency mismatch. That's annoying because we are blocked by this dev dependency now.

Apart from that, I'd like to remove eslint-plugin-async-await, which I don't find particularly useful. Thoughts?

@willdurand willdurand requested a review from rpl November 2, 2021 08:03
@willdurand
Copy link
Member Author

willdurand commented Nov 2, 2021

re-requesting a review not for the review itself but to make sure you see the last comment.

@willdurand
Copy link
Member Author

I switched to v4.0.0 of the eslint-plugin-no-unsanitized plugin.

@willdurand
Copy link
Member Author

@rpl for when you have time, this is ready for a review with two caveats:

  • eslint-plugin-promise removed because it is currently not compatible
  • eslint-plugin-async-await isn't removed yet but I would like to remove it, see: Upgrade ESLint to v8 #3984 (comment)

I am not sure when eslint-plugin-promise will get proper support for ESLint v8 so I am thinking about removing it here now and adding it back in a different patch when it is compatible? That would allow us to move forward given that eslint-plugin-promise is a dev dependency (and not a lib we use in the core of the linter).

@rpl
Copy link
Member

rpl commented Nov 3, 2021

@rpl for when you have time, this is ready for a review with two caveats:

* `eslint-plugin-promise` removed because it is currently not compatible

* `eslint-plugin-async-await` isn't removed yet but I would like to remove it, see: [Upgrade ESLint to v8 mozilla/addons-frontend#3984 (comment)](https://github.com/mozilla/addons-linter/pull/3984#discussion_r740788256)

I am not sure when eslint-plugin-promise will get proper support for ESLint v8 so I am thinking about removing it here now and adding it back in a different patch when it is compatible? That would allow us to move forward given that eslint-plugin-promise is a dev dependency (and not a lib we use in the core of the linter).

100% agree on eslint-plugin-async-await (#3984 (comment)).

For eslint-plugin-promise instead, it would be nice to bring it back as soon as we can, I'm ok to remove it in the short run (to allow us to proceed with upgrading eslint to v8) along with filing a follow up issue to bring it back.

Copy link
Member

@rpl rpl left a comment

Choose a reason for hiding this comment

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

@willdurand lgtm, just one detail related to @babel/eslint-parser being listed as a dependency instead of a dev dependency. Everything else looks good to me as is.

@willdurand
Copy link
Member Author

I moved the babel parser to the list of dev dependencies and removed the async-await eslint plugin. I also filed an issue for the eslint-plugin-promise: #4016

@willdurand willdurand requested a review from rpl November 3, 2021 12:18
Copy link
Member

@rpl rpl left a comment

Choose a reason for hiding this comment

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

Thanks!

@willdurand willdurand merged commit 2e9ab54 into master Nov 3, 2021
@willdurand willdurand deleted the eslint8 branch November 3, 2021 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants