You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1002 B

1 year ago
  1. // JSHINT has some GPL Compatability issues, so we are faking it out and using esprima for validation
  2. // Based on https://github.com/jquery/esprima/blob/gh-pages/demo/validate.js which is MIT licensed
  3. var fakeJSHINT = new function() {
  4. var syntax, errors;
  5. var that = this;
  6. this.data = [];
  7. this.convertError = function( error ){
  8. return {
  9. line: error.lineNumber,
  10. character: error.column,
  11. reason: error.description,
  12. code: 'E'
  13. };
  14. };
  15. this.parse = function( code ){
  16. try {
  17. syntax = window.esprima.parse(code, { tolerant: true, loc: true });
  18. errors = syntax.errors;
  19. if ( errors.length > 0 ) {
  20. for ( var i = 0; i < errors.length; i++) {
  21. var error = errors[i];
  22. that.data.push( that.convertError( error ) );
  23. }
  24. } else {
  25. that.data = [];
  26. }
  27. } catch (e) {
  28. that.data.push( that.convertError( e ) );
  29. }
  30. };
  31. };
  32. window.JSHINT = function( text ){
  33. fakeJSHINT.parse( text );
  34. };
  35. window.JSHINT.data = function(){
  36. return {
  37. errors: fakeJSHINT.data
  38. };
  39. };