Permalink
Browse files

Adjust .jshintrc, try to get code to lint, give up

It complains about a number of things that are entirely valid,
or not even the case (see 'return after return' warning for lib/def.js).

It did catch a bug though, so there's an upside. Doesn't seem to be
configurable enough yet to suppress the bogus warnings, so I don't see
routine use working out yet.
  • Loading branch information...
1 parent 1bfa7f6 commit abc9a10bd3e2835d5a92b85af946ec84e1f50660 @marijnh marijnh committed Sep 8, 2014
Showing with 21 additions and 20 deletions.
  1. +2 −1 .jshintrc
  2. +4 −4 lib/infer.js
  3. +15 −15 lib/tern.js
View
@@ -20,5 +20,6 @@
"laxcomma" : false,
"laxbreak" : true,
"lastsemic": true,
- "globals" : {}
+ "globals" : {"tern": true, "acorn": true, "define": true},
+ "loopfunc" : true
}
View
@@ -107,15 +107,15 @@
hasType: function(type) {
return this.types.indexOf(type) > -1;
},
- isEmpty: function() { return this.types.length == 0; },
+ isEmpty: function() { return this.types.length === 0; },
getFunctionType: function() {
for (var i = this.types.length - 1; i >= 0; --i)
if (this.types[i] instanceof Fn) return this.types[i];
},
getType: function(guess) {
- if (this.types.length == 0 && guess !== false) return this.makeupType();
- if (this.types.length == 1) return this.types[0];
+ if (this.types.length === 0 && guess !== false) return this.makeupType();
+ if (this.types.length === 1) return this.types[0];
return canonicalType(this.types);
},
@@ -680,7 +680,7 @@
if (cx.origins.indexOf(origin) < 0) cx.origins.push(origin);
};
- var baseMaxWorkDepth = 20, reduceMaxWorkDepth = .0001;
+ var baseMaxWorkDepth = 20, reduceMaxWorkDepth = 0.0001;
function withWorklist(f) {
if (cx.workList) return f(cx.workList);
View
@@ -110,7 +110,7 @@
Server.prototype = signal.mixin({
addFile: function(name, /*optional*/ text, parent) {
// Don't crash when sloppy plugins pass non-existent parent ids
- if (parent && !parent in this.fileMap) parent = null;
+ if (parent && !(parent in this.fileMap)) parent = null;
ensureFile(this, name, parent, text);
},
delFile: function(name) {
@@ -163,7 +163,7 @@
},
finishAsyncAction: function(err) {
if (err) this.asyncError = err;
- if (--this.pending == 0) this.signal("everythingFetched");
+ if (--this.pending === 0) this.signal("everythingFetched");
}
});
@@ -259,9 +259,8 @@
function fetchAll(srv, c) {
var done = true, returned = false;
- for (var i = 0; i < srv.files.length; ++i) {
- var file = srv.files[i];
- if (file.text != null) continue;
+ srv.files.forEach(function(file) {
+ if (file.text != null) return;
if (srv.options.async) {
done = false;
srv.options.getFile(file.name, function(err, text) {
@@ -274,7 +273,7 @@
updateText(file, srv.options.getFile(file.name) || "", srv);
} catch (e) { return c(e); }
}
- }
+ });
if (done) c();
}
@@ -375,6 +374,7 @@
var line = firstLine(file.text);
var foundPos = findMatchingPosition(line, realFile.text, offset);
var pos = foundPos == null ? Math.max(0, realFile.text.lastIndexOf("\n", offset)) : foundPos;
+ var inObject, atFunction;
infer.withContext(srv.cx, function() {
infer.purge(file.name, pos, pos + file.text.length);
@@ -383,13 +383,13 @@
if (m = text.match(/(?:"([^"]*)"|([\w$]+))\s*:\s*function\b/)) {
var objNode = walk.findNodeAround(file.backing.ast, pos, "ObjectExpression");
if (objNode && objNode.node.objType)
- var inObject = {type: objNode.node.objType, prop: m[2] || m[1]};
+ inObject = {type: objNode.node.objType, prop: m[2] || m[1]};
}
if (foundPos && (m = line.match(/^(.*?)\bfunction\b/))) {
var cut = m[1].length, white = "";
for (var i = 0; i < cut; ++i) white += " ";
text = white + text.slice(cut);
- var atFunction = true;
+ atFunction = true;
}
var scopeStart = infer.scopeAt(realFile.ast, pos, realFile.scope);
@@ -499,8 +499,8 @@
while (curLine < line) {
++curLine;
pos = text.indexOf("\n", pos) + 1;
- if (pos == 0) return null;
- if (curLine % offsetSkipLines == 0) offsets.push(pos);
+ if (pos === 0) return null;
+ if (curLine % offsetSkipLines === 0) offsets.push(pos);
}
return pos;
}
@@ -592,7 +592,7 @@
// out when no prefix is provided.
if (query.omitObjectPrototype !== false && obj == srv.cx.protos.Object && !word) return;
if (query.filter !== false && word &&
- (query.caseInsensitive ? prop.toLowerCase() : prop).indexOf(word) != 0) return;
+ (query.caseInsensitive ? prop.toLowerCase() : prop).indexOf(word) !== 0) return;
for (var i = 0; i < completions.length; ++i) {
var c = completions[i];
if ((wrapAsObjs ? c.name : c) == prop) return;
@@ -671,7 +671,7 @@
function findProperties(srv, query) {
var prefix = query.prefix, found = [];
for (var prop in srv.cx.props)
- if (prop != "<i>" && (!prefix || prop.indexOf(prefix) == 0)) found.push(prop);
+ if (prop != "<i>" && (!prefix || prop.indexOf(prefix) === 0)) found.push(prop);
if (query.sort !== false) found.sort(compareCompletions);
return {completions: found};
}
@@ -695,7 +695,7 @@
};
function findTypeAt(_srv, query, file) {
- var expr = findExpr(file, query);
+ var expr = findExpr(file, query), exprName;
infer.resetGuessing();
var type = infer.expressionType(expr);
if (query.preferFunction)
@@ -704,9 +704,9 @@
type = type.getType();
if (expr.node.type == "Identifier")
- var exprName = expr.node.name;
+ exprName = expr.node.name;
else if (expr.node.type == "MemberExpression" && !expr.node.computed)
- var exprName = expr.node.property.name;
+ exprName = expr.node.property.name;
if (query.depth != null && typeof query.depth != "number")
throw ternError(".query.depth must be a number");

0 comments on commit abc9a10

Please sign in to comment.