Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
b54a88b
Modernize code-editor.js with const and let.
westonruter Jan 31, 2026
ce4192b
Code Editor: Fix JSDoc types for CodeMirror instances.
westonruter Jan 31, 2026
ef4352c
Replace deprecated substr() with slice().
westonruter Feb 10, 2026
c76450f
Replace deprecated event.keyCode with event.key.
westonruter Feb 10, 2026
68967d4
Pass Underscore to IIFE and add JSDoc types.
westonruter Feb 10, 2026
49ab652
Define and use CodeEditorSettings typedef.
westonruter Feb 11, 2026
d3d39e9
Make CodeEditorSettings sub-properties optional.
westonruter Feb 11, 2026
7bd58f0
Refine CodeEditorInstance and initialize types.
westonruter Feb 11, 2026
1569be3
Refine CodeMirror settings types in CodeEditorSettings.
westonruter Feb 11, 2026
55a86e9
Use public CodeMirror API for wrapper element.
westonruter Feb 11, 2026
d2dddab
Use native Node.contains() instead of jQuery.contains().
westonruter Feb 11, 2026
7bdadc7
Use native Element.classList instead of jQuery.hasClass().
westonruter Feb 11, 2026
7aa5359
Fix logic error when calling overridden onUpdateLinting.
westonruter Feb 11, 2026
0eab515
Use specific CodeMirror.EditorFromTextArea type for editor instances.
westonruter Feb 11, 2026
c3f6261
Fix unresolved performLint() and improve CodeMirror types.
westonruter Feb 11, 2026
dfffb19
Use native filter() for annotations to improve type inference.
westonruter Feb 11, 2026
651b325
Add types for CodeMirror state and token state.
westonruter Feb 11, 2026
cfa9f8a
Enhance CodeMirror type definitions for better IDE compatibility.
westonruter Feb 11, 2026
81db304
Ensure shouldAutocomplete is always boolean.
westonruter Feb 11, 2026
c4cb899
Use getDoc method
westonruter Feb 11, 2026
75173fd
Try alternative typedef
westonruter Feb 12, 2026
b27dcd9
Merge branch 'trunk' into fix/wp-code-editor-types-and-options
westonruter Feb 14, 2026
f5bcb81
Build Tooling: Introduce TypeScript checking for JavaScript files via…
westonruter Feb 14, 2026
c5e8db3
Code Editor: Refactor JSDoc types for TypeScript compatibility.
westonruter Feb 14, 2026
b4eda5b
Code Editor: Refine type definitions and resolve unused variable warn…
westonruter Feb 14, 2026
835a3d9
Code Editor: Simplify type casts in optionChange handler.
westonruter Feb 14, 2026
6cf7940
Code Editor: Add explicit types for mousedown event handler.
westonruter Feb 14, 2026
1bad754
Code Editor: Cast fromTextArea return value to CodeMirrorEditor.
westonruter Feb 14, 2026
b23615c
Code Editor: Refine CodeMirror types and integrate addon definitions.
westonruter Feb 14, 2026
dd7579f
Code Editor: Prevent redundant linting pass during initialization.
westonruter Feb 14, 2026
70e4196
Code Editor: Remove obsolete nested 'options.options' for linting.
westonruter Feb 14, 2026
9cbfb44
Build Tooling: Reorganize CodeMirror source files.
westonruter Feb 14, 2026
8570258
Code Editor: Enable TypeScript checking for CodeMirror extensions.
westonruter Feb 14, 2026
26b7cee
Code Editor: Refactor htmlhint-kses.js to modern syntax.
westonruter Feb 14, 2026
339fe05
Code Editor: Use for...of loop in htmlhint-kses.js.
westonruter Feb 14, 2026
393b360
Code Editor: Use template literals in htmlhint-kses.js.
westonruter Feb 14, 2026
6d5374a
Code Editor: Add HTMLHint types to htmlhint-kses.js.
westonruter Feb 14, 2026
493be25
Eliminate abbreviated variables
westonruter Feb 14, 2026
b16bfaa
Code Editor: Strengthen TypeScript checking with specific JSDoc types.
westonruter Feb 14, 2026
c8a795a
Code Editor: Enable strict TypeScript checking.
westonruter Feb 14, 2026
6fe9a8e
Code Editor: Refine linting types and reduce 'any' usage.
westonruter Feb 14, 2026
6489ad0
Code Editor: Use flat linting options and refine intersection type.
westonruter Feb 14, 2026
6a94d99
Code Editor: Refine linting types and eliminate 'any' usage.
westonruter Feb 14, 2026
bdc959f
Code Editor: Remove remaining 'any' type and streamline event listeners.
westonruter Feb 14, 2026
ffb7bcc
Break up long conditional line and remove redundant types
westonruter Feb 14, 2026
81179e8
Eliminate redundancy in setting same-named variable to key in object …
westonruter Feb 14, 2026
ba15ab7
Code Editor: Add trailing commas to multi-line object literals.
westonruter Feb 14, 2026
666a2c1
Code Editor: Refine local ESLint configuration.
westonruter Feb 14, 2026
bf2f382
Address ESLint complaints with htmlhint-kses.js
westonruter Feb 14, 2026
0147a63
Code Editor: Apply Prettier formatting to htmlhint-kses.js.
westonruter Feb 14, 2026
d33a45c
Build Tooling: Revert esprima.js build source to node_modules.
westonruter Feb 14, 2026
b693399
Build Tooling: Remove redundant esprima.js source file.
westonruter Feb 14, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ module.exports = function(grunt) {
},
{
expand: true,
cwd: SOURCE_DIR + 'js/_enqueues/vendor/codemirror/',
cwd: SOURCE_DIR + 'js/_enqueues/lib/codemirror/',
src: [
'fakejshint.js',
'htmlhint-kses.js',
Expand Down
74 changes: 74 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
"@playwright/test": "1.56.1",
"@pmmmwh/react-refresh-webpack-plugin": "0.6.1",
"@types/codemirror": "5.60.17",
"@types/espree": "10.1.0",
"@types/htmlhint": "1.1.5",
"@types/jquery": "3.5.33",
"@types/underscore": "1.11.15",
"@wordpress/e2e-test-utils-playwright": "1.33.2",
"@wordpress/prettier-config": "4.33.1",
"@wordpress/scripts": "30.26.2",
Expand Down Expand Up @@ -69,6 +73,7 @@
"sinon-test": "~3.1.6",
"source-map-loader": "5.0.0",
"terser-webpack-plugin": "5.3.14",
"typescript": "5.9.3",
"uuid": "13.0.0",
"wait-on": "9.0.3",
"webpack": "5.98.0"
Expand Down Expand Up @@ -115,6 +120,7 @@
"grunt": "grunt",
"lint:jsdoc": "wp-scripts lint-js",
"lint:jsdoc:fix": "wp-scripts lint-js --fix",
"static-analysis:js": "tsc",
Copy link
Member Author

Choose a reason for hiding this comment

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

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 not currently incorporated into the precommit Grunt task or in any GHA workflow. But I didn't want to expand the scope even more.

"env:start": "node ./tools/local-env/scripts/start.js && node ./tools/local-env/scripts/docker.js run -T --rm php composer update -W",
"env:stop": "node ./tools/local-env/scripts/docker.js down",
"env:restart": "npm run env:stop && npm run env:start",
Expand Down
17 changes: 17 additions & 0 deletions src/js/_enqueues/lib/codemirror/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"overrides": [
{
"files": [ "javascript-lint.js" ],
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2020
}
},
{
"files": [ "htmlhint-kses.js" ],
"parserOptions": {
"ecmaVersion": 2020
}
}
]
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: The coding standards failure is due to an existing JSHint error with fakejshint.js which is now deprecated. The file was unchanged.

File renamed without changes.
47 changes: 47 additions & 0 deletions src/js/_enqueues/lib/codemirror/htmlhint-kses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* global HTMLHint */
/* eslint no-magic-numbers: ["error", { "ignore": [1] }] */
HTMLHint.addRule( {
id: 'kses',
description: 'Element or attribute cannot be used.',

/**
* Initialize.
*
* @this {import('htmlhint/types').Rule}
* @param {import('htmlhint').HTMLParser} parser - Parser.
* @param {import('htmlhint').Reporter} reporter - Reporter.
* @param {Record<string, Record<string, boolean>>} options - KSES options.
* @return {void}
*/
init: function ( parser, reporter, options ) {
'use strict';

parser.addListener( 'tagstart', ( event ) => {
const tagName = event.tagName.toLowerCase();
if ( ! options[ tagName ] ) {
reporter.error(
`Tag <${ event.tagName }> is not allowed.`,
event.line,
event.col,
this,
event.raw
);
return;
}

const allowedAttributes = options[ tagName ];
const column = event.col + event.tagName.length + 1;
for ( const attribute of event.attrs ) {
if ( ! allowedAttributes[ attribute.name.toLowerCase() ] ) {
reporter.error(
`Tag attribute [${ attribute.raw }] is not allowed.`,
event.line,
column + attribute.index,
this,
attribute.raw
);
}
}
} );
},
} );
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import CodeMirror from 'codemirror';
* @see https://www.npmjs.com/package/espree#options
*
* @typedef {Object} SupportedJSHintOptions
* @property {number} [esversion] - "This option is used to specify the ECMAScript version to which the code must adhere."
* @property {import('espree').Options['ecmaVersion']} [esversion] - "This option is used to specify the ECMAScript version to which the code must adhere."
* @property {boolean} [es5] - "This option enables syntax first defined in the ECMAScript 5.1 specification. This includes allowing reserved keywords as object properties."
* @property {boolean} [es3] - "This option tells JSHint that your code needs to adhere to ECMAScript 3 specification. Use this option if you need your program to be executable in older browsers—such as Internet Explorer 6/7/8/9—and other legacy JavaScript environments."
* @property {boolean} [module] - "This option informs JSHint that the input code describes an ECMAScript 6 module. All module code is interpreted as strict mode code."
Expand All @@ -50,19 +50,20 @@ async function validator( text, options ) {
loc: true,
} );
} catch ( error ) {
const enhancedError = /** @type {Error & { lineNumber?: number, column?: number }} */ ( error );
if (
// This is an `EnhancedSyntaxError` in Espree: <https://github.com/brettz9/espree/blob/3c1120280b24f4a5e4c3125305b072fa0dfca22b/packages/espree/lib/espree.js#L48-L54>.
error instanceof SyntaxError &&
typeof error.lineNumber === 'number' &&
typeof error.column === 'number'
typeof enhancedError.lineNumber === 'number' &&
typeof enhancedError.column === 'number'
) {
const line = error.lineNumber - 1;
errors.push( {
const line = enhancedError.lineNumber - 1;
errors.push( /** @type {CodeMirrorLintError} */ ( {
message: error.message,
severity: 'error',
from: CodeMirror.Pos( line, error.column - 1 ),
to: CodeMirror.Pos( line, error.column ),
} );
from: CodeMirror.Pos( line, enhancedError.column - 1 ),
to: CodeMirror.Pos( line, enhancedError.column ),
} ) );
} else {
console.warn( '[CodeMirror] Unable to lint JavaScript:', error ); // jshint ignore:line
}
Expand All @@ -80,13 +81,15 @@ CodeMirror.registerHelper( 'lint', 'javascript', validator );
*
* @param {SupportedJSHintOptions} options - Linting options for JSHint.
* @return {{
* ecmaVersion?: number|'latest',
* ecmaVersion?: import('espree').Options['ecmaVersion'],
* sourceType?: 'module'|'script',
* ecmaFeatures?: {
* impliedStrict?: true
* }
* }}
*/
function getEspreeOptions( options ) {
/** @type {{ impliedStrict?: true }} */
const ecmaFeatures = {};
if ( options.strict === 'implied' ) {
ecmaFeatures.impliedStrict = true;
Expand All @@ -105,10 +108,10 @@ function getEspreeOptions( options ) {
* @since 7.0.0
*
* @param {SupportedJSHintOptions} options - Options.
* @return {number|'latest'} ECMAScript version.
* @return {import('espree').Options['ecmaVersion']} ECMAScript version.
*/
function getEcmaVersion( options ) {
if ( typeof options.esversion === 'number' ) {
if ( options.esversion ) {
return options.esversion;
}
if ( options.es5 ) {
Expand Down
Loading
Loading