Skip to content

Commit 4e3fb2c

Browse files
committed
jscs update
1 parent ec64da3 commit 4e3fb2c

File tree

13 files changed

+410
-392
lines changed

13 files changed

+410
-392
lines changed

.jscs.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,26 @@
2424
"requireParenthesesAroundIIFE": true,
2525

2626
"requireSpaceBeforeBlockStatements": true,
27+
"disallowNewlineBeforeBlockStatements": true,
2728

2829
"requireSpacesInConditionalExpression": true,
2930

3031
"requireSpacesInFunctionExpression": {
3132
"beforeOpeningCurlyBrace": true
3233
},
3334

35+
"disallowSpacesInAnonymousFunctionExpression": {
36+
"beforeOpeningRoundBrace": true
37+
},
38+
39+
"disallowSpacesInFunctionDeclaration": {
40+
"beforeOpeningRoundBrace": true
41+
},
42+
43+
"disallowSpacesInFunctionExpression": {
44+
"beforeOpeningRoundBrace": true
45+
},
46+
3447
"requireSpaceBeforeBinaryOperators": [
3548
"+",
3649
"-",
@@ -62,6 +75,12 @@
6275

6376
"safeContextKeyword": "self",
6477

78+
"maximumLineLength": {
79+
"value": 120,
80+
"allowUrlComments": true,
81+
"allowRegex": true
82+
},
83+
6584
"validateIndentation": 4,
6685
"validateParameterSeparator": ", ",
6786

examples/example.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ var ttl; //Can't use a different ttl per set() call with memory cache
88
//
99
// Basic usage
1010
//
11-
memory_cache.set('foo', 'bar', ttl, function (err) {
11+
memory_cache.set('foo', 'bar', ttl, function(err) {
1212
if (err) { throw err; }
1313

14-
memory_cache.get('foo', function (err, result) {
14+
memory_cache.get('foo', function(err, result) {
1515
console.log(result);
1616
// >> 'bar'
17-
memory_cache.del('foo', function (err) {
17+
memory_cache.del('foo', function(err) {
1818
if (err) {
1919
console.log(err);
2020
}
@@ -23,7 +23,7 @@ memory_cache.set('foo', 'bar', ttl, function (err) {
2323
});
2424

2525
function get_user(id, cb) {
26-
setTimeout(function () {
26+
setTimeout(function() {
2727
console.log("Fetching user from slow database.");
2828
cb(null, {id: id, name: 'Bob'});
2929
}, 100);
@@ -38,14 +38,14 @@ var key = 'user_' + user_id;
3838

3939
// Instead of manually managing the cache like this:
4040
function get_cached_user_manually(id, cb) {
41-
memory_cache.get(id, function (err, result) {
41+
memory_cache.get(id, function(err, result) {
4242
if (err) { return cb(err); }
4343

4444
if (result) {
4545
return cb(null, result);
4646
}
4747

48-
get_user(id, function (err, result) {
48+
get_user(id, function(err, result) {
4949
if (err) { return cb(err); }
5050
memory_cache.set(id, result);
5151
cb(null, result);
@@ -55,16 +55,16 @@ function get_cached_user_manually(id, cb) {
5555

5656
// ... you can instead use the `wrap` function:
5757
function get_cached_user(id, cb) {
58-
memory_cache.wrap(id, function (cache_callback) {
58+
memory_cache.wrap(id, function(cache_callback) {
5959
get_user(id, cache_callback);
6060
}, cb);
6161
}
6262

63-
get_cached_user(user_id, function (err, user) {
63+
get_cached_user(user_id, function(err, user) {
6464
// First time fetches the user from the (fake) database:
6565
console.log(user);
6666

67-
get_cached_user(user_id, function (err, user) {
67+
get_cached_user(user_id, function(err, user) {
6868
// Second time fetches from cache.
6969
console.log(user);
7070
});
@@ -76,15 +76,15 @@ get_cached_user(user_id, function (err, user) {
7676
// { id: 123, name: 'Bob' }
7777

7878
// Same as above, but written differently:
79-
memory_cache.wrap(key, function (cb) {
79+
memory_cache.wrap(key, function(cb) {
8080
get_user(user_id, cb);
81-
}, function (err, user) {
81+
}, function(err, user) {
8282
console.log(user);
8383

8484
// Second time fetches user from memory_cache
85-
memory_cache.wrap(key, function (cb) {
85+
memory_cache.wrap(key, function(cb) {
8686
get_user(user_id, cb);
87-
}, function (err, user) {
87+
}, function(err, user) {
8888
console.log(user);
8989
});
9090
});
@@ -97,31 +97,31 @@ var user_id2 = 456;
9797
var key2 = 'user_' + user_id;
9898
var ttl2; //Can't use a different ttl per set() call with memory cache
9999

100-
multi_cache.wrap(key2, function (cb) {
100+
multi_cache.wrap(key2, function(cb) {
101101
get_user(user_id2, cb);
102-
}, function (err, user) {
102+
}, function(err, user) {
103103
console.log(user);
104104

105105
// Second time fetches user from memory_cache, since it's highest priority.
106106
// If the data expires in the memory cache, the next fetch would pull it from
107107
// the Redis cache, and set the data in memory again.
108-
multi_cache.wrap(key2, function (cb) {
108+
multi_cache.wrap(key2, function(cb) {
109109
get_user(user_id2, cb);
110-
}, function (err, user) {
110+
}, function(err, user) {
111111
console.log(user);
112112
});
113113

114114
// Sets in all caches.
115-
multi_cache.set('foo2', 'bar2', ttl2, function (err) {
115+
multi_cache.set('foo2', 'bar2', ttl2, function(err) {
116116
if (err) { throw err; }
117117

118118
// Fetches from highest priority cache that has the key.
119-
multi_cache.get('foo2', function (err, result) {
119+
multi_cache.get('foo2', function(err, result) {
120120
console.log(result);
121121
// >> 'bar2'
122122

123123
// Delete from all caches
124-
multi_cache.del('foo2', function (err) {
124+
multi_cache.del('foo2', function(err) {
125125
if (err) {
126126
console.log(err);
127127
}

examples/redis_example/example.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ var redis_cache = cache_manager.caching({store: redis_store, db: 0, ttl: 100});
1010
var ttl = 60;
1111

1212
console.log("set/get/del example:");
13-
redis_cache.set('foo', 'bar', ttl, function (err) {
13+
redis_cache.set('foo', 'bar', ttl, function(err) {
1414
if (err) { throw err; }
1515

16-
redis_cache.get('foo', function (err, result) {
16+
redis_cache.get('foo', function(err, result) {
1717
if (err) { throw err; }
1818
console.log("result fetched from cache: " + result);
1919
// >> 'bar'
20-
redis_cache.del('foo', function (err) {
20+
redis_cache.del('foo', function(err) {
2121
if (err) { throw err; }
2222
});
2323
});
@@ -30,32 +30,32 @@ function create_key(id) {
3030
}
3131

3232
function get_user(id, cb) {
33-
setTimeout(function () {
33+
setTimeout(function() {
3434
console.log("\n\nReturning user from slow database.");
3535
cb(null, {id: id, name: 'Bob'});
3636
}, 100);
3737
}
3838

3939
function get_user_from_cache(id, cb) {
4040
var key = create_key(id);
41-
redis_cache.wrap(key, function (cache_cb) {
41+
redis_cache.wrap(key, function(cache_cb) {
4242
get_user(user_id, cache_cb);
4343
}, ttl, cb);
4444
}
4545

46-
get_user_from_cache(user_id, function (err, user) {
46+
get_user_from_cache(user_id, function(err, user) {
4747
console.log(user);
4848

4949
// Second time fetches user from redis_cache
50-
get_user_from_cache(user_id, function (err, user) {
50+
get_user_from_cache(user_id, function(err, user) {
5151
console.log("user from second cache request:");
5252
console.log(user);
5353

54-
redis_cache.keys(function (err, keys) {
54+
redis_cache.keys(function(err, keys) {
5555
console.log("keys: " + util.inspect(keys));
5656

5757
var key = create_key(user_id);
58-
redis_cache.del(key, function (err) {
58+
redis_cache.del(key, function(err) {
5959
if (err) { throw err; }
6060
process.exit();
6161
});

examples/redis_example/redis_store.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function redis_store(args) {
2020
var pool = new RedisPool(redis_options);
2121

2222
function connect(cb) {
23-
pool.acquire(function (err, conn) {
23+
pool.acquire(function(err, conn) {
2424
if (err) {
2525
pool.release(conn);
2626
return cb(err);
@@ -34,58 +34,58 @@ function redis_store(args) {
3434
});
3535
}
3636

37-
self.get = function (key, cb) {
38-
connect(function (err, conn) {
37+
self.get = function(key, cb) {
38+
connect(function(err, conn) {
3939
if (err) { return cb(err); }
4040

41-
conn.get(key, function (err, result) {
41+
conn.get(key, function(err, result) {
4242
pool.release(conn);
4343
if (err) { return cb(err); }
4444
cb(null, JSON.parse(result));
4545
});
4646
});
4747
};
4848

49-
self.set = function (key, value, ttl, cb) {
49+
self.set = function(key, value, ttl, cb) {
5050
var ttlToUse = ttl || ttlDefault;
51-
connect(function (err, conn) {
51+
connect(function(err, conn) {
5252
if (err) { return cb(err); }
5353

5454
if (ttlToUse) {
55-
conn.setex(key, ttlToUse, JSON.stringify(value), function (err, result) {
55+
conn.setex(key, ttlToUse, JSON.stringify(value), function(err, result) {
5656
pool.release(conn);
5757
cb(err, result);
5858
});
5959
} else {
60-
conn.set(key, JSON.stringify(value), function (err, result) {
60+
conn.set(key, JSON.stringify(value), function(err, result) {
6161
pool.release(conn);
6262
cb(err, result);
6363
});
6464
}
6565
});
6666
};
6767

68-
self.del = function (key, cb) {
69-
connect(function (err, conn) {
68+
self.del = function(key, cb) {
69+
connect(function(err, conn) {
7070
if (err) { return cb(err); }
7171

72-
conn.del(key, function (err, result) {
72+
conn.del(key, function(err, result) {
7373
pool.release(conn);
7474
cb(err, result);
7575
});
7676
});
7777
};
7878

79-
self.keys = function (pattern, cb) {
79+
self.keys = function(pattern, cb) {
8080
if (typeof pattern === 'function') {
8181
cb = pattern;
8282
pattern = '*';
8383
}
8484

85-
connect(function (err, conn) {
85+
connect(function(err, conn) {
8686
if (err) { return cb(err); }
8787

88-
conn.keys(pattern, function (err, result) {
88+
conn.keys(pattern, function(err, result) {
8989
pool.release(conn);
9090
cb(err, result);
9191
});
@@ -96,7 +96,7 @@ function redis_store(args) {
9696
}
9797

9898
module.exports = {
99-
create: function (args) {
99+
create: function(args) {
100100
return redis_store(args);
101101
}
102102
};

lib/caching.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*jshint maxcomplexity:15*/
22
var domain = require('domain');
33

4-
var caching = function (args) {
4+
var caching = function(args) {
55
args = args || {};
66
var self = {};
77
if (typeof args.store === 'object') {
@@ -36,7 +36,7 @@ var caching = function (args) {
3636
* console.log(user);
3737
* });
3838
*/
39-
self.wrap = function (key, work, ttl, cb) {
39+
self.wrap = function(key, work, ttl, cb) {
4040
if (typeof ttl === 'function') {
4141
cb = ttl;
4242
ttl = undefined;
@@ -57,7 +57,7 @@ var caching = function (args) {
5757
delete self.queues[key];
5858
}
5959

60-
self.store.get(key, function (err, result) {
60+
self.store.get(key, function(err, result) {
6161
if (err && (!self.ignoreCacheErrors)) {
6262
fillCallbacks(err);
6363
} else if (result) {
@@ -68,12 +68,12 @@ var caching = function (args) {
6868
.on('error', function(err) {
6969
fillCallbacks(err);
7070
})
71-
.bind(work)(function (err, data) {
71+
.bind(work)(function(err, data) {
7272
if (err) {
7373
fillCallbacks(err);
7474
return;
7575
}
76-
self.store.set(key, data, ttl, function (err) {
76+
self.store.set(key, data, ttl, function(err) {
7777
if (err && (!self.ignoreCacheErrors)) {
7878
fillCallbacks(err);
7979
} else {

0 commit comments

Comments
 (0)