Linter Demo
x
1
var widgets = []
2
function updateHints() {
3
editor.operation(function(){
4
for (var i = 0; i < widgets.length; ++i)
5
editor.removeLineWidget(widgets[i]);
6
widgets.length = 0;
7
8
JSHINT(editor.getValue());
9
for (var i = 0; i < JSHINT.errors.length; ++i) {
10
var err = JSHINT.errors[i];
11
if (!err) continue;
12
var msg = document.createElement("div");
13
var icon = msg.appendChild(document.createElement("span"));
14
icon.innerHTML = "!!";
15
icon.className = "lint-error-icon";
16
msg.appendChild(document.createTextNode(err.reason));
17
msg.className = "lint-error";
18
widgets.push(editor.addLineWidget(err.line - 1, msg, {coverGutter: false, noHScroll: true}));
19
}
20
});
21
var info = editor.getScrollInfo();
22
var after = editor.charCoords({line: editor.getCursor().line + 1, ch: 0}, "local").top;
23
if (info.top + info.clientHeight < after)
24
editor.scrollTo(null, after - info.clientHeight + 3);
25
}
26
21
1
[
2
{
3
_id: "post 1",
4
"author": "Bob",
5
"content": "...",
6
"page_views": 5
7
},
8
{
9
"_id": "post 2",
10
"author": "Bob",
11
"content": "...",
12
"page_views": 9
13
},
14
{
15
"_id": "post 3",
16
"author": "Bob",
17
"content": "...",
18
"page_views": 8
19
}
20
]
21