small cleanup

This commit is contained in:
nightwing 2012-09-02 18:32:54 +04:00
commit 828e445a27
2 changed files with 47 additions and 36 deletions

View file

@ -47,7 +47,7 @@ var errorsRe = startRegex([
"Unexpected",
"Expected ",
"Confusing (plus|minus)",
"{a} unterminated regular expression",
"\\{a\\} unterminated regular expression",
"Unclosed ",
"Unmatched ",
"Unbegun comment",
@ -61,6 +61,7 @@ var infoRe = startRegex([
"Unexpected comma",
"Unexpected space",
"Missing radix parameter.",
"\\['\\{a\\}'\\] is better written in dot notation."
]);
var JavaScriptWorker = exports.JavaScriptWorker = function(sender) {
@ -76,24 +77,40 @@ oop.inherits(JavaScriptWorker, Mirror);
this.options = options || {
// undef: true,
// unused: true,
es5: true,
esnext: true,
devel: true,
browser: true,
node: true,
laxcomma: true,
laxbreak: true,
lastsemic: true,
onevar: false,
passfail: false,
maxerr: 100,
expr: true
expr: true,
multistr: true,
globalstrict: true
};
this.doc.getValue() && this.deferredUpdate.schedule(100);
};
this.changeOptions = function(newOptions) {
oop.mixin(this.options, newOptions);
this.doc.getValue() && this.deferredUpdate.schedule(100);
};
this.isValidJS = function(str) {
try {
// evaluated code can only create variables in this function
eval("throw 0;" + str);
} catch(e) {
if (e === 0)
return true;
}
return false
};
this.onUpdate = function() {
var value = this.doc.getValue();
value = value.replace(/^#!.*\n/, "\n");
@ -105,14 +122,7 @@ oop.inherits(JavaScriptWorker, Mirror);
// jshint reports many false errors
// report them as error only if code is actually invalid
var maxErrorLevel = "warning";
try {
eval("throw 0;" + value);
} catch(e) {
if (e != 0) {
maxErrorLevel = "error";
}
}
var maxErrorLevel = this.isValidJS(value) ? "warning" : "error";
// var start = new Date();
lint(value, this.options);
@ -129,7 +139,7 @@ oop.inherits(JavaScriptWorker, Mirror);
if (raw == "Missing semicolon.") {
var str = error.evidence.substr(error.character);
str = str.charAt(str.search(/\S/));
if (maxErrorLevel == "error" && str && /[\w\d{([]/.test(str)) {
if (maxErrorLevel == "error" && str && /[\w\d{(['"]/.test(str)) {
error.reason = 'Missing ";" before statement';
type = "error";
} else