-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Code Editor: Improve types and options handling #10900
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
Open
westonruter
wants to merge
52
commits into
WordPress:trunk
Choose a base branch
from
westonruter:fix/wp-code-editor-types-and-options
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.
+494
−6,894
Open
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 ce4192b
Code Editor: Fix JSDoc types for CodeMirror instances.
westonruter ef4352c
Replace deprecated substr() with slice().
westonruter c76450f
Replace deprecated event.keyCode with event.key.
westonruter 68967d4
Pass Underscore to IIFE and add JSDoc types.
westonruter 49ab652
Define and use CodeEditorSettings typedef.
westonruter d3d39e9
Make CodeEditorSettings sub-properties optional.
westonruter 7bd58f0
Refine CodeEditorInstance and initialize types.
westonruter 1569be3
Refine CodeMirror settings types in CodeEditorSettings.
westonruter 55a86e9
Use public CodeMirror API for wrapper element.
westonruter d2dddab
Use native Node.contains() instead of jQuery.contains().
westonruter 7bdadc7
Use native Element.classList instead of jQuery.hasClass().
westonruter 7aa5359
Fix logic error when calling overridden onUpdateLinting.
westonruter 0eab515
Use specific CodeMirror.EditorFromTextArea type for editor instances.
westonruter c3f6261
Fix unresolved performLint() and improve CodeMirror types.
westonruter dfffb19
Use native filter() for annotations to improve type inference.
westonruter 651b325
Add types for CodeMirror state and token state.
westonruter cfa9f8a
Enhance CodeMirror type definitions for better IDE compatibility.
westonruter 81db304
Ensure shouldAutocomplete is always boolean.
westonruter c4cb899
Use getDoc method
westonruter 75173fd
Try alternative typedef
westonruter b27dcd9
Merge branch 'trunk' into fix/wp-code-editor-types-and-options
westonruter f5bcb81
Build Tooling: Introduce TypeScript checking for JavaScript files via…
westonruter c5e8db3
Code Editor: Refactor JSDoc types for TypeScript compatibility.
westonruter b4eda5b
Code Editor: Refine type definitions and resolve unused variable warn…
westonruter 835a3d9
Code Editor: Simplify type casts in optionChange handler.
westonruter 6cf7940
Code Editor: Add explicit types for mousedown event handler.
westonruter 1bad754
Code Editor: Cast fromTextArea return value to CodeMirrorEditor.
westonruter b23615c
Code Editor: Refine CodeMirror types and integrate addon definitions.
westonruter dd7579f
Code Editor: Prevent redundant linting pass during initialization.
westonruter 70e4196
Code Editor: Remove obsolete nested 'options.options' for linting.
westonruter 9cbfb44
Build Tooling: Reorganize CodeMirror source files.
westonruter 8570258
Code Editor: Enable TypeScript checking for CodeMirror extensions.
westonruter 26b7cee
Code Editor: Refactor htmlhint-kses.js to modern syntax.
westonruter 339fe05
Code Editor: Use for...of loop in htmlhint-kses.js.
westonruter 393b360
Code Editor: Use template literals in htmlhint-kses.js.
westonruter 6d5374a
Code Editor: Add HTMLHint types to htmlhint-kses.js.
westonruter 493be25
Eliminate abbreviated variables
westonruter b16bfaa
Code Editor: Strengthen TypeScript checking with specific JSDoc types.
westonruter c8a795a
Code Editor: Enable strict TypeScript checking.
westonruter 6fe9a8e
Code Editor: Refine linting types and reduce 'any' usage.
westonruter 6489ad0
Code Editor: Use flat linting options and refine intersection type.
westonruter 6a94d99
Code Editor: Refine linting types and eliminate 'any' usage.
westonruter bdc959f
Code Editor: Remove remaining 'any' type and streamline event listeners.
westonruter ffb7bcc
Break up long conditional line and remove redundant types
westonruter 81179e8
Eliminate redundancy in setting same-named variable to key in object …
westonruter ba15ab7
Code Editor: Add trailing commas to multi-line object literals.
westonruter 666a2c1
Code Editor: Refine local ESLint configuration.
westonruter bf2f382
Address ESLint complaints with htmlhint-kses.js
westonruter 0147a63
Code Editor: Apply Prettier formatting to htmlhint-kses.js.
westonruter d33a45c
Build Tooling: Revert esprima.js build source to node_modules.
westonruter b693399
Build Tooling: Remove redundant esprima.js source file.
westonruter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
| 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 | ||
| } | ||
| } | ||
| ] | ||
| } |
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
File renamed without changes.
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
| 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 | ||
| ); | ||
| } | ||
| } | ||
| } ); | ||
| }, | ||
| } ); |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: @justlevine cf. #10419 (comment)
There was a problem hiding this comment.
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
precommitGrunt task or in any GHA workflow. But I didn't want to expand the scope even more.