Skip to content

Commit

Permalink
Switch to ESLint for linting
Browse files Browse the repository at this point in the history
  • Loading branch information
stewart committed Jun 11, 2015
1 parent db83e5e commit 1328ae9
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 89 deletions.
46 changes: 46 additions & 0 deletions .eslintrc
@@ -0,0 +1,46 @@
env:
node: true

globals:
every: true
after: true
constantly: 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"]
38 changes: 0 additions & 38 deletions .jshintrc

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -18,7 +18,7 @@ cover:
@istanbul cover $(BIN)/_mocha $(TEST_FILES) --report lcovonly -- -R spec

lint:
@jshint $(FILES)
@$(BIN)/eslint lib spec examples

ci: lint cover

Expand Down
2 changes: 2 additions & 0 deletions examples/.eslintrc
@@ -0,0 +1,2 @@
rules:
camelcase: 0
2 changes: 1 addition & 1 deletion examples/rgb-led-strobe/fluent-rgb-led-strobe.js
Expand Up @@ -26,7 +26,7 @@ Cylon
if (index === 2) {
index = 0;
fade = -fade;
}else{
} else {
brightness = (fade > 0) ? 0 : 255;
index++;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/rgb-led-strobe/rgb-led-strobe.js
Expand Up @@ -30,7 +30,7 @@ Cylon.robot({
if (index === 2) {
index = 0;
fade = -fade;
}else{
} else {
brightness = (fade > 0) ? 0 : 255;
index++;
}
Expand Down
26 changes: 13 additions & 13 deletions lib/digispark.js
Expand Up @@ -29,7 +29,7 @@ Cylon.Utils.subclass(Digispark, Cylon.Adaptor);
* Connects to the Digispark
*
* @param {Function} callback to be triggered when connected
* @return {null}
* @return {void}
*/
Digispark.prototype.connect = function(callback) {
this.digispark = new digispark.Digispark();
Expand All @@ -41,7 +41,7 @@ Digispark.prototype.connect = function(callback) {
* Disconnects from the Digispark
*
* @param {Function} callback to be triggered when disconnected
* @return {null}
* @return {void}
*/
Digispark.prototype.disconnect = function(callback) {
callback();
Expand All @@ -50,9 +50,9 @@ Digispark.prototype.disconnect = function(callback) {
/**
* Writes a value to a digital pin
*
* @param {Number} pin
* @param {Number} value
* @return {null}
* @param {Number} pin the pin to write to
* @param {Number} value the value to write to the pin
* @return {void}
* @publish
*/
Digispark.prototype.digitalWrite = function(pin, value) {
Expand All @@ -63,10 +63,10 @@ Digispark.prototype.digitalWrite = function(pin, value) {
/**
* Reads a value from a digital pin
*
* @param {Number} pin
* @param {Number} pin the pin to read from
* @param {Function} callback triggered when the value has been read from the
* pin
* @return {null}
* @return {void}
* @publish
*/
Digispark.prototype.digitalRead = function(pin, callback) {
Expand All @@ -80,9 +80,9 @@ Digispark.prototype.digitalRead = function(pin, callback) {
/**
* Writes a servo value to a pin
*
* @param {Number} pin
* @param {Number} value
* @return {null}
* @param {Number} pin the pin to write to
* @param {Number} value the value to write to the pin
* @return {void}
* @publish
*/
Digispark.prototype.servoWrite = function(pin, value) {
Expand All @@ -93,9 +93,9 @@ Digispark.prototype.servoWrite = function(pin, value) {
/**
* Writes a PWM value to a pin
*
* @param {Number} pin
* @param {Number} value
* @return {null}
* @param {Number} pin the pin to write to
* @param {Number} value the value to write to the pin
* @return {void}
* @publish
*/
Digispark.prototype.pwmWrite = function(pin, value) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -35,7 +35,7 @@
"chai": "~1.7.2",
"mocha": "~1.12.1",
"sinon": "~1.7.3",
"jshint": "~2.4.4"
"eslint": "0.22.1"
},

"dependencies": {
Expand Down
15 changes: 15 additions & 0 deletions spec/.eslintrc
@@ -0,0 +1,15 @@
env:
mocha: true

globals:
expect: true
lib: true
stub: true
spy: true
chai: true
sinon: true

rules:
no-unused-expressions: 0
max-nested-callbacks: 0
camelcase: 0
28 changes: 14 additions & 14 deletions spec/helper.js
@@ -1,39 +1,39 @@
'use strict';
"use strict";

// allow production modules to expose internal
// functions and properties for testing
process.env.NODE_ENV = 'test';
process.env.NODE_ENV = "test";

var path = require('path');
var chai = require('chai');
var sinonChai = require('sinon-chai');
var path = require("path");
var chai = require("chai");
var sinonChai = require("sinon-chai");

var Cylon = require('cylon');
var Cylon = require("cylon");
Cylon.config({ logging: { logger: false } });

global.chai = chai;
global.should = chai.should();
global.expect = chai.expect;
global.assert = chai.assert;
global.AssertionError = chai.AssertionError;
global.sinon = require('sinon');
global.spy = sinon.spy
global.stub = sinon.stub
global.sinon = require("sinon");
global.spy = sinon.spy;
global.stub = sinon.stub;

// can be used by test modules to require production modules,
// relative to the base path (where the Gruntfile.js also lives)
global.source = function (src) {
var resource = path.normalize('../lib/' + src);
global.lib = function(src) {
var resource = path.normalize("../lib/" + src);
return require(resource);
};

// can be used when you expect a function to throw an error
global.err = function (fn, msg) {
global.err = function(fn, msg) {
try {
fn();
throw new chai.AssertionError({ message: 'Expected an error' });
throw new chai.AssertionError({ message: "Expected an error" });
} catch (err) {
if ('string' === typeof msg) {
if (typeof msg === "string") {
chai.expect(err.message).to.equal(msg);
} else {
chai.expect(err.message).to.match(msg);
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/cylon-digispark.spec.js
@@ -1,7 +1,7 @@
"use strict";

var mod = source("cylon-digispark"),
Digispark = source("digispark");
var mod = lib("cylon-digispark"),
Digispark = lib("digispark");

describe("cylon-digispark", function() {
describe("#adaptors", function() {
Expand Down
34 changes: 16 additions & 18 deletions spec/lib/digispark.spec.js
@@ -1,9 +1,9 @@
/* jshint expr:true */
"use strict";

var Digispark = source("digispark");
var Digispark = lib("digispark");

var digispark = source("../build/Release/digispark.node");
var digispark = lib("../build/Release/digispark.node");

describe("Digispark", function() {
var spark = new Digispark({
Expand Down Expand Up @@ -61,26 +61,25 @@ describe("Digispark", function() {
});

describe("#digitalWrite", function() {
var digispark;
var mock;

beforeEach(function() {
digispark = { pinMode: spy(), digitalWrite: spy() };
spark.digispark = digispark;
mock = { pinMode: spy(), digitalWrite: spy() };
spark.digispark = mock;
spark.digitalWrite("A", 1);
});

it("sets the pin mode to 0", function() {
expect(digispark.pinMode).to.be.calledWith("A", 0);
expect(mock.pinMode).to.be.calledWith("A", 0);
});

it("writes the value to the pin", function() {
expect(digispark.digitalWrite).to.be.calledWith("A", 1);
expect(mock.digitalWrite).to.be.calledWith("A", 1);
});
});

describe("#digitalRead", function() {
var digispark, callback,
clock;
var mock, callback, clock;

beforeEach(function() {
clock = sinon.useFakeTimers();
Expand All @@ -91,34 +90,33 @@ describe("Digispark", function() {
});

beforeEach(function() {
digispark = { pinMode: spy(), digitalRead: spy() };
mock = { pinMode: spy(), digitalRead: spy() };
callback = spy();
spark.digispark = digispark;
spark.digispark = mock;
spark.digitalRead("A", callback);
});

it("sets the pin mode to 1", function() {
expect(digispark.pinMode).to.be.calledWith("A", 1);
expect(mock.pinMode).to.be.calledWith("A", 1);
});

it("reads the value from the pin", function() {
clock.tick(2050);
expect(digispark.digitalRead).to.be.calledWith("A", callback);
expect(mock.digitalRead).to.be.calledWith("A", callback);
});
});

describe("#servoWrite", function() {
var digispark, callback;
var mock;

beforeEach(function() {
digispark = { servoWrite: spy() };
callback = spy();
spark.digispark = digispark;
mock = { servoWrite: spy() };
spark.digispark = mock;
spark.servoWrite("A", 1);
});

it("writes the value to the pin", function() {
expect(digispark.servoWrite).to.be.calledWith(180);
expect(mock.servoWrite).to.be.calledWith(180);
});
});

Expand Down

0 comments on commit 1328ae9

Please sign in to comment.