1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Fix all jshint warnings in core code

This commit is contained in:
Nick O'Leary 2014-07-01 23:46:25 +01:00
parent c18119f26e
commit 649c82f7d7
9 changed files with 108 additions and 60 deletions

View File

@ -44,11 +44,31 @@ module.exports = function(grunt) {
},
all: [
'Gruntfile.js',
'public/red/**/*.js',
'red.js',
'red/**/*.js',
'nodes/**/*.js',
'public/red/**/*.js'
],
core: {
files: {
src: [
'Gruntfile.js',
'red.js',
'red/**/*.js'
]
}
},
nodes: {
files: {
src: [ 'nodes/**/*.js' ]
}
},
editor: {
files: {
src: [ 'public/red/**/*.js' ]
}
},
tests: {
files: {
src: ['test/*.js']
@ -65,6 +85,6 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.registerTask('default', ['jshint:tests','simplemocha']);
grunt.registerTask('all', ['jshint:all','default']);
grunt.registerTask('all', ['jshint:core','jshint:nodes','jshint:editor','default']);
};

View File

@ -90,7 +90,7 @@ function createLibrary(type) {
}).otherwise(function(err) {
util.log("[red] Error saving library entry '"+path+"' : "+err);
res.send(500);
});;
});
});
});
}

View File

@ -30,9 +30,9 @@ var log = module.exports = {
},
log: function(msg) {
for (var i in logHandlers) {
logHandlers.each(function() {
logHandlers[i].emit("log",msg);
}
});
}
}

View File

@ -66,7 +66,7 @@ Node.prototype.send = function(msg) {
} else if (!util.isArray(msg)) {
msg = [msg];
}
for (var i in this.wires) {
for (var i=0;i<this.wires.length;i++) {
var wires = this.wires[i];
if (i < msg.length) {
if (msg[i] != null) {
@ -85,10 +85,10 @@ Node.prototype.send = function(msg) {
// }
//} else {
// Multiple recipients, must send message copies
for (var j in wires) {
for (var j=0;j<wires.length;j++) {
var node = flows.get(wires[j]);
if (node) {
for (var k in msgs) {
for (var k=0;k<msgs.length;k++) {
var mm = msgs[k];
// Temporary fix for #97
// TODO: remove this http-node-specific fix somehow
@ -121,17 +121,23 @@ Node.prototype.receive = function(msg) {
Node.prototype.log = function(msg) {
var o = {level:'log',id:this.id, type:this.type, msg:msg};
if (this.name) o.name = this.name;
if (this.name) {
o.name = this.name;
}
this.emit("log",o);
}
Node.prototype.warn = function(msg) {
var o = {level:'warn',id:this.id, type:this.type, msg:msg};
if (this.name) o.name = this.name;
if (this.name) {
o.name = this.name;
}
this.emit("log",o);
}
Node.prototype.error = function(msg) {
var o = {level:'error',id:this.id, type:this.type, msg:msg};
if (this.name) o.name = this.name;
if (this.name) {
o.name = this.name;
}
this.emit("log",o);
}
/**

View File

@ -29,7 +29,7 @@ function getCredDef(type) {
}
function isRegistered(type) {
return getCredDef(type) != undefined;
return getCredDef(type) !== undefined;
}
function restPOST(type) {
@ -47,16 +47,18 @@ function restPOST(type) {
var definition = getCredDef(nodeType);
for (var cred in definition) {
if (newCreds[cred] == undefined) {
continue;
if (definition.hasOwnProperty(cred)) {
if (newCreds[cred] === undefined) {
continue;
}
if (definition[cred].type == "password" && newCreds[cred] == '__PWRD__') {
continue;
}
if (newCreds[cred] === '') {
delete credentials[cred];
}
credentials[cred] = newCreds[cred];
}
if (definition[cred].type == "password" && newCreds[cred] == '__PWRD__') {
continue;
}
if (newCreds[cred] == '') {
delete credentials[cred];
}
credentials[cred] = newCreds[cred];
}
Credentials.add(nodeID, credentials);
res.send(200);
@ -70,7 +72,7 @@ function restGET(type) {
var nodeID = req.params.id;
var credentials = Credentials.get(nodeID);
if (credentials == undefined) {
if (credentials === undefined) {
res.json({});
return;
}
@ -78,12 +80,14 @@ function restGET(type) {
var sendCredentials = {};
for (var cred in definition) {
if (definition[cred].type == "password") {
var key = 'has' + cred;
sendCredentials[key] = credentials[cred] != null && credentials[cred] != '';
continue;
if (definition.hasOwnProperty(cred)) {
if (definition[cred].type == "password") {
var key = 'has' + cred;
sendCredentials[key] = credentials[cred] != null && credentials[cred] !== '';
continue;
}
sendCredentials[cred] = credentials[cred] || '';
}
sendCredentials[cred] = credentials[cred] || '';
}
res.json(sendCredentials);
@ -128,10 +132,12 @@ module.exports = {
clean: function (getNode) {
var deletedCredentials = false;
for (var c in credentials) {
var n = getNode(c);
if (!n) {
deletedCredentials = true;
delete credentials[c];
if (credentials.hasOwnProperty(c)) {
var n = getNode(c);
if (!n) {
deletedCredentials = true;
delete credentials[c];
}
}
}
if (deletedCredentials) {

View File

@ -35,7 +35,7 @@ events.on('type-registered',function(type) {
missingTypes.splice(i,1);
util.log("[red] Missing type registered: "+type);
}
if (missingTypes.length == 0) {
if (missingTypes.length === 0) {
parseConfig();
}
}
@ -43,20 +43,22 @@ events.on('type-registered',function(type) {
var parseConfig = function() {
var i;
var nt;
missingTypes = [];
for (var i in activeConfig) {
for (i=0;i<activeConfig.length;i++) {
var type = activeConfig[i].type;
// TODO: remove workspace in next release+1
if (type != "workspace" && type != "tab") {
var nt = typeRegistry.get(type);
nt = typeRegistry.get(type);
if (!nt && missingTypes.indexOf(type) == -1) {
missingTypes.push(type);
}
}
};
}
if (missingTypes.length > 0) {
util.log("[red] Waiting for missing types to be registered:");
for (var i in missingTypes) {
for (i=0;i<missingType.length;i++) {
util.log("[red] - "+missingTypes[i]);
}
return;
@ -64,11 +66,11 @@ var parseConfig = function() {
util.log("[red] Starting flows");
events.emit("nodes-starting");
for (var i in activeConfig) {
for (i=0;i<activeConfig.length;i++) {
var nn = null;
// TODO: remove workspace in next release+1
if (activeConfig[i].type != "workspace" && activeConfig[i].type != "tab") {
var nt = typeRegistry.get(activeConfig[i].type);
nt = typeRegistry.get(activeConfig[i].type);
if (nt) {
try {
nn = new nt(activeConfig[i]);
@ -124,13 +126,15 @@ var flowNodes = module.exports = {
events.emit("nodes-stopping");
var promises = [];
for (var n in nodes) {
try {
var p = nodes[n].close();
if (p) {
promises.push(p);
if (nodes.hasOwnProperty(n)) {
try {
var p = nodes[n].close();
if (p) {
promises.push(p);
}
} catch(err) {
nodes[n].error(err);
}
} catch(err) {
nodes[n].error(err);
}
}
when.settle(promises).then(function() {
@ -142,7 +146,9 @@ var flowNodes = module.exports = {
},
each: function(cb) {
for (var n in nodes) {
cb(nodes[n]);
if (nodes.hasOwnProperty(n)) {
cb(nodes[n]);
}
}
},
addLogHandler: function(handler) {

View File

@ -90,13 +90,15 @@ function loadNodesFromModule(moduleDir,pkg) {
var promises = [];
var iconDirs = [];
for (var n in nodes) {
promises.push(loadNode(moduleDir,nodes[n],pkg.name+":"+n));
var iconDir = path.join(moduleDir,path.dirname(nodes[n]),"icons");
if (iconDirs.indexOf(iconDir) == -1) {
if (fs.existsSync(iconDir)) {
events.emit("node-icon-dir",iconDir);
iconDirs.push(iconDir);
};
if (nodes.hasOwnProperty(n)) {
promises.push(loadNode(moduleDir,nodes[n],pkg.name+":"+n));
var iconDir = path.join(moduleDir,path.dirname(nodes[n]),"icons");
if (iconDirs.indexOf(iconDir) == -1) {
if (fs.existsSync(iconDir)) {
events.emit("node-icon-dir",iconDir);
iconDirs.push(iconDir);
}
}
}
}
return promises;
@ -258,8 +260,10 @@ function registerConfig(config) {
var openTag = "<"+el.name;
var closeTag = "</"+el.name+">";
if (el.attribs) {
for (var i in el.attribs) {
openTag += " "+i+'="'+el.attribs[i]+'"';
for (var j in el.attribs) {
if (el.attribs.hasOwnProperty(j)) {
openTag += " "+i+'="'+el.attribs[j]+'"';
}
}
}
openTag += ">";
@ -288,8 +292,8 @@ var typeRegistry = module.exports = {
result += node_configs[i];
}
result += '<script type="text/javascript">';
for (var i=0;i<node_scripts.length;i++) {
result += node_scripts[i];
for (var j=0;j<node_scripts.length;j++) {
result += node_scripts[j];
}
result += '</script>';
return result;

View File

@ -127,7 +127,9 @@ function writeFile(root,path,meta,body,res) {
var fn = fspath.join(root,path);
var headers = "";
for (var i in meta) {
headers += "// "+i+": "+meta[i]+"\n";
if (meta.hasOwnProperty(i)) {
headers += "// "+i+": "+meta[i]+"\n";
}
}
mkdirp(fspath.dirname(fn), function (err) {
fs.writeFile(fn,headers+body,function(err) {
@ -255,7 +257,9 @@ var localfilesystem = {
var rootPath = fspath.join(libDir,type,path);
return promiseDir(root).then(function () {
return nodeFn.call(fs.lstat, rootPath).then(function(stats) {
if (stats.isFile()) return getFileBody(root,path);
if (stats.isFile()) {
return getFileBody(root,path);
}
if (path.substr(-1) == '/') {
path = path.substr(0,path.length-1);
}
@ -286,7 +290,9 @@ var localfilesystem = {
var fn = fspath.join(libDir, type, path);
var headers = "";
for (var i in meta) {
headers += "// "+i+": "+meta[i]+"\n";
if (meta.hasOwnProperty(i)) {
headers += "// "+i+": "+meta[i]+"\n";
}
}
return promiseDir(fspath.dirname(fn)).then(function () {
nodeFn.call(fs.writeFile, fn, headers+body);

View File

@ -49,7 +49,7 @@ function setupUI(settings) {
if (iconCache[req.params.icon]) {
res.sendfile(iconCache[req.params.icon]);
} else {
for (var p in icon_paths) {
for (var p=0;p<icon_paths.length;p++) {
var iconPath = path.join(icon_paths[p],req.params.icon);
if (fs.existsSync(iconPath)) {
res.sendfile(iconPath);