Skip to content

Commit 0c3fe1c

Browse files
pdehaanphated
authored andcommitted
Build: Add eslint and jscs presets & update code
1 parent 25c2a90 commit 0c3fe1c

29 files changed

+280
-268
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# Generated by integration tests
21
test/fixtures/out

.eslintrc

Lines changed: 1 addition & 12 deletions
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-
"consistent-return": 0
8-
},
9-
"env": {
10-
"es6": true,
11-
"browser": true,
12-
"node": true
13-
}
2+
"extends": "gulp"
143
}

.jscsrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"preset": "gulp"
3+
}

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ var registry = require('./lib/registry');
1414
var _getTask = require('./lib/get-task');
1515
var _setTask = require('./lib/set-task');
1616

17-
function Undertaker(customRegistry){
17+
function Undertaker(customRegistry) {
1818
EventEmitter.call(this);
1919

2020
this._registry = new DefaultRegistry();
21-
if(customRegistry){
21+
if (customRegistry) {
2222
this.registry(customRegistry);
2323
}
2424

lib/get-task.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22

33
var metadata = require('./helpers/metadata');
44

5-
function get(name){
6-
/* jshint validthis: true */
5+
function get(name) {
76
var wrapper = this._registry.get(name);
87

9-
if(!wrapper){
8+
if (!wrapper) {
109
return;
1110
}
1211

1312
var meta = metadata.get(wrapper);
1413

15-
if(meta){
14+
if (meta) {
1615
return meta.orig;
1716
}
1817

lib/helpers/buildTree.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ var _ = require('lodash');
44

55
var metadata = require('./metadata');
66

7-
function buildTree(tasks){
8-
return _.map(tasks, function(task){
7+
function buildTree(tasks) {
8+
return _.map(tasks, function(task) {
99
var meta = metadata.get(task);
10-
if(meta){
10+
if (meta) {
1111
return meta.tree;
1212
}
1313

@@ -17,8 +17,8 @@ function buildTree(tasks){
1717
tree: {
1818
label: name,
1919
type: 'function',
20-
nodes: []
21-
}
20+
nodes: [],
21+
},
2222
};
2323

2424
metadata.set(task, meta);

lib/helpers/createExtensions.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var metadata = require('./metadata');
77

88
var uid = 0;
99

10-
function Storage(fn){
10+
function Storage(fn) {
1111
var meta = metadata.get(fn);
1212

1313
this.fn = meta.orig || fn;
@@ -17,41 +17,41 @@ function Storage(fn){
1717
this.startHr = [];
1818
}
1919

20-
Storage.prototype.capture = function(){
20+
Storage.prototype.capture = function() {
2121
captureLastRun(this.fn, this.captureTime);
2222
};
2323

24-
Storage.prototype.release = function(){
24+
Storage.prototype.release = function() {
2525
releaseLastRun(this.fn);
2626
};
2727

28-
function createExtensions(ee){
28+
function createExtensions(ee) {
2929
return {
30-
create: function(fn){
30+
create: function(fn) {
3131
return new Storage(fn);
3232
},
33-
before: function(storage){
33+
before: function(storage) {
3434
storage.startHr = process.hrtime();
3535
ee.emit('start', {
3636
uid: storage.uid,
3737
name: storage.name,
38-
time: Date.now()
38+
time: Date.now(),
3939
});
4040
},
41-
after: function(result, storage){
42-
if(result && result.state === 'error'){
41+
after: function(result, storage) {
42+
if (result && result.state === 'error') {
4343
return this.error(result.value, storage);
4444
}
4545
storage.capture();
4646
ee.emit('stop', {
4747
uid: storage.uid,
4848
name: storage.name,
4949
duration: process.hrtime(storage.startHr),
50-
time: Date.now()
50+
time: Date.now(),
5151
});
5252
},
53-
error: function(error, storage){
54-
if(Array.isArray(error)){
53+
error: function(error, storage) {
54+
if (Array.isArray(error)) {
5555
error = error[0];
5656
}
5757
storage.release();
@@ -60,9 +60,9 @@ function createExtensions(ee){
6060
name: storage.name,
6161
error: error,
6262
duration: process.hrtime(storage.startHr),
63-
time: Date.now()
63+
time: Date.now(),
6464
});
65-
}
65+
},
6666
};
6767
}
6868

lib/helpers/normalizeArgs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ var assert = require('assert');
44

55
var _ = require('lodash');
66

7-
function normalizeArgs(registry, args){
8-
function getFunction(task){
9-
if(typeof task === 'function'){
7+
function normalizeArgs(registry, args) {
8+
function getFunction(task) {
9+
if (typeof task === 'function') {
1010
return task;
1111
}
1212

lib/helpers/validateRegistry.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ var assert = require('assert');
44

55
var _ = require('lodash');
66

7-
function isConstructor(registry){
8-
if(!(registry && registry.prototype)){
7+
function isConstructor(registry) {
8+
if (!(registry && registry.prototype)) {
99
return false;
1010
}
1111

@@ -14,21 +14,21 @@ function isConstructor(registry){
1414
var hasProtoInit = _.isFunction(registry.prototype.init);
1515
var hasProtoTasks = _.isFunction(registry.prototype.tasks);
1616

17-
if(hasProtoGet || hasProtoSet || hasProtoInit || hasProtoTasks){
17+
if (hasProtoGet || hasProtoSet || hasProtoInit || hasProtoTasks) {
1818
return true;
1919
}
2020

2121
return false;
2222
}
2323

24-
function validateRegistry(registry){
24+
function validateRegistry(registry) {
2525
try {
2626
assert(_.isFunction(registry.get), 'Custom registry must have `get` function');
2727
assert(_.isFunction(registry.set), 'Custom registry must have `set` function');
2828
assert(_.isFunction(registry.init), 'Custom registry must have `init` function');
2929
assert(_.isFunction(registry.tasks), 'Custom registry must have `tasks` function');
3030
} catch (err) {
31-
if(isConstructor(registry)){
31+
if (isConstructor(registry)) {
3232
assert(false, 'Custom registries must be instantiated, but it looks like you passed a constructor');
3333
} else {
3434
throw err;

lib/last-run.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
var retrieveLastRun = require('last-run');
44

55
function lastRun(task, timeResolution) {
6-
if(timeResolution == null){
6+
if (timeResolution == null) {
77
timeResolution = process.env.UNDERTAKER_TIME_RESOLUTION;
88
}
99

1010
var fn = task;
11-
if(typeof task === 'string'){
11+
if (typeof task === 'string') {
1212
fn = this._getTask(task);
1313
}
1414

lib/parallel.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ var buildTree = require('./helpers/buildTree');
77
var normalizeArgs = require('./helpers/normalizeArgs');
88
var createExtensions = require('./helpers/createExtensions');
99

10-
function parallel(){
11-
/* jshint validthis: true */
12-
10+
function parallel() {
1311
var create = this._settle ? bach.settleParallel : bach.parallel;
1412

1513
var args = normalizeArgs(this._registry, arguments);
@@ -21,8 +19,8 @@ function parallel(){
2119
tree: {
2220
label: '<parallel>',
2321
type: 'function',
24-
nodes: buildTree(args)
25-
}
22+
nodes: buildTree(args),
23+
},
2624
});
2725
return fn;
2826
}

lib/registry.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ var _ = require('lodash');
44

55
var validateRegistry = require('./helpers/validateRegistry');
66

7-
function setTasks(inst, task, name){
7+
function setTasks(inst, task, name) {
88
inst.set(name, task);
99
return inst;
1010
}
1111

12-
function registry(newRegistry){
13-
/* jshint validthis: true */
14-
if(!newRegistry){
12+
function registry(newRegistry) {
13+
if (!newRegistry) {
1514
return this._registry;
1615
}
1716

lib/series.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ var buildTree = require('./helpers/buildTree');
77
var normalizeArgs = require('./helpers/normalizeArgs');
88
var createExtensions = require('./helpers/createExtensions');
99

10-
function series(){
11-
/* jshint validthis: true */
12-
10+
function series() {
1311
var create = this._settle ? bach.settleSeries : bach.series;
1412

1513
var args = normalizeArgs(this._registry, arguments);
@@ -21,8 +19,8 @@ function series(){
2119
tree: {
2220
label: '<series>',
2321
type: 'function',
24-
nodes: buildTree(args)
25-
}
22+
nodes: buildTree(args),
23+
},
2624
});
2725
return fn;
2826
}

lib/set-task.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ var _ = require('lodash');
66

77
var metadata = require('./helpers/metadata');
88

9-
function set(name, fn){
10-
/* jshint validthis: true */
11-
9+
function set(name, fn) {
1210
assert(name, 'Task name must be specified');
1311
assert(typeof name === 'string', 'Task name must be a string');
1412
assert(_.isFunction(fn), 'Task function must be specified');
@@ -21,7 +19,7 @@ function set(name, fn){
2119

2220
var meta = metadata.get(fn) || {};
2321
var nodes = [];
24-
if(meta.branch){
22+
if (meta.branch) {
2523
nodes.push(meta.tree);
2624
}
2725

@@ -33,8 +31,8 @@ function set(name, fn){
3331
tree: {
3432
label: name,
3533
type: 'task',
36-
nodes: nodes
37-
}
34+
nodes: nodes,
35+
},
3836
});
3937
}
4038

lib/task.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
'use strict';
22

3-
function task(name, fn){
4-
/* jshint validthis: true */
5-
if(typeof name === 'function'){
3+
function task(name, fn) {
4+
if (typeof name === 'function') {
65
fn = name;
76
name = fn.displayName || fn.name;
87
}
98

10-
if(!fn){
9+
if (!fn) {
1110
return this._getTask(name);
1211
}
1312

lib/tree.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ var _ = require('lodash');
44

55
var metadata = require('./helpers/metadata');
66

7-
function tree(opts){
8-
/* jshint validthis: true */
7+
function tree(opts) {
98
opts = _.defaults(opts || {}, {
10-
deep: false
9+
deep: false,
1110
});
1211

1312
var tasks = this._registry.tasks();
14-
return _.map(tasks, function(task){
13+
return _.map(tasks, function(task) {
1514
var meta = metadata.get(task);
1615

17-
if(opts.deep){
16+
if (opts.deep) {
1817
return meta.tree;
1918
}
2019

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"lib"
1919
],
2020
"scripts": {
21-
"test": "lab -cvL --ignore store@sparkles"
21+
"lint": "eslint . && jscs *.js lib/ test/",
22+
"test": "lab -cv --ignore store@sparkles"
2223
},
2324
"dependencies": {
2425
"bach": "^0.4.1",
@@ -31,7 +32,11 @@
3132
"async-once": "^1.0.0",
3233
"code": "^1.2.1",
3334
"del": "^2.0.2",
35+
"eslint": "1.7.3",
36+
"eslint-config-gulp": "2.0.0",
3437
"gulp-jshint": "^1.8.4",
38+
"jscs": "2.3.5",
39+
"jscs-preset-gulp": "1.0.0",
3540
"lab": "^6.2.0",
3641
"once": "^1.3.1",
3742
"through2": "^2.0.0",

test/.eslintrc

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

0 commit comments

Comments
 (0)