summaryrefslogtreecommitdiffstats
path: root/wp-includes/js/codemirror/fakejshint.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 07:56:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 07:56:49 +0000
commita415c29efee45520ae252d2aa28f1083a521cd7b (patch)
treef4ade4b6668ecc0765de7e1424f7c1427ad433ff /wp-includes/js/codemirror/fakejshint.js
parentInitial commit. (diff)
downloadwordpress-a415c29efee45520ae252d2aa28f1083a521cd7b.tar.xz
wordpress-a415c29efee45520ae252d2aa28f1083a521cd7b.zip
Adding upstream version 6.4.3+dfsg1.upstream/6.4.3+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'wp-includes/js/codemirror/fakejshint.js')
-rw-r--r--wp-includes/js/codemirror/fakejshint.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/wp-includes/js/codemirror/fakejshint.js b/wp-includes/js/codemirror/fakejshint.js
new file mode 100644
index 0000000..6cc33ce
--- /dev/null
+++ b/wp-includes/js/codemirror/fakejshint.js
@@ -0,0 +1,43 @@
+// JSHINT has some GPL Compatability issues, so we are faking it out and using esprima for validation
+// Based on https://github.com/jquery/esprima/blob/gh-pages/demo/validate.js which is MIT licensed
+
+var fakeJSHINT = new function() {
+ var syntax, errors;
+ var that = this;
+ this.data = [];
+ this.convertError = function( error ){
+ return {
+ line: error.lineNumber,
+ character: error.column,
+ reason: error.description,
+ code: 'E'
+ };
+ };
+ this.parse = function( code ){
+ try {
+ syntax = window.esprima.parse(code, { tolerant: true, loc: true });
+ errors = syntax.errors;
+ if ( errors.length > 0 ) {
+ for ( var i = 0; i < errors.length; i++) {
+ var error = errors[i];
+ that.data.push( that.convertError( error ) );
+ }
+ } else {
+ that.data = [];
+ }
+ } catch (e) {
+ that.data.push( that.convertError( e ) );
+ }
+ };
+};
+
+window.JSHINT = function( text ){
+ fakeJSHINT.parse( text );
+};
+window.JSHINT.data = function(){
+ return {
+ errors: fakeJSHINT.data
+ };
+};
+
+