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.

yaml-lint.js 1.2KB

2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: https://codemirror.net/LICENSE
  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. // Depends on js-yaml.js from https://github.com/nodeca/js-yaml
  13. // declare global: jsyaml
  14. CodeMirror.registerHelper("lint", "yaml", function(text) {
  15. var found = [];
  16. if (!window.jsyaml) {
  17. if (window.console) {
  18. window.console.error("Error: window.jsyaml not defined, CodeMirror YAML linting cannot run.");
  19. }
  20. return found;
  21. }
  22. try { jsyaml.loadAll(text); }
  23. catch(e) {
  24. var loc = e.mark,
  25. // js-yaml YAMLException doesn't always provide an accurate lineno
  26. // e.g., when there are multiple yaml docs
  27. // ---
  28. // ---
  29. // foo:bar
  30. from = loc ? CodeMirror.Pos(loc.line, loc.column) : CodeMirror.Pos(0, 0),
  31. to = from;
  32. found.push({ from: from, to: to, message: e.message });
  33. }
  34. return found;
  35. });
  36. });