Switch to ESLint for linting

This commit is contained in:
Andrew Stewart 2015-04-14 21:49:12 -07:00
parent cccb376679
commit 62cbae7cff
41 changed files with 194 additions and 174 deletions

52
.eslintrc Normal file
View File

@ -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"]

View File

@ -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
}

View File

@ -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

View File

@ -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

2
examples/.eslintrc Normal file
View File

@ -0,0 +1,2 @@
rules:
camelcase: 0

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -142,7 +142,7 @@ Cylon.robot({
}
// 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) *

View File

@ -26,6 +26,7 @@ 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;

View File

@ -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);
});
}

View File

@ -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) {

View File

@ -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));

View File

@ -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");

View File

@ -6,6 +6,8 @@
* Licensed under the Apache 2.0 license.
*/
/* eslint camelcase: 0 */
"use strict";
var Basestar = require("./basestar"),

View File

@ -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));

View File

@ -97,12 +97,14 @@ var Registry = module.exports = {
search: function(entry, value) {
for (var name in this.data) {
if (this.data.hasOwnProperty(name)) {
var repo = this.data[name];
if (repo[entry] && _.includes(repo[entry], value)) {
return repo.module;
}
}
}
return false;
}

View File

@ -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);

View File

@ -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;
i = i.toString();
}
},

View File

@ -29,11 +29,9 @@ function extend(base, source) {
base[i] = e;
} else if (typeof e === "object") {
base[i] = extend(base[i], e);
} else {
if (!~base.indexOf(e)) {
} else if (!~base.indexOf(e)) {
base.push(e);
}
}
});
} else {
var key;
@ -41,15 +39,13 @@ function extend(base, source) {
for (key in source) {
if (typeof source[key] !== "object" || !source[key]) {
base[key] = source[key];
} else {
if (base[key]) {
} else if (base[key]) {
extend(base[key], source[key]);
} else {
base[key] = source[key];
}
}
}
}
return base;
}
@ -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;

View File

@ -6,6 +6,8 @@
* Licensed under the Apache 2.0 license.
*/
/* eslint no-extend-native: 0 */
"use strict";
var max = Math.max,

View File

@ -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": {

7
spec/.eslintrc Normal file
View File

@ -0,0 +1,7 @@
env:
mocha: true
rules:
no-unused-expressions: 0
max-nested-callbacks: 0
camelcase: 0

View File

@ -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",

View File

@ -1,4 +1,3 @@
/* jshint expr:true */
"use strict";
var Adaptor = source("adaptor"),

View File

@ -1,4 +1,3 @@
/* jshint expr:true */
"use strict";
var Basestar = source("basestar"),
@ -82,8 +81,13 @@ 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() {

View File

@ -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();
});

View File

@ -1,4 +1,4 @@
/* jshint expr:true */
/* eslint no-sync: 0 */
"use strict";
var fs = require("fs");

View File

@ -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);

View File

@ -1,4 +1,3 @@
/* jshint expr:true */
"use strict";
var Utils = source("io/utils.js");

View File

@ -1,4 +1,3 @@
/* jshint expr:true */
"use strict";
var Logger = source("logger"),

View File

@ -1,4 +1,3 @@
/* jshint expr:true */
"use strict";
var logger = source("logger/basic_logger");

View File

@ -1,4 +1,3 @@
/* jshint expr:true */
"use strict";
var Registry = source("registry");

View File

@ -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([]);
});
});

View File

@ -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() {

View File

@ -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 = {
@ -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;
})

View File

@ -2,6 +2,6 @@
"use strict";
module.exports = {
adaptors: [ 'test-adaptor' ],
drivers: [ 'test-driver' ]
adaptors: [ "test-adaptor" ],
drivers: [ "test-driver" ]
};