-
Notifications
You must be signed in to change notification settings - Fork 2
/
ContinuousCompilationController.js
64 lines (51 loc) · 3.05 KB
/
ContinuousCompilationController.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
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, $, setTimeout, clearTimeout */
define(function (require, exports, module) {
"use strict";
var JSLintError = require("JSLintError"),
JSLINT = require("JSLint/jslint"),
CodeMirrorErrorDisplayController = require("CodeMirrorErrorDisplayController");
var cssClassesForSeverityLevel = {};
cssClassesForSeverityLevel[JSLintError.SeverityLevelEnum.UNCLASSIFIED] = "cc-JSLint-unclassified-error";
cssClassesForSeverityLevel[JSLintError.SeverityLevelEnum.SYNTAX_ERROR] = "cc-JSLint-syntax-error";
cssClassesForSeverityLevel[JSLintError.SeverityLevelEnum.BAD_CODE_OR_PRACTICE] = "cc-JSLint-bad-code-error";
cssClassesForSeverityLevel[JSLintError.SeverityLevelEnum.WARNING] = "cc-JSLint-warning";
cssClassesForSeverityLevel[JSLintError.SeverityLevelEnum.JUST_STYLE] = "cc-JSLint-just-style-warning";
function compileCodeAndDisplayErrors(newCodeToCompile) {
if (newCodeToCompile === null) {
CodeMirrorErrorDisplayController.setErrorsToDisplay(null);
} else {
// If a line contains only whitespace, remove the whitespace
// This should be doable with a regexp: text.replace(/\r[\x20|\t]+\r/g, "\r\r");,
// but that doesn't work.
var i,
codeToCompileLines,
linesWithoutCompleteWhitespaceLines = newCodeToCompile.split("\n");
// JSLint complains about lines that just contain whitespace. We just remove those, because that's really over the top...
for (i = 0; i < linesWithoutCompleteWhitespaceLines.length; i++) {
if (!linesWithoutCompleteWhitespaceLines[i].match(/\S/)) {
linesWithoutCompleteWhitespaceLines[i] = "";
}
}
//codeToCompile = arr.join("\n");
codeToCompileLines = linesWithoutCompleteWhitespaceLines;
var passedJSLintCheck = JSLINT(codeToCompileLines, null); // no options => use the default options
if (passedJSLintCheck) {
CodeMirrorErrorDisplayController.setErrorsToDisplay(null);
} else {
var errorsToDisplay = JSLINT.errors.map(function (errorItem) {
if (errorItem === null) {
return undefined;
} // else
return new JSLintError(errorItem, codeToCompileLines);
});
errorsToDisplay = errorsToDisplay.filter(function (error) { return error !== undefined; });
CodeMirrorErrorDisplayController.setErrorsToDisplay(errorsToDisplay);
}
}
}
exports.compileCodeAndDisplayErrors = compileCodeAndDisplayErrors;
exports.setCodeMirrorToAddHighlightsTo = function (codeMirrorToUse) {
CodeMirrorErrorDisplayController.setCodeMirrorToAddHighlightsTo(codeMirrorToUse);
};
});