json-lint.js 954 B

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