From 62cbae7cffde02ca8a81c845d0ec1c3936acd4e0 Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Tue, 14 Apr 2015 21:49:12 -0700 Subject: [PATCH] Switch to ESLint for linting --- .eslintrc | 52 ++++++++++++++++ .jshintrc | 38 ------------ .travis.yml | 2 +- Makefile | 3 +- examples/.eslintrc | 2 + examples/api/api.js | 4 +- examples/conway_sphero/conway_sphero.js | 8 +-- .../conway_sphero/fluent-conway_sphero.js | 8 +-- examples/hello/hello.js | 4 +- examples/leap_ardrone/leap_ardrone.js | 62 +++++++++---------- examples/sf-sphero/sf-sphero.js | 5 +- examples/sphero-pebble-sf/sphero-pebble-sf.js | 2 +- .../sphero_shakeometer/sphero_shakeometer.js | 2 +- examples/travis/travis.js | 4 ++ lib/basestar.js | 2 +- lib/cylon.js | 5 +- lib/driver.js | 2 + lib/io/digital-pin.js | 4 +- lib/io/utils.js | 2 +- lib/logger.js | 2 +- lib/registry.js | 10 +-- lib/robot.js | 2 +- lib/utils.js | 6 +- lib/utils/helpers.js | 34 +++++----- lib/utils/monkey-patches.js | 4 +- package.json | 3 +- spec/.eslintrc | 7 +++ spec/helper.js | 16 ++--- spec/lib/adaptor.spec.js | 1 - spec/lib/basestar.spec.js | 12 ++-- spec/lib/cylon.spec.js | 17 +++-- spec/lib/digital-pin.spec.js | 4 +- spec/lib/driver.spec.js | 7 +-- spec/lib/io/utils.js | 1 - spec/lib/logger.spec.js | 1 - spec/lib/logger/basic_logger.spec.js | 1 - spec/lib/registry.spec.js | 1 - spec/lib/robot.spec.js | 9 +-- spec/lib/utils.spec.js | 3 +- spec/lib/utils/helpers.spec.js | 12 ++-- spec/support/mock_module.js | 4 +- 41 files changed, 194 insertions(+), 174 deletions(-) create mode 100644 .eslintrc delete mode 100644 .jshintrc create mode 100644 examples/.eslintrc create mode 100644 spec/.eslintrc diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..39bd36a --- /dev/null +++ b/.eslintrc @@ -0,0 +1,52 @@ +env: + node: true + +globals: + every: true + after: true + constantly: true + expect: true + source: true + stub: true + spy: true + chai: true + sinon: true + +rules: + camelcase: [2, {properties: "always"}] + comma-dangle: "always-multiline" + comma-spacing: [2, {before: false, after: true}] + comma-style: [2, "last"] + handle-callback-err: [2, "^.*(e|E)rr" ] + indent: [2, 2] + key-spacing: [2, { beforeColon: false, afterColon: true }] + max-depth: [1, 3] + max-len: [1, 80, 4] + max-nested-callbacks: [1, 3] + no-cond-assign: 2 + no-constant-condition: 2 + no-dupe-args: 2 + no-dupe-keys: 2 + no-else-return: 2 + no-empty: 2 + no-lonely-if: 2 + no-multiple-empty-lines: 2 + no-nested-ternary: 2 + no-reserved-keys: 2 + no-self-compare: 2 + no-sync: 1 + no-throw-literal: 2 + no-underscore-dangle: 0 + quote-props: [2, "as-needed"] + quotes: [2, "double", "avoid-escape"] + radix: 2 + semi-spacing: [2, {before: false, after: true}] + semi: [2, "always"] + space-after-keywords: [2, "always"] + space-before-blocks: [2, "always"] + space-before-function-paren: [1, "never"] + space-in-parens: [2, "never"] + spaced-line-comment: [1, "always"] + strict: [2, "global"] + valid-jsdoc: 2 + yoda: [2, "never"] diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 89a5c96..0000000 --- a/.jshintrc +++ /dev/null @@ -1,38 +0,0 @@ -{ - "node": true, - - "globals": { - "every": true, - "after": true, - "constantly": true, - - "it": true, - "expect": true, - "source": true, - "describe": true, - "context": true, - "beforeEach": true, - "afterEach": true, - "stub": true, - "spy": true, - "chai": true, - "sinon": true - }, - - "boss": true, - "curly": true, - "eqeqeq": true, - "eqnull": true, - "immed": true, - "indent": 2, - "latedef": true, - "maxlen": 80, - "newcap": true, - "noarg": true, - "nonew": true, - "quotmark": "double", - "strict": true, - "sub": true, - "undef": true, - "unused": true -} diff --git a/.travis.yml b/.travis.yml index 320c337..d1e84d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ node_js: before_install: - "mkdir -p ~/.npm" before_script: - - npm install -g istanbul jshint codeclimate-test-reporter + - npm install -g istanbul codeclimate-test-reporter script: - make ci - CODECLIMATE_REPO_TOKEN=d3aad610220b6eaf4f51e38393c1b62586b1d68b898b42e418d9c2a8e0a7cb0d codeclimate < coverage/lcov.info diff --git a/Makefile b/Makefile index 95d2cfa..577e072 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,4 @@ BIN := ./node_modules/.bin -FILES := $(shell find lib spec/lib examples -type f -name "*.js") TEST_FILES := spec/helper.js $(shell find spec/lib -type f -name "*.js") VERSION := $(shell node -e "console.log(require('./package.json').version)") @@ -18,7 +17,7 @@ cover: @istanbul cover $(BIN)/_mocha $(TEST_FILES) --report lcovonly -- -R spec lint: - @jshint $(FILES) + @eslint lib spec examples ci: lint cover diff --git a/examples/.eslintrc b/examples/.eslintrc new file mode 100644 index 0000000..bd6eac6 --- /dev/null +++ b/examples/.eslintrc @@ -0,0 +1,2 @@ +rules: + camelcase: 0 diff --git a/examples/api/api.js b/examples/api/api.js index 3ded68c..574a8df 100644 --- a/examples/api/api.js +++ b/examples/api/api.js @@ -10,8 +10,8 @@ Cylon.api({ }); var bots = { - "Thelma": "/dev/rfcomm0", - "Louise": "/dev/rfcomm1" + Thelma: "/dev/rfcomm0", + Louise: "/dev/rfcomm1" }; Object.keys(bots).forEach(function(name) { diff --git a/examples/conway_sphero/conway_sphero.js b/examples/conway_sphero/conway_sphero.js index b0913cc..66c793e 100644 --- a/examples/conway_sphero/conway_sphero.js +++ b/examples/conway_sphero/conway_sphero.js @@ -6,10 +6,10 @@ var Green = 0x0000FF, Red = 0xFF0000; var bots = { - "Thelma": "/dev/rfcomm0", - "Louise": "/dev/rfcomm1", - "Grace": "/dev/rfcomm2", - "Ada": "/dev/rfcomm3" + Thelma: "/dev/rfcomm0", + Louise: "/dev/rfcomm1", + Grace: "/dev/rfcomm2", + Ada: "/dev/rfcomm3" }; Object.keys(bots).forEach(function(name) { diff --git a/examples/conway_sphero/fluent-conway_sphero.js b/examples/conway_sphero/fluent-conway_sphero.js index 51134e7..29b04a1 100644 --- a/examples/conway_sphero/fluent-conway_sphero.js +++ b/examples/conway_sphero/fluent-conway_sphero.js @@ -6,10 +6,10 @@ var Green = 0x0000FF, Red = 0xFF0000; var bots = { - "Thelma": "/dev/rfcomm0", - "Louise": "/dev/rfcomm1", - "Grace": "/dev/rfcomm2", - "Ada": "/dev/rfcomm3" + Thelma: "/dev/rfcomm0", + Louise: "/dev/rfcomm1", + Grace: "/dev/rfcomm2", + Ada: "/dev/rfcomm3" }; Object.keys(bots).forEach(function(name) { diff --git a/examples/hello/hello.js b/examples/hello/hello.js index 663a4ed..0718d73 100644 --- a/examples/hello/hello.js +++ b/examples/hello/hello.js @@ -18,12 +18,12 @@ Cylon.robot({ }, work: function(my) { - every((1).seconds(), function(){ + every((1).seconds(), function() { console.log("Hello, human!"); console.log(my.ping.ping()); }); - after((5).seconds(), function(){ + after((5).seconds(), function() { console.log("I've been at your command for 5 seconds now."); }); } diff --git a/examples/leap_ardrone/leap_ardrone.js b/examples/leap_ardrone/leap_ardrone.js index a878cda..dbb6d7e 100644 --- a/examples/leap_ardrone/leap_ardrone.js +++ b/examples/leap_ardrone/leap_ardrone.js @@ -33,9 +33,9 @@ Cylon.robot({ }, devices: { - drone: { driver: "ardrone", connection:"ardrone" }, - leapmotion: { driver: "leapmotion", connection:"leapmotion" }, - keyboard: { driver: "keyboard", connection:"keyboard" } + drone: { driver: "ardrone", connection: "ardrone" }, + leapmotion: { driver: "leapmotion", connection: "leapmotion" }, + keyboard: { driver: "keyboard", connection: "keyboard" } }, work: function(my) { @@ -92,11 +92,11 @@ Cylon.robot({ signal = handStartDirection[0] - hand.direction[0]; value = (horizontal - TURN_TRESHOLD) * TURN_SPEED_FACTOR; - if (signal > 0){ + if (signal > 0) { my.drone.counterClockwise(value); } - if (signal < 0){ + if (signal < 0) { my.drone.clockwise(value); } } @@ -132,51 +132,51 @@ Cylon.robot({ } if (hand.palmNormal[2] < 0) { - value = Math.abs( - Math.round(hand.palmNormal[2] * 10 - DIRECTION_THRESHOLD) * - DIRECTION_SPEED_FACTOR - ); + value = Math.abs( + Math.round(hand.palmNormal[2] * 10 - DIRECTION_THRESHOLD) * + DIRECTION_SPEED_FACTOR + ); - my.drone.back(value); + my.drone.back(value); } } // DIRECTION LEFT/RIGHT - if ((Math.abs(hand.palmNormal[0])>DIRECTION_THRESHOLD)) { + if (Math.abs(hand.palmNormal[0]) > DIRECTION_THRESHOLD) { if (hand.palmNormal[0] > 0) { - value = Math.abs( - Math.round(hand.palmNormal[0] * 10 + DIRECTION_THRESHOLD) * - DIRECTION_SPEED_FACTOR - ); + value = Math.abs( + Math.round(hand.palmNormal[0] * 10 + DIRECTION_THRESHOLD) * + DIRECTION_SPEED_FACTOR + ); - my.drone.left(value); + my.drone.left(value); } if (hand.palmNormal[0] < 0) { - value = Math.abs( - Math.round(hand.palmNormal[0] * 10 - DIRECTION_THRESHOLD) * - DIRECTION_SPEED_FACTOR - ); + value = Math.abs( + Math.round(hand.palmNormal[0] * 10 - DIRECTION_THRESHOLD) * + DIRECTION_SPEED_FACTOR + ); - my.drone.right(value); + my.drone.right(value); } } // AUTO FREEZE if ( - // within left/right threshold - (Math.abs(hand.palmNormal[0]) < DIRECTION_THRESHOLD) && + // within left/right threshold + (Math.abs(hand.palmNormal[0]) < DIRECTION_THRESHOLD) && - // within forward/back threshold - (Math.abs(hand.palmNormal[2]) < DIRECTION_THRESHOLD) && + // within forward/back threshold + (Math.abs(hand.palmNormal[2]) < DIRECTION_THRESHOLD) && - // within up/down threshold - Math.abs(hand.palmPosition[1] - handStartPosition[1]) < - UP_CONTROL_THRESHOLD && + // within up/down threshold + Math.abs(hand.palmPosition[1] - handStartPosition[1]) < + UP_CONTROL_THRESHOLD && - // within turn threshold - Math.abs(handStartDirection[0] - hand.direction[0]) < - TURN_TRESHOLD) { + // within turn threshold + Math.abs(handStartDirection[0] - hand.direction[0]) < + TURN_TRESHOLD) { my.drone.stop(); } } diff --git a/examples/sf-sphero/sf-sphero.js b/examples/sf-sphero/sf-sphero.js index c46904b..054a6c9 100644 --- a/examples/sf-sphero/sf-sphero.js +++ b/examples/sf-sphero/sf-sphero.js @@ -26,8 +26,9 @@ Cylon.robot({ my.salesforce.on("start", function() { my.salesforce.subscribe("/topic/SpheroMsgOutbound", function(data) { var msg = "Sphero: " + data.sobject.Sphero_Name__c + ","; - msg += "Bucks: " + data.sobject.Bucks__c + ","; - msg += "SM_Id: " + data.sobject.Id; + + msg += "Bucks: " + data.sobject.Bucks__c + ","; + msg += "SM_Id: " + data.sobject.Id; console.log(msg); diff --git a/examples/sphero-pebble-sf/sphero-pebble-sf.js b/examples/sphero-pebble-sf/sphero-pebble-sf.js index 8e88b7e..baaed56 100644 --- a/examples/sphero-pebble-sf/sphero-pebble-sf.js +++ b/examples/sphero-pebble-sf/sphero-pebble-sf.js @@ -155,7 +155,7 @@ bots.forEach(function(bot) { bucks: "" + (my.totalBucks++) }); - var sf = Cylon.robots["salesforce"]; + var sf = Cylon.robots.salesforce; sf.devices.salesforce.push("SpheroController", "POST", data); }); } diff --git a/examples/sphero_shakeometer/sphero_shakeometer.js b/examples/sphero_shakeometer/sphero_shakeometer.js index fdadcad..fc09df7 100644 --- a/examples/sphero_shakeometer/sphero_shakeometer.js +++ b/examples/sphero_shakeometer/sphero_shakeometer.js @@ -17,7 +17,7 @@ Cylon.robot({ my.sphero.setDataStreaming(["velocity"], { n: 40, m: 1, pcnt: 0 }); my.sphero.on("data", function(data) { - if(!changingColor) { + if (!changingColor) { var x = Math.abs(data[0]), y = Math.abs(data[1]); diff --git a/examples/travis/travis.js b/examples/travis/travis.js index 9f815e6..05e1929 100644 --- a/examples/travis/travis.js +++ b/examples/travis/travis.js @@ -23,6 +23,10 @@ Cylon.robot({ my.sphero.setColor("blue", true); travis.repos({ owner_name: user, name: name }, function(err, res) { + if (err) { + console.log(err); + } + if (res.repo === undefined) { my.sphero.setColor("blue", true); } switch (res.repo.last_build_state) { diff --git a/lib/basestar.js b/lib/basestar.js index 085dc26..999831f 100644 --- a/lib/basestar.js +++ b/lib/basestar.js @@ -43,7 +43,7 @@ Basestar.prototype.proxyMethods = Utils.proxyFunctionsToObject; Basestar.prototype.respond = function(event, callback, err) { var args = Array.prototype.slice.call(arguments, 3); - if (!!err) { + if (err) { this.emit("error", err); } else { this.emit.apply(this, [event].concat(args)); diff --git a/lib/cylon.js b/lib/cylon.js index 369373f..7998e3b 100644 --- a/lib/cylon.js +++ b/lib/cylon.js @@ -179,8 +179,9 @@ Cylon.toJSON = function() { }; if (process.platform === "win32") { - var readline = require("readline"), - io = { input: process.stdin, output: process.stdout }; + var readline = require("readline"); + + var io = { input: process.stdin, output: process.stdout }; readline.createInterface(io).on("SIGINT", function() { process.emit("SIGINT"); diff --git a/lib/driver.js b/lib/driver.js index 2d9328d..d2735dd 100644 --- a/lib/driver.js +++ b/lib/driver.js @@ -6,6 +6,8 @@ * Licensed under the Apache 2.0 license. */ +/* eslint camelcase: 0 */ + "use strict"; var Basestar = require("./basestar"), diff --git a/lib/io/digital-pin.js b/lib/io/digital-pin.js index 2f398a2..9d9e205 100644 --- a/lib/io/digital-pin.js +++ b/lib/io/digital-pin.js @@ -6,6 +6,8 @@ * Licensed under the Apache 2.0 license. */ +/* eslint no-sync: 0 */ + "use strict"; var FS = require("fs"), @@ -90,7 +92,7 @@ DigitalPin.prototype.digitalRead = function(interval) { var error = "Error occurred while reading from pin " + this.pinNum; this.emit("error", error); } else { - var readData = parseInt(data.toString()); + var readData = parseInt(data.toString(), 10); this.emit("digitalRead", readData); } }.bind(this)); diff --git a/lib/io/utils.js b/lib/io/utils.js index 483f9f7..1756e13 100644 --- a/lib/io/utils.js +++ b/lib/io/utils.js @@ -22,7 +22,7 @@ module.exports = { var pulseWidthMin = pulseWidth.min * 1000, pulseWidthMax = pulseWidth.max * 1000; - maxDuty = pulseWidthMax - pulseWidthMin; + maxDuty = pulseWidthMax - pulseWidthMin; duty = Math.round(pulseWidthMin + (maxDuty * scaledDuty)); } else { duty = Math.round(period * scaledDuty); diff --git a/lib/logger.js b/lib/logger.js index 1d66323..511dcbf 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -22,7 +22,7 @@ var Logger = module.exports = { } var logger = Config.logging.logger, - level = Config.logging.level || "info"; + level = Config.logging.level || "info"; // --debug CLI flag overrides any other option if (_.includes(process.argv, "--debug")) { diff --git a/lib/registry.js b/lib/registry.js index 4c72f7f..6684fba 100644 --- a/lib/registry.js +++ b/lib/registry.js @@ -20,7 +20,7 @@ require("./test/ping"); var missingModuleError = function(module) { var str = "Cannot find the '" + module + "' module.\n"; str += "This problem might be fixed by installing it with "; - str +="'npm install " + module + "' and trying again."; + str += "'npm install " + module + "' and trying again."; console.log(str); @@ -97,10 +97,12 @@ var Registry = module.exports = { search: function(entry, value) { for (var name in this.data) { - var repo = this.data[name]; + if (this.data.hasOwnProperty(name)) { + var repo = this.data[name]; - if (repo[entry] && _.includes(repo[entry], value)) { - return repo.module; + if (repo[entry] && _.includes(repo[entry], value)) { + return repo.module; + } } } diff --git a/lib/robot.js b/lib/robot.js index 9256ea5..30dcda2 100644 --- a/lib/robot.js +++ b/lib/robot.js @@ -299,7 +299,7 @@ Robot.prototype.start = function(callback) { this.startDevices, start ], function(err, results) { - if (!!err) { + if (err) { this.log("fatal", "An error occured while trying to start the robot:"); this.log("fatal", err); diff --git a/lib/utils.js b/lib/utils.js index fc0a411..fa94b6d 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -70,10 +70,10 @@ var Utils = module.exports = { // Returns a function sleep: function sleep(ms) { var start = Date.now(), - i; + i = 0; - while(Date.now() < start + ms) { - i = 0; + while (Date.now() < start + ms) { + i = i.toString(); } }, diff --git a/lib/utils/helpers.js b/lib/utils/helpers.js index b84135c..0146dc1 100644 --- a/lib/utils/helpers.js +++ b/lib/utils/helpers.js @@ -29,10 +29,8 @@ function extend(base, source) { base[i] = e; } else if (typeof e === "object") { base[i] = extend(base[i], e); - } else { - if (!~base.indexOf(e)) { - base.push(e); - } + } else if (!~base.indexOf(e)) { + base.push(e); } }); } else { @@ -41,12 +39,10 @@ function extend(base, source) { for (key in source) { if (typeof source[key] !== "object" || !source[key]) { base[key] = source[key]; + } else if (base[key]) { + extend(base[key], source[key]); } else { - if (base[key]) { - extend(base[key], source[key]); - } else { - base[key] = source[key]; - } + base[key] = source[key]; } } } @@ -70,14 +66,14 @@ function isA(type) { } extend(H, { - isObject: isA("Object"), + isObject: isA("Object"), isObjectLoose: function(thing) { return typeof thing === "object"; }, - isFunction: isA("Function"), - isArray: isA("Array"), - isString: isA("String"), - isNumber: isA("Number"), - isArguments: isA("Arguments"), - isUndefined: isA("Undefined") + isFunction: isA("Function"), + isArray: isA("Array"), + isString: isA("String"), + isNumber: isA("Number"), + isArguments: isA("Arguments"), + isUndefined: isA("Undefined") }); function iterate(thing, fn, thisVal) { @@ -92,8 +88,6 @@ function iterate(thing, fn, thisVal) { fn.call(thisVal, value, key); } } - - return []; } function pluck(collection, key) { @@ -165,8 +159,8 @@ function reduce(collection, iteratee, accumulator, thisVal) { } } - iterate(collection, function(object, key) { - accumulator = iteratee.call(thisVal, accumulator, object, key); + iterate(collection, function(object, name) { + accumulator = iteratee.call(thisVal, accumulator, object, name); }); return accumulator; diff --git a/lib/utils/monkey-patches.js b/lib/utils/monkey-patches.js index e38f310..5d1080e 100644 --- a/lib/utils/monkey-patches.js +++ b/lib/utils/monkey-patches.js @@ -6,6 +6,8 @@ * Licensed under the Apache 2.0 license. */ +/* eslint no-extend-native: 0 */ + "use strict"; var max = Math.max, @@ -68,7 +70,7 @@ module.exports.install = function() { return 1; } - if (val < 0){ + if (val < 0) { return 0; } diff --git a/package.json b/package.json index 1c3230c..20fb20e 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "sinon-chai": "2.7.0", "chai": "2.2.0", "mocha": "2.2.4", - "sinon": "1.14.1" + "sinon": "1.14.1", + "eslint": "0.19.0" }, "dependencies": { diff --git a/spec/.eslintrc b/spec/.eslintrc new file mode 100644 index 0000000..7faa7ae --- /dev/null +++ b/spec/.eslintrc @@ -0,0 +1,7 @@ +env: + mocha: true + +rules: + no-unused-expressions: 0 + max-nested-callbacks: 0 + camelcase: 0 diff --git a/spec/helper.js b/spec/helper.js index 8d523d1..35d68e4 100644 --- a/spec/helper.js +++ b/spec/helper.js @@ -1,12 +1,12 @@ -'use strict'; +"use strict"; -process.env.NODE_ENV = 'test'; +process.env.NODE_ENV = "test"; -var path = require('path'); +var path = require("path"); -var chai = require('chai'), - sinon = require('sinon'), - sinonChai = require('sinon-chai'); +var chai = require("chai"), + sinon = require("sinon"), + sinonChai = require("sinon-chai"); chai.use(sinonChai); @@ -23,10 +23,10 @@ global.stub = sinon.stub; // convenience function to require modules in lib directory global.source = function(module) { - return require(path.normalize('./../lib/' + module)); + return require(path.normalize("./../lib/" + module)); }; -var Cylon = source('cylon'); +var Cylon = source("cylon"); Cylon.config({ mode: "manual", diff --git a/spec/lib/adaptor.spec.js b/spec/lib/adaptor.spec.js index 28fa930..c19342c 100644 --- a/spec/lib/adaptor.spec.js +++ b/spec/lib/adaptor.spec.js @@ -1,4 +1,3 @@ -/* jshint expr:true */ "use strict"; var Adaptor = source("adaptor"), diff --git a/spec/lib/basestar.spec.js b/spec/lib/basestar.spec.js index 4fd1800..4280543 100644 --- a/spec/lib/basestar.spec.js +++ b/spec/lib/basestar.spec.js @@ -1,4 +1,3 @@ -/* jshint expr:true */ "use strict"; var Basestar = source("basestar"), @@ -82,11 +81,16 @@ describe("Basestar", function() { errListener = spy(); child = new Child(); child.on("error", errListener); - child.respond("event", callback, - "Error on event!", "arg1", 2, { three: true }); + child.respond( + "event", + callback, + "Error on event!", + "arg1", + 2, + { three: true }); }); - it ("emits an error event", function() { + it("emits an error event", function() { expect(errListener).to.be.calledWith("Error on event!"); }); }); diff --git a/spec/lib/cylon.spec.js b/spec/lib/cylon.spec.js index 5e67553..75fdd04 100644 --- a/spec/lib/cylon.spec.js +++ b/spec/lib/cylon.spec.js @@ -1,4 +1,3 @@ -/* jshint expr:true */ "use strict"; var Cylon = source("cylon"), @@ -46,7 +45,7 @@ describe("Cylon", function() { var robot = Cylon.robot(opts); expect(robot.toString()).to.be.eql("[Robot name='Ultron']"); - expect(Cylon.robots["Ultron"]).to.be.eql(robot); + expect(Cylon.robots.Ultron).to.be.eql(robot); }); it("avoids duplicating names", function() { @@ -99,8 +98,8 @@ describe("Cylon", function() { bot2 = { start: spy() }; Cylon.robots = { - "bot1": bot1, - "bot2": bot2 + bot1: bot1, + bot2: bot2 }; Cylon.start(); @@ -163,8 +162,8 @@ describe("Cylon", function() { bot2 = { halt: spy() }; Cylon.robots = { - "bot1": bot1, - "bot2": bot2 + bot1: bot1, + bot2: bot2 }; Cylon.halt(); @@ -175,14 +174,14 @@ describe("Cylon", function() { }); describe("#toJSON", function() { - var json, bot1, bot2, echo; + var json, bot1, bot2; beforeEach(function() { bot1 = new Robot(); bot2 = new Robot(); - Cylon.robots = { "bot1": bot1, "bot2": bot2 }; - Cylon.commands.echo = echo = function(arg) { return arg; }; + Cylon.robots = { bot1: bot1, bot2: bot2 }; + Cylon.commands.echo = function(arg) { return arg; }; json = Cylon.toJSON(); }); diff --git a/spec/lib/digital-pin.spec.js b/spec/lib/digital-pin.spec.js index 5e38044..1e70d40 100644 --- a/spec/lib/digital-pin.spec.js +++ b/spec/lib/digital-pin.spec.js @@ -1,4 +1,4 @@ -/* jshint expr:true */ +/* eslint no-sync: 0 */ "use strict"; var fs = require("fs"); @@ -148,7 +148,7 @@ describe("Cylon.IO.DigitalPin", function() { pin.emit.restore(); }); - it("emits a digitalWrite event with the written value", function() { + it("emits a digitalWrite event with the written value", function() { pin.digitalWrite(1); expect(fs.writeFile).to.be.calledWith(path, 1); expect(pin.emit).to.be.calledWith("digitalWrite", 1); diff --git a/spec/lib/driver.spec.js b/spec/lib/driver.spec.js index 391b069..0fa81cf 100644 --- a/spec/lib/driver.spec.js +++ b/spec/lib/driver.spec.js @@ -1,4 +1,3 @@ -/* jshint expr:true */ "use strict"; var Driver = source("driver"), @@ -77,7 +76,7 @@ describe("Driver", function() { }); describe("#toJSON", function() { - var driver, json; + var json; beforeEach(function() { driver = new Driver({ @@ -125,8 +124,8 @@ describe("Driver", function() { var commands = ["helloWorld", "otherTestCommand"], snake_case = ["hello_world", "other_test_command"]; - commands.forEach(function(cmd) { - driver[cmd] = spy(); + commands.forEach(function(name) { + driver[name] = spy(); }); driver.setupCommands(commands); diff --git a/spec/lib/io/utils.js b/spec/lib/io/utils.js index c4c91ba..52cd4ae 100644 --- a/spec/lib/io/utils.js +++ b/spec/lib/io/utils.js @@ -1,4 +1,3 @@ -/* jshint expr:true */ "use strict"; var Utils = source("io/utils.js"); diff --git a/spec/lib/logger.spec.js b/spec/lib/logger.spec.js index fd29c17..ed8c4ce 100644 --- a/spec/lib/logger.spec.js +++ b/spec/lib/logger.spec.js @@ -1,4 +1,3 @@ -/* jshint expr:true */ "use strict"; var Logger = source("logger"), diff --git a/spec/lib/logger/basic_logger.spec.js b/spec/lib/logger/basic_logger.spec.js index ac18618..554d77b 100644 --- a/spec/lib/logger/basic_logger.spec.js +++ b/spec/lib/logger/basic_logger.spec.js @@ -1,4 +1,3 @@ -/* jshint expr:true */ "use strict"; var logger = source("logger/basic_logger"); diff --git a/spec/lib/registry.spec.js b/spec/lib/registry.spec.js index 016917d..1d2bd11 100644 --- a/spec/lib/registry.spec.js +++ b/spec/lib/registry.spec.js @@ -1,4 +1,3 @@ -/* jshint expr:true */ "use strict"; var Registry = source("registry"); diff --git a/spec/lib/robot.spec.js b/spec/lib/robot.spec.js index d93849b..cb5d37e 100644 --- a/spec/lib/robot.spec.js +++ b/spec/lib/robot.spec.js @@ -1,4 +1,3 @@ -/* jshint expr:true */ "use strict"; var Driver = source("driver"), @@ -85,8 +84,6 @@ describe("Robot", function() { }); context("if no commands are provided", function() { - var robot; - beforeEach(function() { robot = new Robot({ name: "NewBot", @@ -101,8 +98,6 @@ describe("Robot", function() { }); context("if a commands function is provided", function() { - var robot; - beforeEach(function() { robot = new Robot({ name: "NewBot", @@ -147,8 +142,6 @@ describe("Robot", function() { }); context("if a commands object is provided", function() { - var robot; - beforeEach(function() { robot = new Robot({ name: "NewBot", @@ -246,7 +239,7 @@ describe("Robot", function() { it("contains the robot's events, or an empty array", function() { expect(json.events).to.eql(["hello", "world"]); - var bot = new Robot(); + bot = new Robot(); expect(bot.toJSON().events).to.be.eql([]); }); }); diff --git a/spec/lib/utils.spec.js b/spec/lib/utils.spec.js index 4977907..62b2224 100644 --- a/spec/lib/utils.spec.js +++ b/spec/lib/utils.spec.js @@ -1,4 +1,3 @@ -/* jshint expr:true */ "use strict"; var utils = source("utils"); @@ -207,7 +206,7 @@ describe("Utils", function() { describe("#fetch", function() { var fetch = utils.fetch, - obj = { property: "hello world", "false": false, "null": null }; + obj = { property: "hello world", false: false, null: null }; context("if the property exists on the object", function() { it("returns the value", function() { diff --git a/spec/lib/utils/helpers.spec.js b/spec/lib/utils/helpers.spec.js index 977c499..d4925e9 100644 --- a/spec/lib/utils/helpers.spec.js +++ b/spec/lib/utils/helpers.spec.js @@ -11,7 +11,7 @@ describe("Helpers", function() { vegetables: ["beet"], thing: null, otherThing: "hello!", - data: [{ "user": "barney" }, { "user": "fred" }] + data: [{ user: "barney" }, { user: "fred" }] }; var source = { @@ -19,7 +19,7 @@ describe("Helpers", function() { vegetables: ["carrot"], thing: "hello!", otherThing: null, - data: [{ "age": 36 }, { "age": 40 }] + data: [{ age: 36 }, { age: 40 }] }; var expected = { @@ -37,7 +37,7 @@ describe("Helpers", function() { }); describe("isObject", function() { - var fn =_.isObject; + var fn = _.isObject; it("checks if a value is an Object", function() { var Klass = function() {}, @@ -54,7 +54,7 @@ describe("Helpers", function() { }); describe("isFunction", function() { - var fn =_.isFunction; + var fn = _.isFunction; it("checks if a value is a Function", function() { expect(fn(function() {})).to.be.eql(true); @@ -224,14 +224,14 @@ describe("Helpers", function() { }); it("defaults to the first value for the accumulator", function() { - var obj = { + var object = { a: { name: "hello" }, b: { name: "world" } }; expect(_.reduce(arr, add)).to.be.eql(21); expect( - _.reduce(obj, function(acc, val) { + _.reduce(object, function(acc, val) { acc.name += " " + val.name; return acc; }) diff --git a/spec/support/mock_module.js b/spec/support/mock_module.js index 7c1f82c..2d184b9 100644 --- a/spec/support/mock_module.js +++ b/spec/support/mock_module.js @@ -2,6 +2,6 @@ "use strict"; module.exports = { - adaptors: [ 'test-adaptor' ], - drivers: [ 'test-driver' ] + adaptors: [ "test-adaptor" ], + drivers: [ "test-driver" ] };