-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Switch from Esprima to Espree for JavaScript linting in CodeMirror. #10806
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
Draft
westonruter
wants to merge
10
commits into
WordPress:trunk
Choose a base branch
from
westonruter:replace-esprima-with-espree
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Switch from Esprima to Espree for JavaScript linting in CodeMirror. #10806
westonruter
wants to merge
10
commits into
WordPress:trunk
from
westonruter:replace-esprima-with-espree
+711
−129
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
5c7da3d to
cfd3baf
Compare
Replaces the `esprima`-based validation in the code editor with `espree` to provide support for modern JavaScript (ES6+).
Key Changes:
1. **New Linter Integration:**
* Introduces `src/js/_enqueues/vendor/codemirror/javascript-lint.js` which uses `espree` (v9.6.1) for parsing and error reporting.
* This replaces the previous dependency on the `jshint` and `esprima` scripts. The `espree` module is now loaded via a dynamic import on demand by the new javascript lint integration.
* This custom linter is bundled into the CodeMirror build via `tools/vendors/codemirror-entry.js`.
2. **Script Modules:**
* Registers `espree` as a script module in `src/wp-includes/script-modules.php`.
* Adds a workaround in the `wp-codemirror` registration to ensure `espree` is included in the importmap.
3. **Editor Settings:**
* Updates `wp_get_code_editor_settings()` in `src/wp-includes/general-template.php` to use ES11 defaults.
* Synchronizes JSHint settings from .jshintrc, even though these are not supported by Espree.
4. **Deprecations:**
* Marks `esprima` and `jshint` script handles as deprecated in `src/wp-includes/script-loader.php`.
5. **Build Tools:**
* Updates Webpack configuration (`tools/webpack/codemirror.config.js`) to bundle `espree` as a module.
* Updates `codemirror-entry.js` to use the new local `javascript-lint.js`.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
cfd3baf to
bd2376c
Compare
…into replace-esprima-with-espree
… at 9acd7f0 Co-authored-by: Jon Surrell <jonsurrell@git.wordpress.org> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…resolution. By adding /* webpackIgnore: true */ to the dynamic import in javascript-lint.js, we prevent Webpack from bundling Espree into a separate chunk. This allows the browser to resolve Espree at runtime using the Import Map. Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
The IIFE in javascript-lint.js is removed as it is redundant when bundled by Webpack. Both javascript-lint.js and codemirror-entry.js are updated to use 'const' instead of 'var' for the CodeMirror require, aligning with modern JavaScript practices in the project. Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
942ce9e to
99a6994
Compare
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…vascript-lint.js. Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Previously developed in westonruter#4 as a sub-PR off of #10778
Depends on:
New Linter Integration:
src/js/_enqueues/vendor/codemirror/javascript-lint.jswhich usesespree(v9.6.1) for parsing and error reporting.jshintandesprimascripts. Theespreemodule is now loaded via a dynamic import on demand by the new javascript lint integration.tools/vendors/codemirror-entry.js.Script Modules:
espreeas a script module insrc/wp-includes/script-modules.php.wp-codemirrorregistration to ensureespreeis included in the importmap.Editor Settings:
wp_get_code_editor_settings()insrc/wp-includes/general-template.phpto use ES11 defaults.Deprecations:
esprimaandjshintscript handles as deprecated insrc/wp-includes/script-loader.php.Build Tools:
tools/webpack/codemirror.config.js) to bundleespreeas a module.codemirror-entry.jsto use the new localjavascript-lint.js.Trac ticket: https://core.trac.wordpress.org/ticket/64558
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.