Skip to content

Commit 3e8e9fd

Browse files
pdehaanphated
authored andcommitted
Build: Add eslint and jscs presets & update code
1 parent e1d3945 commit 3e8e9fd

14 files changed

+98
-119
lines changed

.eslintrc

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
11
{
2-
"rules": {
3-
"semi": [2, "always"],
4-
"quotes": [2, "single"],
5-
"strict": [2, "global"],
6-
"no-underscore-dangle": 0,
7-
"no-use-before-define": 0
8-
},
9-
"env": {
10-
"es6": true,
11-
"browser": true,
12-
"node": true
13-
}
2+
"extends": "gulp"
143
}

.jscsrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"preset": "gulp"
3+
}

.jshintrc

-25
This file was deleted.

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
sudo: false
2+
23
language: node_js
4+
35
node_js:
46
- '0.10'
57
- '0.12'
6-
- 'iojs'
8+
- 'stable'

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
async-done
22
==========
33

4-
[![build status](https://secure.travis-ci.org/phated/async-done.png)](http://travis-ci.org/phated/async-done)
4+
[![build status](https://secure.travis-ci.org/gulpjs/async-done.png)](http://travis-ci.org/gulpjs/async-done)
55

66
Handles completion and errors for callbacks, promises, observables, child processes and streams.
77

index.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,31 @@ var once = require('once');
88
var exhaust = require('stream-exhaust');
99

1010
var eosConfig = {
11-
error: false
11+
error: false,
1212
};
1313

14-
function asyncDone(fn, cb){
14+
function asyncDone(fn, cb) {
1515
cb = once(cb);
1616

1717
var d = domain.create();
1818
d.once('error', onError);
1919
var domainBoundFn = d.bind(fn);
2020

21-
function done(){
21+
function done() {
2222
d.removeListener('error', onError);
2323
d.exit();
2424
return cb.apply(null, arguments);
2525
}
2626

27-
function onSuccess(result){
27+
function onSuccess(result) {
2828
return done(null, result);
2929
}
3030

31-
function onError(error){
31+
function onError(error) {
3232
return done(error);
3333
}
3434

35-
function asyncRunner(){
35+
function asyncRunner() {
3636
var result = domainBoundFn(done);
3737

3838
function onNext(state) {
@@ -43,21 +43,21 @@ function asyncDone(fn, cb){
4343
return onSuccess(onNext.state);
4444
}
4545

46-
if(result && typeof result.on === 'function'){
47-
// assume node stream
46+
if (result && typeof result.on === 'function') {
47+
// Assume node stream
4848
d.add(result);
4949
eos(exhaust(result), eosConfig, done);
5050
return;
5151
}
5252

53-
if(result && typeof result.subscribe === 'function'){
54-
// assume RxJS observable
53+
if (result && typeof result.subscribe === 'function') {
54+
// Assume RxJS observable
5555
result.subscribe(onNext, onError, onCompleted);
5656
return;
5757
}
5858

59-
if(result && typeof result.then === 'function'){
60-
// assume promise
59+
if (result && typeof result.then === 'function') {
60+
// Assume promise
6161
result.then(onSuccess, onError);
6262
return;
6363
}

package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"Pawel Kozlowski <[email protected]>",
99
"Matthew Podwysocki <[email protected]>"
1010
],
11-
"repository": "phated/async-done",
11+
"repository": "gulpjs/async-done",
1212
"license": "MIT",
1313
"engines": {
1414
"node": ">= 0.10"
@@ -19,7 +19,8 @@
1919
"LICENSE"
2020
],
2121
"scripts": {
22-
"test": "lab -cvL"
22+
"lint": "eslint . && jscs *.js test/",
23+
"test": "lab -cv"
2324
},
2425
"dependencies": {
2526
"end-of-stream": "^1.1.0",
@@ -29,6 +30,10 @@
2930
},
3031
"devDependencies": {
3132
"code": "^1.4.1",
33+
"eslint": "^1.7.3",
34+
"eslint-config-gulp": "^2.0.0",
35+
"jscs": "^2.3.5",
36+
"jscs-preset-gulp": "^1.0.0",
3237
"lab": "^6.2.0",
3338
"rx": "^4.0.6",
3439
"through2": "^2.0.0",

test/.eslintrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "gulp/test"
3+
}

test/arguments.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ var expect = require('code').expect;
77

88
var asyncDone = require('../');
99

10-
function twoArg(cb){
10+
function twoArg(cb) {
1111
cb(null, 1, 2);
1212
}
1313

14-
describe('arguments', function(){
14+
describe('arguments', function() {
1515

16-
it('passes all arguments to the completion callback', function(done){
17-
asyncDone(twoArg, function(err, arg1, arg2){
16+
it('passes all arguments to the completion callback', function(done) {
17+
asyncDone(twoArg, function(err, arg1, arg2) {
1818
expect(arg1).to.equal(1);
1919
expect(arg2).to.equal(2);
2020
done(err);

test/callbacks.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,53 @@ var expect = require('code').expect;
77

88
var asyncDone = require('../');
99

10-
function success(cb){
10+
function success(cb) {
1111
cb(null, 2);
1212
}
1313

14-
function failure(cb){
14+
function failure(cb) {
1515
cb(new Error('Callback Error'));
1616
}
1717

18-
function neverDone(){
18+
function neverDone() {
1919
return 2;
2020
}
2121

22-
describe('callbacks', function(){
22+
describe('callbacks', function() {
2323

24-
it('should handle a successful callback', function(done){
25-
asyncDone(success, function(err, result){
24+
it('should handle a successful callback', function(done) {
25+
asyncDone(success, function(err, result) {
2626
expect(result).to.equal(2);
2727
done(err);
2828
});
2929
});
3030

31-
it('should handle an errored callback', function(done){
32-
asyncDone(failure, function(err){
31+
it('should handle an errored callback', function(done) {
32+
asyncDone(failure, function(err) {
3333
expect(err).to.be.instanceof(Error);
3434
done();
3535
});
3636
});
3737

38-
it('a function that takes an argument but never calls callback', function(done){
39-
asyncDone(neverDone, function(){
38+
it('a function that takes an argument but never calls callback', function(done) {
39+
asyncDone(neverDone, function() {
4040
done(new Error('Callback called'));
4141
});
4242

43-
setTimeout(function(){
43+
setTimeout(function() {
4444
done();
4545
}, 1000);
4646
});
4747

48-
it('should not handle error if something throws inside the callback', function(done){
48+
it('should not handle error if something throws inside the callback', function(done) {
4949
var d = require('domain').create();
50-
d.on('error', function(err){
50+
d.on('error', function(err) {
5151
expect(err).to.be.instanceof(Error);
5252
done();
5353
});
5454

55-
d.run(function(){
56-
asyncDone(success, function(){
55+
d.run(function() {
56+
asyncDone(success, function() {
5757
throw new Error('Thrown Error');
5858
});
5959
});

test/child_processes.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,46 @@ var cp = require('child_process');
99
var asyncDone = require('../');
1010

1111

12-
function execSuccess(){
12+
function execSuccess() {
1313
return cp.exec('echo hello world');
1414
}
1515

16-
function execFail(){
16+
function execFail() {
1717
return cp.exec('foo-bar-baz hello world');
1818
}
1919

20-
function spawnSuccess(){
20+
function spawnSuccess() {
2121
return cp.spawn('echo', ['hello world']);
2222
}
2323

24-
function spawnFail(){
24+
function spawnFail() {
2525
return cp.spawn('foo-bar-baz', ['hello world']);
2626
}
2727

28-
describe('child processes', function(){
29-
it('should handle successful exec', function(done){
30-
asyncDone(execSuccess, function(err){
28+
describe('child processes', function() {
29+
it('should handle successful exec', function(done) {
30+
asyncDone(execSuccess, function(err) {
3131
expect(err).to.not.be.instanceof(Error);
3232
done();
3333
});
3434
});
3535

36-
it('should handle failing exec', function(done){
37-
asyncDone(execFail, function(err){
36+
it('should handle failing exec', function(done) {
37+
asyncDone(execFail, function(err) {
3838
expect(err).to.be.an.instanceof(Error);
3939
done();
4040
});
4141
});
4242

43-
it('should handle successful spawn', function(done){
44-
asyncDone(spawnSuccess, function(err){
43+
it('should handle successful spawn', function(done) {
44+
asyncDone(spawnSuccess, function(err) {
4545
expect(err).to.not.be.instanceof(Error);
4646
done();
4747
});
4848
});
4949

50-
it('should handle failing spawn', function(done){
51-
asyncDone(spawnFail, function(err){
50+
it('should handle failing spawn', function(done) {
51+
asyncDone(spawnFail, function(err) {
5252
expect(err).to.be.an.instanceof(Error);
5353
done();
5454
});

test/observables.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,36 @@ var asyncDone = require('../');
99

1010
var Observable = require('rx').Observable;
1111

12-
function success(){
12+
function success() {
1313
return Observable.empty();
1414
}
1515

16-
function successValue(){
16+
function successValue() {
1717
return Observable.return(42);
1818
}
1919

20-
function failure(){
20+
function failure() {
2121
return Observable.throw(new Error('Observable error'));
2222
}
2323

24-
describe('observables', function(){
24+
describe('observables', function() {
2525

26-
it('should handle a finished observable', function(done){
27-
asyncDone(success, function(err, result){
26+
it('should handle a finished observable', function(done) {
27+
asyncDone(success, function(err, result) {
2828
expect(result).to.equal(undefined);
2929
done(err);
3030
});
3131
});
3232

33-
it('should handle a finished observable with value', function(done){
34-
asyncDone(successValue, function(err, result){
33+
it('should handle a finished observable with value', function(done) {
34+
asyncDone(successValue, function(err, result) {
3535
expect(result).to.equal(42);
3636
done(err);
3737
});
3838
});
3939

40-
it('should handle an errored observable', function(done){
41-
asyncDone(failure, function(err){
40+
it('should handle an errored observable', function(done) {
41+
asyncDone(failure, function(err) {
4242
expect(err).to.be.instanceof(Error);
4343
done();
4444
});

test/promises.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@ var when = require('when');
99

1010
var asyncDone = require('../');
1111

12-
function success(){
12+
function success() {
1313
return when.resolve(2);
1414
}
1515

16-
function failure(){
16+
function failure() {
1717
return when.reject(new Error('Promise Error'));
1818
}
1919

20-
describe('promises', function(){
20+
describe('promises', function() {
2121

22-
it('should handle a resolved promise', function(done){
23-
asyncDone(success, function(err, result){
22+
it('should handle a resolved promise', function(done) {
23+
asyncDone(success, function(err, result) {
2424
expect(result).to.equal(2);
2525
done(err);
2626
});
2727
});
2828

29-
it('should handle a rejected promise', function(done){
30-
asyncDone(failure, function(err){
29+
it('should handle a rejected promise', function(done) {
30+
asyncDone(failure, function(err) {
3131
expect(err).to.be.instanceof(Error);
3232
done();
3333
});

0 commit comments

Comments
 (0)