Skip to content
This repository was archived by the owner on Jul 9, 2026. It is now read-only.

Bump ESLint and Prettier packages to match versions in Gutenberg - #6219

Merged
fluiddot merged 4 commits into
trunkfrom
update/bump-eslint-and-prettier
Sep 25, 2023
Merged

fluiddot merged 4 commits into
trunkfrom
update/bump-eslint-and-prettier

Conversation

@fluiddot

Copy link
Copy Markdown
Contributor

This PR updates ESLint, some ESLint plugins, and Prettier packages following the changes recently made in Gutenberg (WordPress/gutenberg#54539).

These updates are needed to avoid failures when running the command npm run lint, as it was identified when trying to merge the release 1.104.0 into trunk (#6204). Here is the sequence of errors found when trying to address the failures:

Error 1

eslint-plugin-prettier package was recently introduced (reference) with the version 5.0.0. This version uses a newer version of ESLint than the one currently installed in GBM (version installed in GBM 6.8.0 vs. version referenced in the ESLint plugin 8.0.0). This explains the error of not loading the rule context.getPhysicalFilename, as it was introduced in ESLint version 7.28.0 (reference).

This problem was solved by upgrading the ESLint version in GBM to match the one used in Gutenberg (^8.3.0).

NOTE 1: In Gutenberg, the ESLint version installed is the one set by the @wordpress/scripts package. Since we don't use it in GBM, we have to set our own ESLint version.

NOTE 2: Alternatively, we could add the scripts package as a dev dependency in GBM. However, if we reference it via a local path, ESLint won't be automatically installed. This is mentioned in NPM documentation:

note: Packages linked by local path will not have their own dependencies installed when npm install is ran in this case. You must run npm install from inside the local path itself.

Error 2

The @typescript-eslint/eslint-plugin plugin can't be loaded due to the following error:

TypeError: Failed to load plugin '@typescript-eslint' declared in '.eslintrc.js » plugin:@wordpress/recommended': Class extends value undefined is not a constructor or null
Referenced from: /Users/fluiddot/workspace/gutenberg-mobile/gutenberg/packages/eslint-plugin/index.js

This was solved by upgrading to 6.4.1, as referenced in @wordpress/eslint-plugin package.

Alternatively, we could point to the npm version. However, this seems to not work because peer dependencies are not installed at the root level and ESLint plugins are only imported from that location.

Error 3

The eslint-plugin-import plugin can't be loaded:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Failed to load plugin 'import' declared in '.eslintrc.js » plugin:@wordpress/recommended » /Users/fluiddot/workspace/gutenberg-mobile/gutenberg/packages/eslint-plugin/configs/recommended-with-formatting.js': Package subpath './lib/util/glob-util' is not defined by "exports" in /Users/fluiddot/workspace/gutenberg-mobile/node_modules/eslint/package.json

Similar to the above solutions, we need to upgrade it to 2.25.2 as referenced in the Gutenberg package.

Error 4

The eslint-plugin-prettier plugin fails when using Prettier:

TypeError: prettier.resolveConfig is not a function
    at /Users/fluiddot/workspace/gutenberg-mobile/node_modules/eslint-plugin-prettier/worker.js:38:24

This was solved by upgrading Prettier to version 3.0.3-beta-3 as applied in the PR.

After solving the above errors, several files were formatted after running npm run lint:fix.

To test:

  • Check that all CI jobs pass.

PR submission checklist:

  • I have considered adding unit tests where possible.
  • I have considered if this change warrants user-facing release notes more info and have added them to RELEASE-NOTES.txt if necessary.

@fluiddot fluiddot added the dependencies Pull requests that update a dependency file label Sep 21, 2023
@fluiddot fluiddot added this to the 1.105.0 (23.4) milestone Sep 21, 2023
@fluiddot fluiddot self-assigned this Sep 21, 2023
@fluiddot fluiddot mentioned this pull request Sep 21, 2023
4 tasks done
@fluiddot
fluiddot requested review from dcalhoun and geriux September 21, 2023 14:18

@geriux geriux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thanks for addressing this 🚀

FYI I've restarted some CI jobs since they failed due to a network error, hopefully, they'll pass this time.

@fluiddot
fluiddot enabled auto-merge September 25, 2023 08:21
@fluiddot
fluiddot merged commit 0da94bf into trunk Sep 25, 2023
@fluiddot
fluiddot deleted the update/bump-eslint-and-prettier branch September 25, 2023 08:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants