-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Changes from 48 commits
b54a88b
ce4192b
ef4352c
c76450f
68967d4
49ab652
d3d39e9
7bd58f0
1569be3
55a86e9
d2dddab
7bdadc7
7aa5359
0eab515
c3f6261
dfffb19
651b325
cfa9f8a
81db304
c4cb899
75173fd
b27dcd9
f5bcb81
c5e8db3
b4eda5b
835a3d9
6cf7940
1bad754
b23615c
dd7579f
70e4196
9cbfb44
8570258
26b7cee
339fe05
393b360
6d5374a
493be25
b16bfaa
c8a795a
6fe9a8e
6489ad0
6a94d99
bdc959f
ffb7bcc
81179e8
ba15ab7
666a2c1
bf2f382
0147a63
d33a45c
b693399
7505032
b0a53a4
6d0d9ee
8c78893
2f4a6a2
f0ea1df
b47db54
c8911e3
8211a45
ef18c0c
3be7a13
5f54c0b
df54173
6ab382c
bf45a14
5d895d2
43e51ee
d01237c
8add99b
8b2e015
521ffb3
81d741a
9338964
b5dd3f0
62eec88
b4c8cd8
5192ff9
ed9f7b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "overrides": [ | ||
| { | ||
| "files": [ "javascript-lint.js" ], | ||
| "parserOptions": { | ||
| "sourceType": "module", | ||
| "ecmaVersion": 2020 | ||
| } | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* global HTMLHint */ | ||
| /* eslint no-magic-numbers: ["error", { "ignore": [0, 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 ); | ||
| } | ||
| } | ||
| }); | ||
| }, | ||
| }); |
|
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. This file isn't deleted, but moved to another directory. But it was so heavily updated to use modern JS syntax that it isn't recognized as a rename.
Member
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. Here's the file diff between fdafcd3 diff --git o/src/js/_enqueues/vendor/codemirror/htmlhint-kses.js w/src/js/_enqueues/lib/codemirror/htmlhint-kses.js
index 1aa7ffbd08..e08c4c0f5b 100644
--- o/src/js/_enqueues/vendor/codemirror/htmlhint-kses.js
+++ w/src/js/_enqueues/lib/codemirror/htmlhint-kses.js
@@ -1,30 +1,47 @@
/* global HTMLHint */
-/* eslint no-magic-numbers: ["error", { "ignore": [0, 1] }] */
-HTMLHint.addRule({
+/* eslint no-magic-numbers: ["error", { "ignore": [1] }] */
+HTMLHint.addRule( {
id: 'kses',
description: 'Element or attribute cannot be used.',
- init: function( parser, reporter, options ) {
+
+ /**
+ * 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';
- var self = this;
- parser.addListener( 'tagstart', function( event ) {
- var attr, col, attrName, allowedAttributes, i, len, tagName;
-
- tagName = event.tagName.toLowerCase();
+ parser.addListener( 'tagstart', ( event ) => {
+ const tagName = event.tagName.toLowerCase();
if ( ! options[ tagName ] ) {
- reporter.error( 'Tag <' + event.tagName + '> is not allowed.', event.line, event.col, self, event.raw );
+ reporter.error(
+ `Tag <${ event.tagName }> is not allowed.`,
+ event.line,
+ event.col,
+ this,
+ event.raw
+ );
return;
}
- allowedAttributes = options[ tagName ];
- col = event.col + event.tagName.length + 1;
- for ( i = 0, len = event.attrs.length; i < len; i++ ) {
- attr = event.attrs[ i ];
- attrName = attr.name.toLowerCase();
- if ( ! allowedAttributes[ attrName ] ) {
- reporter.error( 'Tag attribute [' + attr.raw + ' ] is not allowed.', event.line, col + attr.index, self, attr.raw );
+ 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 was deleted.
Uh oh!
There was an error while loading. Please reload this page.