-
Notifications
You must be signed in to change notification settings - Fork 26
/
lintIndicator.js
89 lines (72 loc) · 2.92 KB
/
lintIndicator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* Interactive Linter Copyright (c) 2015 Miguel Castillo.
*
* Licensed under MIT
*/
define(function (require/*, exports, module*/) {
"use strict";
var DefaultDialogs = brackets.getModule("widgets/DefaultDialogs"),
Dialogs = brackets.getModule("widgets/Dialogs"),
StatusBar = brackets.getModule("widgets/StatusBar"),
StringUtils = brackets.getModule("utils/StringUtils"),
linterReporter = require("linterReporter"),
linterManager = require("linterManager"),
dialogTemplate = require("text!templates/errorDialog.html");
var $statusBarIndicator = $("<div> </div>");
var dialogContent;
var INDICATOR_TOOLTIPS = {
OK: "Interactive Linter found no problems in code.",
WARNING: "Interactive Linter found {0} problem(s) in code.",
ERROR: "Interactive Linter encountered a fatal error, click for more details.",
DISABLED: "Interactive Linter is disabled, or there are no linters for this file."
};
var INDICATOR_STATUS = {
OK: "okay",
WARNING: "warning",
ERROR: "error",
DISABLED: "inactive"
};
function setStatus(status) {
$statusBarIndicator.attr("status", status);
}
function indicatorClickHandler() {
if ($statusBarIndicator.attr("status") === INDICATOR_STATUS.ERROR) {
Dialogs.showModalDialog(DefaultDialogs.DIALOG_ID_ERROR, "Interactive Linter: Fatal Linter Error", dialogContent);
}
}
function fatalErrorHandler(message) {
if (message) {
setStatus(INDICATOR_STATUS.ERROR);
$statusBarIndicator.attr("title", INDICATOR_TOOLTIPS.ERROR);
dialogContent = Mustache.render(dialogTemplate, {
line: message.line,
character: message.character,
error: message.reason,
href: message.href
});
}
}
function lintMessageHandler(messages) {
if (messages && messages.length) {
setStatus(INDICATOR_STATUS.WARNING);
$statusBarIndicator.attr("title", StringUtils.format(INDICATOR_TOOLTIPS.WARNING, messages.length));
}
else {
setStatus(INDICATOR_STATUS.OK);
$statusBarIndicator.attr("title", INDICATOR_TOOLTIPS.OK);
}
}
StatusBar.addIndicator("interactive-linter-lint-indicator", $statusBarIndicator, true, "", "", "status-indent");
setStatus(INDICATOR_STATUS.DISABLED);
$(linterManager).on("linterNotFound", function () {
setStatus(INDICATOR_STATUS.DISABLED);
$statusBarIndicator.attr("title", INDICATOR_TOOLTIPS.DISABLED);
});
$(linterReporter).on("lintMessage", function (evt, messages) {
lintMessageHandler(messages);
});
$(linterReporter).on("fatalError", function (evt, message) {
fatalErrorHandler(message);
});
$statusBarIndicator.on("click", indicatorClickHandler);
});