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