json-lint.js 826 B

12345678910111213141516171819202122232425262728
  1. // Depends on jsonlint.js from https://github.com/zaach/jsonlint
  2. // declare global: jsonlint
  3. (function(mod) {
  4. if (typeof exports == "object" && typeof module == "object") // CommonJS
  5. mod(require("../../lib/codemirror"));
  6. else if (typeof define == "function" && define.amd) // AMD
  7. define(["../../lib/codemirror"], mod);
  8. else // Plain browser env
  9. mod(CodeMirror);
  10. })(function(CodeMirror) {
  11. "use strict";
  12. CodeMirror.registerHelper("lint", "json", function(text) {
  13. var found = [];
  14. jsonlint.parseError = function(str, hash) {
  15. var loc = hash.loc;
  16. found.push({from: CodeMirror.Pos(loc.first_line - 1, loc.first_column),
  17. to: CodeMirror.Pos(loc.last_line - 1, loc.last_column),
  18. message: str});
  19. };
  20. try { jsonlint.parse(text); }
  21. catch(e) {}
  22. return found;
  23. });
  24. });