Skip to content

Commit

Permalink
Merge pull request #837 from megawac/style
Browse files Browse the repository at this point in the history
Implement style guide check via jscs
  • Loading branch information
megawac committed Jul 9, 2015
2 parents deaa5a1 + 9ae79fd commit 7ea45d7
Show file tree
Hide file tree
Showing 8 changed files with 554 additions and 548 deletions.
3 changes: 3 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"validateIndentation": 4
}
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CWD := $(shell pwd)
NODEUNIT = "$(CWD)/node_modules/.bin/nodeunit"
UGLIFY = "$(CWD)/node_modules/.bin/uglifyjs"
JSHINT = "$(CWD)/node_modules/.bin/jshint"
JSCS = "$(CWD)/node_modules/.bin/jscs"
XYZ = node_modules/.bin/xyz --repo git@github.com:caolan/async.git

BUILDDIR = lib
Expand All @@ -21,6 +22,7 @@ clean:

lint:
$(JSHINT) lib/*.js test/*.js perf/*.js
$(JSCS) lib/*.js test/*.js perf/*.js

.PHONY: test lint build all clean

Expand Down
58 changes: 29 additions & 29 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,19 +584,19 @@
var attempts = [];

var opts = {
times: DEFAULT_TIMES,
interval: DEFAULT_INTERVAL
times: DEFAULT_TIMES,
interval: DEFAULT_INTERVAL
};

function parseTimes(acc, t){
if(typeof t === 'number'){
acc.times = parseInt(t, 10) || DEFAULT_TIMES;
} else if(typeof t === 'object'){
acc.times = parseInt(t.times, 10) || DEFAULT_TIMES;
acc.interval = parseInt(t.interval, 10) || DEFAULT_INTERVAL;
} else {
throw new Error('Unsupported argument type for \'times\': ' + typeof(t));
}
if(typeof t === 'number'){
acc.times = parseInt(t, 10) || DEFAULT_TIMES;
} else if(typeof t === 'object'){
acc.times = parseInt(t.times, 10) || DEFAULT_TIMES;
acc.interval = parseInt(t.interval, 10) || DEFAULT_INTERVAL;
} else {
throw new Error('Unsupported argument type for \'times\': ' + typeof(t));
}
}

var length = arguments.length;
Expand All @@ -622,19 +622,19 @@
}

function retryInterval(interval){
return function(seriesCallback){
setTimeout(function(){
seriesCallback(null);
}, interval);
};
return function(seriesCallback){
setTimeout(function(){
seriesCallback(null);
}, interval);
};
}

while (opts.times) {

var finalAttempt = !(opts.times-=1);
attempts.push(retryAttempt(opts.task, finalAttempt));
if(!finalAttempt && opts.interval > 0){
attempts.push(retryInterval(opts.interval));
attempts.push(retryInterval(opts.interval));
}
}

Expand Down Expand Up @@ -835,7 +835,7 @@
if(data.length === 0 && q.idle()) {
// call drain immediately if there are no tasks
return async.setImmediate(function() {
q.drain();
q.drain();
});
}
_arrayEach(data, function(task) {
Expand Down Expand Up @@ -951,17 +951,17 @@
}

function _binarySearch(sequence, item, compare) {
var beg = -1,
end = sequence.length - 1;
while (beg < end) {
var mid = beg + ((end - beg + 1) >>> 1);
if (compare(item, sequence[mid]) >= 0) {
beg = mid;
} else {
end = mid - 1;
}
}
return beg;
var beg = -1,
end = sequence.length - 1;
while (beg < end) {
var mid = beg + ((end - beg + 1) >>> 1);
if (compare(item, sequence[mid]) >= 0) {
beg = mid;
} else {
end = mid - 1;
}
}
return beg;
}

function _insert(q, data, priority, callback) {
Expand Down Expand Up @@ -1060,7 +1060,7 @@
var q = queues[key];
delete queues[key];
for (var i = 0, l = q.length; i < l; i++) {
q[i].apply(null, args);
q[i].apply(null, args);
}
})]));
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"devDependencies": {
"benchmark": "bestiejs/benchmark.js",
"coveralls": "^2.11.2",
"jscs": "^1.13.1",
"jshint": "~2.8.0",
"lodash": "^3.9.0",
"mkdirp": "~0.5.1",
Expand All @@ -43,7 +44,7 @@
},
"scripts": {
"test": "npm run-script lint && nodeunit test/test-async.js",
"lint": "jshint lib/*.js test/*.js perf/*.js",
"lint": "jshint lib/*.js test/*.js perf/*.js && jscs lib/*.js test/*.js perf/*.js",
"coverage": "nyc npm test && nyc report",
"coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls"
},
Expand Down

0 comments on commit 7ea45d7

Please sign in to comment.