Skip to content

Commit

Permalink
Build: Add eslint and jscs presets & update code
Browse files Browse the repository at this point in the history
  • Loading branch information
pdehaan authored and phated committed Jun 27, 2016
1 parent 2bbb1bc commit 888de5b
Show file tree
Hide file tree
Showing 20 changed files with 139 additions and 178 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "gulp"
}
3 changes: 3 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"preset": "gulp"
}
25 changes: 0 additions & 25 deletions .jshintrc

This file was deleted.

8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
sudo: false

language: node_js

node_js:
- 'stable'
- '0.12'
- '0.10'
script:
- npm test
- npm run lint
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bach
====

[![build status](https://secure.travis-ci.org/phated/bach.png)](http://travis-ci.org/phated/bach)
[![build status](https://secure.travis-ci.org/gulpjs/bach.png)](http://travis-ci.org/gulpjs/bach)

Compose your async functions with elegance

Expand Down Expand Up @@ -59,7 +59,7 @@ combinedFn(function(err, res){
});
```

Functions are called with [async-done](https://github.com/phated/async-done), so you can return a stream or promise.
Functions are called with [async-done](https://github.com/gulpjs/async-done), so you can return a stream or promise.
The function will complete when the stream ends/closes/errors or the promise fulfills/rejects.

```js
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ module.exports = {
series: require('./lib/series'),
parallel: require('./lib/parallel'),
settleSeries: require('./lib/settleSeries'),
settleParallel: require('./lib/settleParallel')
settleParallel: require('./lib/settleParallel'),
};
26 changes: 13 additions & 13 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ var assert = require('assert');

var _ = require('lodash');

function getExtensions(lastArg){
if(typeof lastArg !== 'function'){
function getExtensions(lastArg) {
if (typeof lastArg !== 'function') {
return lastArg;
}
}

function buildOnSettled(done){
function buildOnSettled(done) {
done = done || _.noop;

function onSettled(error, result){
if(error){
function onSettled(error, result) {
if (error) {
return done(error, null);
}

var settledErrors = _.where(result, { state: 'error' });
var settledResults = _.where(result, { state: 'success' });

var errors = null;
if(settledErrors.length){
if (settledErrors.length) {
errors = _.pluck(settledErrors, 'value');
}

var results = null;
if(settledResults.length){
if (settledResults.length) {
results = _.pluck(settledResults, 'value');
}

Expand All @@ -37,20 +37,20 @@ function buildOnSettled(done){
return onSettled;
}

function verifyArguments(args){
function verifyArguments(args) {
args = _.flatten(args);
var lastIdx = args.length - 1;

assert.ok(args.length, 'A set of functions to combine is required');

_.forEach(args, function(arg, argIdx){
_.forEach(args, function(arg, argIdx) {
var isFunction = _.isFunction(arg);
if(isFunction){
if (isFunction) {
return;
}

if(argIdx === lastIdx){
// last arg can be an object of extension points
if (argIdx === lastIdx) {
// Last arg can be an object of extension points
return;
}

Expand All @@ -64,5 +64,5 @@ function verifyArguments(args){
module.exports = {
getExtensions: getExtensions,
onSettled: buildOnSettled,
verifyArguments: verifyArguments
verifyArguments: verifyArguments,
};
6 changes: 3 additions & 3 deletions lib/parallel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ var nowAndLater = require('now-and-later');

var helpers = require('./helpers');

function buildParallel(){
function buildParallel() {
var args = helpers.verifyArguments(arguments);

var extensions = helpers.getExtensions(_.last(args));

if(extensions){
if (extensions) {
args = _.initial(args);
}

function parallel(done){
function parallel(done) {
nowAndLater.map(args, asyncDone, extensions, done);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/series.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ var nowAndLater = require('now-and-later');

var helpers = require('./helpers');

function buildSeries(){
function buildSeries() {
var args = helpers.verifyArguments(arguments);

var extensions = helpers.getExtensions(_.last(args));

if(extensions){
if (extensions) {
args = _.initial(args);
}

function series(done){
function series(done) {
nowAndLater.mapSeries(args, asyncDone, extensions, done);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/settleParallel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ var nowAndLater = require('now-and-later');

var helpers = require('./helpers');

function buildSettleParallel(){
function buildSettleParallel() {
var args = helpers.verifyArguments(arguments);

var extensions = helpers.getExtensions(_.last(args));

if(extensions){
if (extensions) {
args = _.initial(args);
}

function settleParallel(done){
function settleParallel(done) {
nowAndLater.map(args, asyncSettle, extensions, helpers.onSettled(done));
}

Expand Down
6 changes: 3 additions & 3 deletions lib/settleSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ var nowAndLater = require('now-and-later');

var helpers = require('./helpers');

function buildSettleSeries(){
function buildSettleSeries() {
var args = helpers.verifyArguments(arguments);

var extensions = helpers.getExtensions(_.last(args));

if(extensions){
if (extensions) {
args = _.initial(args);
}

function settleSeries(done){
function settleSeries(done) {
nowAndLater.mapSeries(args, asyncSettle, extensions, helpers.onSettled(done));
}

Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"Pawel Kozlowski <pkozlowski.opensource@gmail.com>",
"Benjamin Tan <demoneaux@gmail.com> (https://d10.github.io/)"
],
"repository": "phated/bach",
"repository": "gulpjs/bach",
"license": "MIT",
"engines": {
"node": ">= 0.10"
Expand All @@ -20,8 +20,9 @@
"LICENSE"
],
"scripts": {
"pretest": "npm run lint",
"test": "lab -cv",
"lint": "jshint test lib index.js --reporter node_modules/jshint-stylish/index.js --exclude node_modules"
"lint": "eslint . && jscs *.js lib/ test/"
},
"dependencies": {
"async-done": "^1.1.1",
Expand All @@ -31,8 +32,10 @@
},
"devDependencies": {
"code": "^1.5.0",
"jshint": "^2.8.0",
"jshint-stylish": "^2.0.1",
"eslint": "^1.7.3",
"eslint-config-gulp": "^2.0.0",
"jscs": "^2.3.5",
"jscs-preset-gulp": "^1.0.0",
"lab": "^6.2.0"
},
"keywords": [
Expand Down
3 changes: 3 additions & 0 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "gulp/test"
}
12 changes: 4 additions & 8 deletions test/getExtensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@
var lab = exports.lab = require('lab').script();
var describe = lab.describe;
var it = lab.it;
var before = lab.before;
var beforeEach = lab.beforeEach;
var after = lab.after;
var afterEach = lab.afterEach;
var expect = require('code').expect;

var getExtensions = require('../lib/helpers').getExtensions;

describe('getExtensions', function(){
describe('getExtensions', function() {

it('should return the argument if it is an object', function(done){
it('should return the argument if it is an object', function(done) {
var obj = {};
expect(getExtensions(obj)).to.equal(obj);
done();
});

it('should return undefined if argument is not an object', function(done){
var fn = function(){};
it('should return undefined if argument is not an object', function(done) {
var fn = function() {};
expect(getExtensions(fn)).to.equal(undefined);
done();
});
Expand Down
18 changes: 7 additions & 11 deletions test/onSettled.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,34 @@
var lab = exports.lab = require('lab').script();
var describe = lab.describe;
var it = lab.it;
var before = lab.before;
var beforeEach = lab.beforeEach;
var after = lab.after;
var afterEach = lab.afterEach;
var expect = require('code').expect;

var onSettled = require('../lib/helpers').onSettled;

var errors = [
{ state: 'error', value: new Error('Error 1') },
{ state: 'error', value: new Error('Error 2') }
{ state: 'error', value: new Error('Error 2') },
];

describe('onSettled', function(){
describe('onSettled', function() {

it('should group all errors', function(done){
onSettled(function(errs, results){
it('should group all errors', function(done) {
onSettled(function(errs, results) {
expect(errs).to.have.length(2);
expect(results).to.equal(null);
done();
})(null, errors);
});

it('should error early if called with an error', function(done){
onSettled(function(err, results){
it('should error early if called with an error', function(done) {
onSettled(function(err, results) {
expect(err).to.be.an.instanceof(Error);
expect(results).to.equal(null);
done();
})(new Error('Should not happen'));
});

it('should handle the no callback case', function(done){
it('should handle the no callback case', function(done) {
onSettled()(null, errors);
done();
});
Expand Down
Loading

0 comments on commit 888de5b

Please sign in to comment.