Skip to content

Commit

Permalink
Added ESLint to the project.
Browse files Browse the repository at this point in the history
  • Loading branch information
adanperez committed Apr 5, 2016
1 parent 76a32ea commit 1e42a1e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 16 deletions.
13 changes: 13 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "smartthings",
"env": {
"mocha": true
},
"globals": {
"expect": false,
"sinon": false,
"should": false,
"webkit": false,
"tigonMessageHandler": false
}
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
},
"devDependencies": {
"babel-core": "6.7.4",
"babel-eslint": "6.0.2",
"babel-loader": "6.2.4",
"babel-preset-es2015": "6.6.0",
"chai": "3.5.0",
"eslint": "2.7.0",
"eslint-config-smartthings": "2.4.0",
"expose-loader": "0.7.1",
"karma": "0.13.22",
"karma-chai": "0.1.0",
Expand All @@ -48,7 +51,7 @@
"scripts": {
"test": "karma start",
"test-watch": "karma start --auto-watch",
"lint": "eslint --config .eslintrc './src/client/**/*.js'",
"lint": "eslint --config .eslintrc './src/**/*.js'",
"build": "NODE_ENV=production webpack --config webpack/webpack.config.js --verbose --colors --display-error-details",
"build-global": "NODE_ENV=production webpack --config webpack/webpack.config.global.js --verbose --colors --display-error-details",
"release": "npm run build && npm run build-global"
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Exporting default here so we can use actual class as export for commonjs.
*/
var Tigon = require('./tigon').default;
const Tigon = require('./tigon').default;
module.exports = new Tigon();
2 changes: 1 addition & 1 deletion src/tigon.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Tigon {
* @param message - the message you want to send to the client
*/
send(message) {
if (!message) return;
if (!message) return Promise.reject('No message was sent.');

const messageForClient = {
id: utils.createUUID(),
Expand Down
24 changes: 15 additions & 9 deletions src/tigon.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('tigon', () => {
expect(tigon.messageHandlers[0]).to.equal(test2);
});
});

describe('send()', () => {
let agent;

Expand All @@ -34,7 +34,8 @@ describe('tigon', () => {

// The following code will force getUserAgent to get called for each test
delete require.cache[require.resolve('./tigon')];
tigon = new (require('./tigon').default)();
const RefreshTigon = require('./tigon').default; // eslint-disable-line global-require
tigon = new RefreshTigon();
});

afterEach(() => {
Expand All @@ -57,8 +58,13 @@ describe('tigon', () => {
data: 'test'
});

const expectedMessage = '{"id":"uuid","payload":{"id":123,"data":"test"}}';
expect(webkit.messageHandlers.tigon.postMessage).to.have.been.calledWithExactly(expectedMessage);
expect(webkit.messageHandlers.tigon.postMessage).to.have.been.calledWithExactly({
id: 'uuid',
payload: {
id: 123,
data: 'test'
}
});
const callbacks = tigon.messages.get('uuid');
expect(utils.isFunction(callbacks.onSuccess)).to.equal(true);
expect(utils.isFunction(callbacks.onError)).to.equal(true);
Expand Down Expand Up @@ -146,11 +152,11 @@ describe('tigon', () => {
});

return promise.then(() => {
throw new Error('No error should be thrown here.');
})
.catch(err => {
expect(err).to.equal('Browser/OS is not supported.');
});
throw new Error('No error should be thrown here.');
})
.catch(err => {
expect(err).to.equal('Browser/OS is not supported.');
});
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export function getUserAgent() {
android: /(android)/i.test(userAgent),
windowsPhone: /windows phone/i.test(userAgent),
tizen: /tizen/i.test(userAgent)
}
}
};
}
4 changes: 2 additions & 2 deletions src/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as utils from './utils';
describe('utils', () => {
describe('isFunction()', () => {
it('should determine if something is a function', () => {
expect(utils.isFunction(function () {})).to.equal(true);
expect(utils.isFunction(function test() {})).to.equal(true);
expect(utils.isFunction(1)).to.equal(false);
expect(utils.isFunction({})).to.equal(false);
});
Expand Down Expand Up @@ -52,4 +52,4 @@ describe('utils', () => {
});
});
});
});
});

0 comments on commit 1e42a1e

Please sign in to comment.