提交 | 用户 | 时间
|
e7c126
|
1 |
/* |
H |
2 |
* Copyright 1999-2018 Alibaba Group Holding Ltd. |
|
3 |
* |
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
* you may not use this file except in compliance with the License. |
|
6 |
* You may obtain a copy of the License at |
|
7 |
* |
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
* |
|
10 |
* Unless required by applicable law or agreed to in writing, software |
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
* See the License for the specific language governing permissions and |
|
14 |
* limitations under the License. |
|
15 |
*/ |
|
16 |
|
|
17 |
// Depends on jsonlint.js from https://github.com/zaach/jsonlint |
|
18 |
|
|
19 |
// declare global: jsonlint |
|
20 |
|
|
21 |
(function(mod) { |
|
22 |
if (typeof exports == "object" && typeof module == "object") // CommonJS |
|
23 |
mod(require("../../lib/codemirror")); |
|
24 |
else if (typeof define == "function" && define.amd) // AMD |
|
25 |
define(["../../lib/codemirror"], mod); |
|
26 |
else // Plain browser env |
|
27 |
mod(CodeMirror); |
|
28 |
})(function(CodeMirror) { |
|
29 |
"use strict"; |
|
30 |
|
|
31 |
CodeMirror.registerHelper("lint", "json", function(text) { |
|
32 |
var found = []; |
|
33 |
jsonlint.parseError = function(str, hash) { |
|
34 |
var loc = hash.loc; |
|
35 |
found.push({from: CodeMirror.Pos(loc.first_line - 1, loc.first_column), |
|
36 |
to: CodeMirror.Pos(loc.last_line - 1, loc.last_column), |
|
37 |
message: str}); |
|
38 |
}; |
|
39 |
try { jsonlint.parse(text); } |
|
40 |
catch(e) {} |
|
41 |
return found; |
|
42 |
}); |
|
43 |
|
|
44 |
}); |