Bump ESLint and Prettier packages to match versions in Gutenberg #6219
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 release1.104.0
intotrunk
(#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 version5.0.0
. This version uses a newer version of ESLint than the one currently installed in GBM (version installed in GBM6.8.0
vs. version referenced in the ESLint plugin8.0.0
). This explains the error of not loading the rulecontext.getPhysicalFilename
, as it was introduced in ESLint version7.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:Error 2
The
@typescript-eslint/eslint-plugin
plugin can't be loaded due to the following error: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: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: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:
PR submission checklist: