From f4fdebfba5c1ca5867ec86dbdd78c8898f5249ec Mon Sep 17 00:00:00 2001 From: dceejay Date: Thu, 5 Feb 2015 13:52:20 +0000 Subject: [PATCH] Misc tidy ups of jsHint "issues" for some node-red-nodes --- function/smooth/17-smooth.js | 80 ++++++++++++++++--------------- hardware/LEDborg/78-ledborg.js | 11 ++--- io/rawserial/26-rawserial.js | 2 +- parsers/msgpack/70-msgpack.js | 4 +- test/utility/exif/94-exif_spec.js | 23 ++++----- test/utility/exif/Gruntfile.js | 7 ++- 6 files changed, 63 insertions(+), 64 deletions(-) diff --git a/function/smooth/17-smooth.js b/function/smooth/17-smooth.js index dd8e39c2..0d432d65 100644 --- a/function/smooth/17-smooth.js +++ b/function/smooth/17-smooth.js @@ -14,46 +14,48 @@ * limitations under the License. **/ -var RED = require(process.env.NODE_RED_HOME + "/red/red"); +module.exports = function(RED) { + "use strict"; -function SmoothNode(n) { - RED.nodes.createNode(this, n); - this.action = n.action; - this.round = n.round || false; - this.count = Number(n.count); - var node = this; - var a = []; - var tot = 0; - var pop = 0; - var old = null; + function SmoothNode(n) { + RED.nodes.createNode(this, n); + this.action = n.action; + this.round = n.round || false; + this.count = Number(n.count); + var node = this; + var a = []; + var tot = 0; + var pop = 0; + var old = null; - this.on('input', function (msg) { - var n = Number(msg.payload); - if (!isNaN(n)) { - if ((node.action === "low") || (node.action === "high")) { - if (old == null) { old = n; } - old = old + (n - old) / node.count; - if (node.action === "low") { msg.payload = old; } - else { msg.payload = n - old; } + this.on('input', function (msg) { + var n = Number(msg.payload); + if (!isNaN(n)) { + if ((node.action === "low") || (node.action === "high")) { + if (old == null) { old = n; } + old = old + (n - old) / node.count; + if (node.action === "low") { msg.payload = old; } + else { msg.payload = n - old; } + } + else { + a.push(n); + if (a.length > node.count) { pop = a.shift(); } + if (node.action === "max") { + msg.payload = Math.max.apply(Math, a); + } + if (node.action === "min") { + msg.payload = Math.min.apply(Math, a); + } + if (node.action === "mean") { + tot = tot + n - pop; + msg.payload = tot / a.length; + } + } + if (node.round) { msg.payload = Math.round(msg.payload); } + node.send(msg); } - else { - a.push(n); - if (a.length > node.count) { pop = a.shift(); } - if (node.action === "max") { - msg.payload = Math.max.apply(Math, a); - } - if (node.action === "min") { - msg.payload = Math.min.apply(Math, a); - } - if (node.action === "mean") { - tot = tot + n - pop; - msg.payload = tot / a.length; - } - } - if (node.round) { msg.payload = Math.round(msg.payload); } - node.send(msg); - } - else { node.log("Not a number: "+msg.payload); } - }); + else { node.log("Not a number: "+msg.payload); } + }); + } + RED.nodes.registerType("smooth", SmoothNode); } -RED.nodes.registerType("smooth", SmoothNode); diff --git a/hardware/LEDborg/78-ledborg.js b/hardware/LEDborg/78-ledborg.js index f928e2fa..7b5b4f84 100644 --- a/hardware/LEDborg/78-ledborg.js +++ b/hardware/LEDborg/78-ledborg.js @@ -41,9 +41,6 @@ module.exports = function(RED) { // GPIO pins 11 (R), 13 (G), 15 (B). function LedBorgNode(n) { - RED.nodes.createNode(this,n); - var node = this; - RED.nodes.createNode(this,n); this.pin = n.pin; this.set = n.set || false; @@ -69,10 +66,10 @@ module.exports = function(RED) { } else if (p3.test(msg.payload)) { var c = msg.payload.split(","); - var r = Math.floor(parseInt(c[0])*100/256).toString(); - var g = Math.floor(parseInt(c[1])*100/256).toString(); - var b = Math.floor(parseInt(c[2])*100/256).toString(); - rgb = r+","+g+","+b; + var r1 = Math.floor(parseInt(c[0])*100/256).toString(); + var g1 = Math.floor(parseInt(c[1])*100/256).toString(); + var b1 = Math.floor(parseInt(c[2])*100/256).toString(); + rgb = r1+","+g1+","+b1; } else { // you can add fancy colours by name here if you want... diff --git a/io/rawserial/26-rawserial.js b/io/rawserial/26-rawserial.js index 86b2b2d1..5f25ecd2 100644 --- a/io/rawserial/26-rawserial.js +++ b/io/rawserial/26-rawserial.js @@ -23,9 +23,9 @@ module.exports = function(RED) { var pre = "\\\\.\\"; if (!plat.match(/^win/)) { + pre = ""; throw "Info : only needed for Windows boxes without serialport npm module installed."; //util.log("[26-rawserial.js] Info : only really needed for Windows boxes without serialport npm module installed."); - pre = ""; } function RawSerialInNode(n) { diff --git a/parsers/msgpack/70-msgpack.js b/parsers/msgpack/70-msgpack.js index f50d276b..e1396447 100644 --- a/parsers/msgpack/70-msgpack.js +++ b/parsers/msgpack/70-msgpack.js @@ -35,10 +35,10 @@ module.exports = function(RED) { } } else { - var l = JSON.stringify(msg.payload).length; + var le = JSON.stringify(msg.payload).length; msg.payload = msgpack.encode(msg.payload); node.send(msg); - node.status({text:l +" o->b "+ msg.payload.length}); + node.status({text:le +" o->b "+ msg.payload.length}); } }); } diff --git a/test/utility/exif/94-exif_spec.js b/test/utility/exif/94-exif_spec.js index 30087415..c5bdf9fe 100644 --- a/test/utility/exif/94-exif_spec.js +++ b/test/utility/exif/94-exif_spec.js @@ -23,7 +23,8 @@ var exifNode = require("../../../utility/exif/94-exif.js"); var helper = require('../../../../node-red/test/nodes/helper.js'); describe('exif node', function() { - + "use strict"; + beforeEach(function(done) { helper.startServer(done); }); @@ -34,43 +35,43 @@ describe('exif node', function() { }); it('extracts location data from Exif data of JPEG', function(done) { - + var exif = require('exif'); var ExifImage = exif.ExifImage; - + // the jpg file is a single black dot but it was originally a photo taken at IBM Hursley var data = fs.readFileSync("./exif_test_image.jpg", null); // extracting genuine exif data to be fed back as the result of the stubbed ExifImage constructor - + var eD; - + new ExifImage({ image : data }, function (error, exifData) { if(error) { done(error); } else { eD = exifData; } - + var flow = [{id:"exifNode1", type:"exif", wires:[["helperNode1"]]}, {id:"helperNode1", type:"helper"}]; - + helper.load(exifNode, flow, function() { var exifNode1 = helper.getNode("exifNode1"); var helperNode1 = helper.getNode("helperNode1"); - + helperNode1.on("input", function(msg) { msg.location.lat.should.equal(50.95624); // this data is stored in the jpg file msg.location.lon.should.equal(-1.36701); done(); }); - + var stub = sinon.stub(ExifImage.prototype, 'loadImage', function(error, callback) { stub.restore(); callback(null, eD); }); - + exifNode1.receive({payload:data}); }); }); - + }); }); diff --git a/test/utility/exif/Gruntfile.js b/test/utility/exif/Gruntfile.js index 80a4296e..1c9b7a5e 100644 --- a/test/utility/exif/Gruntfile.js +++ b/test/utility/exif/Gruntfile.js @@ -15,7 +15,8 @@ **/ module.exports = function(grunt) { - + "use strict"; + // Project configuration. grunt.initConfig({ simplemocha: { @@ -51,7 +52,5 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-lint-inline'); - grunt.registerTask('default', - ['jshint:all', 'simplemocha:all']); - + grunt.registerTask('default', ['jshint:all', 'simplemocha:all']); };