Permalink
Browse files

Convert 8 spaces indent to 4 - update linter

  • Loading branch information...
1 parent 22983f3 commit bcdbda4b97d6d4621b502c3bc1dc36e10c70fee8 @gergelyke gergelyke committed Feb 5, 2014
Showing with 7,388 additions and 7,483 deletions.
  1. +157 −161 bin/report-latency
  2. +2 −2 examples/CORS/cors.js
  3. +3 −3 examples/bench/bench.js
  4. +58 −58 examples/dtrace/demo.js
  5. +12 −12 examples/dtrace/hello.js
  6. +3 −3 examples/jsonp/jsonp.js
  7. +25 −27 examples/sockio/sockio.js
  8. +13 −13 examples/spdy/spdy.js
  9. +84 −87 examples/todoapp/lib/client.js
  10. +2 −2 examples/todoapp/lib/index.js
  11. +300 −305 examples/todoapp/lib/server.js
  12. +89 −89 examples/todoapp/main.js
  13. +88 −90 examples/todoapp/test/todo.test.js
  14. +151 −151 lib/bunyan_helper.js
  15. +382 −385 lib/clients/http_client.js
  16. +3 −3 lib/clients/index.js
  17. +56 −56 lib/clients/json_client.js
  18. +124 −125 lib/clients/string_client.js
  19. +52 −49 lib/dtrace.js
  20. +79 −84 lib/errors/http_error.js
  21. +2 −2 lib/errors/index.js
  22. +56 −59 lib/errors/rest_error.js
  23. +6 −7 lib/formatters/binary.js
  24. +4 −5 lib/formatters/index.js
  25. +17 −18 lib/formatters/json.js
  26. +24 −25 lib/formatters/jsonp.js
  27. +10 −11 lib/formatters/text.js
  28. +3 −3 lib/http_date.js
  29. +90 −91 lib/index.js
  30. +19 −19 lib/plugins/accept.js
  31. +75 −76 lib/plugins/audit.js
  32. +87 −90 lib/plugins/authorization.js
  33. +63 −65 lib/plugins/body_parser.js
  34. +89 −92 lib/plugins/body_reader.js
  35. +24 −26 lib/plugins/bunyan.js
  36. +138 −141 lib/plugins/conditional_request.js
  37. +60 −64 lib/plugins/cors.js
  38. +34 −36 lib/plugins/date.js
  39. +54 −55 lib/plugins/fielded_text_body_parser.js
  40. +39 −41 lib/plugins/form_body_parser.js
  41. +58 −62 lib/plugins/full_response.js
  42. +32 −33 lib/plugins/gzip.js
  43. +23 −23 lib/plugins/index.js
  44. +41 −42 lib/plugins/json_body_parser.js
  45. +10 −11 lib/plugins/jsonp.js
  46. +53 −54 lib/plugins/multipart_parser.js
  47. +37 −39 lib/plugins/pre/pause.js
  48. +18 −20 lib/plugins/pre/pre_path.js
  49. +17 −18 lib/plugins/pre/user_agent.js
  50. +20 −21 lib/plugins/query.js
  51. +102 −103 lib/plugins/static.js
  52. +103 −108 lib/plugins/throttle.js
  53. +153 −155 lib/request.js
  54. +162 −164 lib/response.js
  55. +372 −376 lib/router.js
  56. +510 −512 lib/server.js
  57. +83 −83 lib/upgrade.js
  58. +17 −20 lib/utils.js
  59. +542 −545 test/client.test.js
  60. +70 −71 test/fieldedTextParser.test.js
  61. +72 −73 test/formatter.test.js
  62. +14 −16 test/index.test.js
  63. +78 −79 test/lib/helper.js
  64. +612 −604 test/plugins.test.js
  65. +1,196 −1,198 test/server.test.js
  66. +85 −89 test/throttle.test.js
  67. +330 −332 test/upgrade.test.js
  68. +1 −1 tools/jsstyle.conf
View
@@ -10,214 +10,210 @@ var sprintf = require('util').format;
var nopt = require('nopt');
-
-
///--- Globals
var BUCKETS = {};
var REQUEST_IDS = {};
var OPTS = {
- 'average': Boolean,
- 'help': Boolean,
- 'end': Date,
- 'max-latency': Number,
- 'max-requests': Number,
- 'output': String,
- 'percentile': [Number, Array],
- 'period': Number,
- 'requests': Boolean,
- 'start': Date
+ 'average': Boolean,
+ 'help': Boolean,
+ 'end': Date,
+ 'max-latency': Number,
+ 'max-requests': Number,
+ 'output': String,
+ 'percentile': [Number, Array],
+ 'period': Number,
+ 'requests': Boolean,
+ 'start': Date
};
var SHORT_OPTS = {
- 'a': ['--average'],
- 'h': ['--help'],
- 'i': ['--period'],
- 'e': ['--end'],
- 'l': ['--max-latency'],
- 'n': ['--max-requests'],
- 'o': ['--output'],
- 'p': ['--percentile'],
- 'r': ['--requests'],
- 's': ['--start']
+ 'a': ['--average'],
+ 'h': ['--help'],
+ 'i': ['--period'],
+ 'e': ['--end'],
+ 'l': ['--max-latency'],
+ 'n': ['--max-requests'],
+ 'o': ['--output'],
+ 'p': ['--percentile'],
+ 'r': ['--requests'],
+ 's': ['--start']
};
-
-
///--- Functions
function percentile(p, vals) {
- p = parseInt(p, 10);
- return vals[(Math.round(((p/100) * vals.length) + 1/2) - 1)].latency;
+ p = parseInt(p, 10);
+ return vals[(Math.round(((p / 100) * vals.length) + 1 / 2) - 1)].latency;
}
function report(buckets, output) {
- Object.keys(buckets).sort(function (a, b) {
- return parseInt(a, 10) - parseInt(b, 10);
- }).forEach(function (k) {
- var avg = 0;
- var perc = [];
- var req = buckets[k].length;
- var sum = 0;
- var t = Math.round(buckets[k]._time);
-
- buckets[k] = buckets[k].sort(function (a, b) {
- return a.latency - b.latency;
+ Object.keys(buckets).sort(function (a, b) {
+ return parseInt(a, 10) - parseInt(b, 10);
+ }).forEach(function (k) {
+ var avg = 0;
+ var perc = [];
+ var req = buckets[k].length;
+ var sum = 0;
+ var t = Math.round(buckets[k]._time);
+
+ buckets[k] = buckets[k].sort(function (a, b) {
+ return a.latency - b.latency;
+ });
+
+ buckets[k].forEach(function (v) {
+ sum += v.latency;
+ });
+
+ if (sum > 0 && req > 0) {
+ if (output.average)
+ output.average.push([t, Math.round(sum / req)]);
+ if (output.requests)
+ output.requests.push([t, buckets[k].length]);
+ Object.keys(output.percentile).forEach(function (p) {
+ var _p = percentile(p, buckets[k]);
+ output.percentile[p].push([t, _p]);
});
-
- buckets[k].forEach(function (v) {
- sum += v.latency;
- });
-
- if (sum > 0 && req > 0) {
- if (output.average)
- output.average.push([t, Math.round(sum/req)]);
- if (output.requests)
- output.requests.push([t, buckets[k].length]);
- Object.keys(output.percentile).forEach(function (p) {
- var _p = percentile(p, buckets[k]);
- output.percentile[p].push([t, _p]);
- });
- }
+ }
});
- return output;
+ return output;
}
function usage(code, message) {
- var str = '';
- Object.keys(SHORT_OPTS).forEach(function(k) {
- if (!Array.isArray(SHORT_OPTS[k]))
- return;
-
- var opt = SHORT_OPTS[k][0].replace('--', '');
- var type = OPTS[opt].name || 'string';
- if (type && type === 'boolean')
- type = '';
- type = type.toLowerCase();
-
- str += ' [--' + opt + ' ' + type + ']';
- });
- str += ' [file ...]';
-
- if (message)
- console.error(message);
-
- console.error('usage: ' + path.basename(process.argv[1]) + str);
- process.exit(code);
+ var str = '';
+ Object.keys(SHORT_OPTS).forEach(function (k) {
+ if (!Array.isArray(SHORT_OPTS[k]))
+ return;
+
+ var opt = SHORT_OPTS[k][0].replace('--', '');
+ var type = OPTS[opt].name || 'string';
+ if (type && type === 'boolean')
+ type = '';
+ type = type.toLowerCase();
+
+ str += ' [--' + opt + ' ' + type + ']';
+ });
+ str += ' [file ...]';
+
+ if (message)
+ console.error(message);
+
+ console.error('usage: ' + path.basename(process.argv[1]) + str);
+ process.exit(code);
}
-
///--- Mainline
var parsed;
try {
- parsed = nopt(OPTS, SHORT_OPTS, process.argv, 2);
+ parsed = nopt(OPTS, SHORT_OPTS, process.argv, 2);
} catch (e) {
- usage(1, e.toString());
+ usage(1, e.toString());
}
if (parsed.help)
- usage(0);
+ usage(0);
if (!parsed.average && !parsed.percentile)
- usage(1, '--average or --percentile required');
+ usage(1, '--average or --percentile required');
if (parsed.argv.remain.length < 1)
- usage(1, 'log file required');
+ usage(1, 'log file required');
var config = {
- average: parsed.average || false,
- maxLatency: parsed['max-latency'] || 1000,
- maxRequests: parsed['max-requests'] || 10000,
- percentile: parsed.percentile || [],
- period: parsed.period || 60,
- requests: parsed.requests || false,
- start: parsed.start ? (parsed.start.getTime() / 1000) : 0,
- end: parsed.end ? (parsed.end.getTime() / 1000) : Number.MAX_VALUE
+ average: parsed.average || false,
+ maxLatency: parsed['max-latency'] || 1000,
+ maxRequests: parsed['max-requests'] || 10000,
+ percentile: parsed.percentile || [],
+ period: parsed.period || 60,
+ requests: parsed.requests || false,
+ start: parsed.start ? (parsed.start.getTime() / 1000) : 0,
+ end: parsed.end ? (parsed.end.getTime() / 1000) : Number.MAX_VALUE
};
var buckets = {};
var done = 0;
parsed.argv.remain.forEach(function (f) {
- var stream = readline.createInterface({
- input: fs.createReadStream(f),
- output: null
- })
- stream.on('line', function (l) {
- var record;
- var t = -1;
-
- try {
- record = JSON.parse(l);
- } catch (e) {}
-
- if (!record)
- return;
-
- var t = -1;
- if (record.time)
- t = (new Date(record.time).getTime() / 1000);
-
- if (record._audit !== true ||
- REQUEST_IDS[record.req_id] ||
- t < config.start ||
- t > config.end) {
-
- console.error('Skipping %s', l);
- }
-
- REQUEST_IDS[record.req_id] = true;
- record.time = t;
-
- var b = Math.round(record.time / config.period) + '';
- if (!buckets[b])
- buckets[b] = [];
-
- buckets[b].push(record);
- buckets[b]._time = record.time // good enough
- });
+ var stream = readline.createInterface({
+ input: fs.createReadStream(f),
+ output: null
+ })
+ stream.on('line', function (l) {
+ var record;
+ var t = -1;
+
+ try {
+ record = JSON.parse(l);
+ } catch (e) {
+ }
+
+ if (!record)
+ return;
+
+ var t = -1;
+ if (record.time)
+ t = (new Date(record.time).getTime() / 1000);
+
+ if (record._audit !== true ||
+ REQUEST_IDS[record.req_id] ||
+ t < config.start ||
+ t > config.end) {
+
+ console.error('Skipping %s', l);
+ }
+
+ REQUEST_IDS[record.req_id] = true;
+ record.time = t;
+
+ var b = Math.round(record.time / config.period) + '';
+ if (!buckets[b])
+ buckets[b] = [];
+
+ buckets[b].push(record);
+ buckets[b]._time = record.time // good enough
+ });
+
+ stream.on('end', function () {
+ if (++done === parsed.argv.remain.length) {
+ console.error('Generating report...');
+
+ var output = {
+ average: config.average ? [] : false,
+ requests: config.requests ? [] : false,
+ percentile: {}
+ };
+ config.percentile.forEach(function (p) {
+ output.percentile[p] = [];
+ });
+
+ output = report(buckets, output);
+ var finalOutput = [];
+ if (output.average) {
+ finalOutput.push({
+ name: 'avg',
+ values: output.average
+ });
+ }
+ if (output.requests) {
+ finalOutput.push({
+ name: 'n',
+ values: output.requests
+ });
+ }
+ Object.keys(output.percentile).forEach(function (k) {
+ finalOutput.push({
+ name: 'p' + k,
+ values: output.percentile[k]
+ });
+ });
- stream.on('end', function () {
- if (++done === parsed.argv.remain.length) {
- console.error('Generating report...');
-
- var output = {
- average: config.average ? [] : false,
- requests: config.requests ? [] : false,
- percentile: {}
- };
- config.percentile.forEach(function (p) {
- output.percentile[p] = [];
- });
-
- output = report(buckets, output);
- var finalOutput = [];
- if (output.average) {
- finalOutput.push({
- name: 'avg',
- values: output.average
- });
- }
- if (output.requests) {
- finalOutput.push({
- name: 'n',
- values: output.requests
- });
- }
- Object.keys(output.percentile).forEach(function (k) {
- finalOutput.push({
- name: 'p' + k,
- values: output.percentile[k]
- });
- });
-
- console.log(JSON.stringify(finalOutput));
- }
- });
+ console.log(JSON.stringify(finalOutput));
+ }
+ });
});
View
@@ -4,8 +4,8 @@ var srv = restify.createServer();
srv.use(restify.CORS());
function foo(req, res, next) {
- res.send(204);
- next();
+ res.send(204);
+ next();
}
srv.put('/foo', foo);
View
@@ -2,10 +2,10 @@ var server = require('../../lib').createServer();
//var server = require('express')();
server.get('/echo/:name', function (req, res, next) {
- res.setHeader('content-type', 'text/plain');
- res.send(200, req.params.name);
+ res.setHeader('content-type', 'text/plain');
+ res.send(200, req.params.name);
});
server.listen(8080, function () {
- console.log('ready');
+ console.log('ready');
});
Oops, something went wrong.

0 comments on commit bcdbda4

Please sign in to comment.