Update node-red-nodes sample, analysis, storage and time nodes to use strict and pass jshint scan

This commit is contained in:
Dave C-J 2014-06-28 23:37:19 +01:00
parent 43dfded402
commit ebf950d818
6 changed files with 279 additions and 268 deletions

View File

@ -19,7 +19,8 @@
// Sample Node-RED node file
// Require main module
var RED = require(process.env.NODE_RED_HOME+"/red/red");
module.exports = function(RED) {
"use strict";
// The main node definition - most things happen in here
function SampleNode(n) {
@ -50,3 +51,4 @@ function SampleNode(n) {
// Register the node by name. This must be called before overriding any of the
// Node functions.
RED.nodes.registerType("sample",SampleNode);
}

View File

@ -14,9 +14,10 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
module.exports = function(RED) {
"use strict";
var badwords = require('badwords');
if (badwords.length == 0 ) { return; }
if (badwords.length === 0 ) { return; }
var badwordsRegExp = require('badwords/regexp');
function BadwordsNode(n) {
@ -29,3 +30,4 @@ function BadwordsNode(n) {
});
}
RED.nodes.registerType("badwords",BadwordsNode);
}

View File

@ -14,7 +14,8 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
module.exports = function(RED) {
"use strict";
var WordPos = require('wordpos');
var wordpos = new WordPos();
@ -29,3 +30,4 @@ function WordPOSNode(n) {
});
}
RED.nodes.registerType("wordpos",WordPOSNode);
}

View File

@ -14,7 +14,8 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
module.exports = function(RED) {
"use strict";
var lvldb = require('level');
function LevelNode(n) {
@ -22,7 +23,7 @@ function LevelNode(n) {
this.dbname = n.db;
var node = this;
lvldb(this.dbname, function(err, db) {
if (err) node.error(err);
if (err) { node.error(err); }
node.db = db;
});
this.on('close', function() {
@ -52,7 +53,7 @@ function LevelDBNodeIn(n) {
});
}
else {
if (typeof msg.topic !== 'string') node.error("msg.topic (the key is not defined");
if (typeof msg.topic !== 'string') { node.error("msg.topic (the key is not defined"); }
}
});
}
@ -78,12 +79,12 @@ function LevelDBNodeOut(n) {
}
else {
node.levelConfig.db.put(msg.topic, msg.payload, function(err) {
if (err) node.error(err);
if (err) { node.error(err); }
});
}
}
else {
if (typeof msg.topic !== 'string') node.error("msg.topic (the key is not defined");
if (typeof msg.topic !== 'string') { node.error("msg.topic (the key is not defined"); }
}
});
}
@ -92,3 +93,4 @@ function LevelDBNodeOut(n) {
}
}
RED.nodes.registerType("leveldb out",LevelDBNodeOut);
}

View File

@ -14,7 +14,8 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
module.exports = function(RED) {
"use strict";
var reconnect = RED.settings.mysqlReconnectTime || 30000;
var mysqldb = require('mysql');
var querystring = require('querystring');
@ -22,7 +23,7 @@ var querystring = require('querystring');
RED.httpAdmin.get('/MySQLdatabase/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) {
res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!="")}));
res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!=="")}));
} else {
res.send(JSON.stringify({}));
}
@ -41,12 +42,12 @@ RED.httpAdmin.post('/MySQLdatabase/:id',function(req,res) {
req.on('end', function(){
var newCreds = querystring.parse(body);
var credentials = RED.nodes.getCredentials(req.params.id)||{};
if (newCreds.user == null || newCreds.user == "") {
if (newCreds.user == null || newCreds.user === "") {
delete credentials.user;
} else {
credentials.user = newCreds.user;
}
if (newCreds.password == "") {
if (newCreds.password === "") {
delete credentials.password;
} else {
credentials.password = newCreds.password||credentials.password;
@ -65,15 +66,15 @@ function MySQLNode(n) {
this.connected = false;
this.connecting = false;
if (n.user) {
var credentials = {};
if (n.user) {
credentials.user = n.user;
credentials.password = n.pass;
RED.nodes.addCredentials(n.id,credentials);
this.user = n.user;
this.password = n.pass;
} else {
var credentials = RED.nodes.getCredentials(n.id);
credentials = RED.nodes.getCredentials(n.id);
if (credentials) {
this.user = credentials.user;
this.password = credentials.password;
@ -125,7 +126,7 @@ function MySQLNode(n) {
if (this.tick) { clearTimeout(this.tick); }
if (this.connection) {
node.connection.end(function(err) {
if (err) node.error(err);
if (err) { node.error(err); }
});
}
});
@ -153,7 +154,7 @@ function MysqlDBNodeIn(n) {
});
}
else {
if (typeof msg.topic !== 'string') node.error("msg.topic : the query is not defined as a string");
if (typeof msg.topic !== 'string') { node.error("msg.topic : the query is not defined as a string"); }
}
});
}
@ -193,3 +194,4 @@ RED.nodes.registerType("mysql",MysqlDBNodeIn);
//}
//}
//RED.nodes.registerType("mysql out",MysqlDBNodeOut);
}

View File

@ -15,6 +15,7 @@
**/
module.exports = function(RED) {
"use strict";
var SunCalc = require('suncalc');
function SunNode(n) {