Skip to content

Conversation

@westonruter
Copy link
Member

@westonruter westonruter commented Jan 27, 2026

Previously developed in westonruter#4 as a sub-PR off of #10778

Depends on:

  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.

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.

@github-actions
Copy link

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

westonruter and others added 2 commits January 28, 2026 10:11
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>
@westonruter westonruter force-pushed the replace-esprima-with-espree branch from cfd3baf to bd2376c Compare January 28, 2026 18:39
westonruter and others added 6 commits January 30, 2026 19:53
… 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>
westonruter and others added 2 commits January 30, 2026 20:54
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>
* @since 7.0.0
*/

const CodeMirror = require( 'codemirror' );
Copy link
Member

Choose a reason for hiding this comment

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

This all requires webpack processing. Can we use a static import here which is more common in modern, compiled JavaScript?

Copy link
Member Author

Choose a reason for hiding this comment

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

Webpack processing is required anyway since it creates the bundle from codemirror-entry.js. Or is this for the future where we could possibly re-use this module as-is with v6?

Copy link
Member Author

Choose a reason for hiding this comment

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

In any case, I've switched to using ESM instead of CommonJS for everything in 9e3038d.

westonruter and others added 2 commits February 3, 2026 17:45
… at 9acd7f0...3a67800

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>
@westonruter westonruter marked this pull request as ready for review February 4, 2026 01:47
@github-actions
Copy link

github-actions bot commented Feb 4, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props westonruter, jonsurrell.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Update src/js/_enqueues/vendor/codemirror/javascript-lint.js and tools/vendors/codemirror-entry.js to use ESM import statements instead of CommonJS require(). This aligns with modern JavaScript standards and ensures compatibility with the project's build process.

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>
@@ -0,0 +1 @@
export * from 'espree';
Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately, Epsree does not have an ES module included in its distribution.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR replaces Esprima/JSHint with Espree for JavaScript linting in CodeMirror to address GPL compatibility issues. The change introduces a new custom JavaScript linter that uses the Espree parser (v9.6.1) for syntax validation, registers Espree as a script module, and deprecates the legacy esprima and jshint script handles.

Changes:

  • Introduces a custom JavaScript linter using Espree for syntax-only validation (no linting rules)
  • Registers Espree as a script module with import map integration via module dependencies
  • Updates build tooling to generate separate espree.min.js module and integrate the new linter into codemirror.min.js

Reviewed changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/js/_enqueues/vendor/codemirror/javascript-lint.js New custom JavaScript linter using Espree for syntax validation
tools/webpack/codemirror.config.js Adds espree build configuration and restructures codemirror build
tools/vendors/espree-entry.js Entry point for bundling espree as a module
tools/vendors/codemirror-entry.js Updates to use new javascript-lint and ES module imports
src/wp-includes/script-modules.php Registers espree as a script module
src/wp-includes/script-loader.php Adds module dependency for wp-codemirror and deprecates jshint/esprima
src/wp-includes/general-template.php Updates JSHint settings to ES11 and adds clarifying comments
tests/phpunit/tests/dependencies/scripts.php Updates tests to reflect jshint key changes and adds espree to exclusions
tests/phpunit/tests/widgets/wpWidgetCustomHtml.php Removes jshint enqueue test expectation
package.json Adds espree 9.6.1 and @types/codemirror dependencies
package-lock.json Lock file updates for new dependencies

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

);

$scripts->add( 'wp-codemirror', '/wp-includes/js/codemirror/codemirror.min.js', array(), '5.65.20' );
did_action( 'init' ) && $scripts->add_data( 'wp-codemirror', 'module_dependencies', array( 'espree' ) );
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

The condition did_action( 'init' ) is used here as a guard, but this creates a timing-dependent behavior. If this code runs before the 'init' action, the module dependency won't be added. Consider either: (1) always adding this data unconditionally, or (2) hooking into the 'init' action to add this dependency at the appropriate time. The current pattern may lead to inconsistent behavior depending on when wp_default_scripts is called.

Suggested change
did_action( 'init' ) && $scripts->add_data( 'wp-codemirror', 'module_dependencies', array( 'espree' ) );
$scripts->add_data( 'wp-codemirror', 'module_dependencies', array( 'espree' ) );

Copilot uses AI. Check for mistakes.
Comment on lines +4156 to +4157
// The following are copied from <https://github.com/WordPress/wordpress-develop/blob/6.9.0/.jshintrc>.
// Nevertheless, they are not supported by Espree, which is used instead of JSHint for licensing reasons.
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

The comment states that the JSHint options are "not supported by Espree", but this is only partially accurate. While most of the JSHint options listed (boss, curly, eqeqeq, etc.) are indeed linting rules that Espree doesn't support, the options esversion, es5, es3, module, and strict ARE used by the Espree integration in javascript-lint.js. The comment should be clarified to distinguish between the parsing-related options that Espree does support and the linting-rule options that it doesn't support. This would help future developers understand which options are still relevant.

Suggested change
// The following are copied from <https://github.com/WordPress/wordpress-develop/blob/6.9.0/.jshintrc>.
// Nevertheless, they are not supported by Espree, which is used instead of JSHint for licensing reasons.
// The following JSHint *linting rule* options are copied from
// <https://github.com/WordPress/wordpress-develop/blob/6.9.0/.jshintrc>.
// Parsing-related options such as `esversion` (and, in other contexts, `es5`, `es3`, `module`, `strict`)
// are honored by the Espree-based integration, but these linting-rule options are not interpreted by Espree
// and are kept only for compatibility/documentation with the original JSHint configuration.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants