Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit 98353fa

Browse files
authored
ref: Unify code style using Prettier and update ESLint rules
* Add Prettier, precommit hook using Husky and update ESLint to play nicely with Prettier. * Run new code-style setup on all relevant .js files, without any changes in the code itself. * Update ESLint version and unify package.json with the one from raven-js.
1 parent c7819f4 commit 98353fa

23 files changed

+804
-630
lines changed

.eslintrc

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,16 @@
33
"node": true,
44
"mocha": true,
55
},
6-
"extends": "eslint:recommended",
76
"rules": {
8-
"array-bracket-spacing": [2, "never"],
97
"block-scoped-var": 2,
10-
"brace-style": [2, "1tbs"],
118
"camelcase": [1, "properties": "never"],
129
"comma-dangle": 0,
13-
"comma-spacing": [2, {"before": false, "after": true}],
14-
"comma-style": [2, "last"],
15-
"computed-property-spacing": [2, "never"],
1610
"consistent-return": 2,
1711
"consistent-this": [2, "self"],
18-
"curly": [2, "multi-line"],
1912
"default-case": 2,
2013
"dot-notation": 2,
21-
"eol-last": 2,
2214
"eqeqeq": [2, "allow-null"],
2315
"guard-for-in": 2,
24-
"indent": [2, 2, {"SwitchCase": 1, "VariableDeclarator": { "var": 2, "let": 2, "const": 3}}],
25-
"key-spacing": [1, {"beforeColon": false, "afterColon": true}],
26-
"keyword-spacing": 2,
27-
"max-len": [1, 120],
2816
"new-cap": 2,
2917
"no-alert": 2,
3018
"no-caller": 2,
@@ -36,17 +24,13 @@
3624
"no-eval": 2,
3725
"no-extra-bind": 2,
3826
"no-extend-native": 2,
39-
"no-extra-parens": 2,
4027
"no-fallthrough": 2,
4128
"no-floating-decimal": 2,
4229
"no-implied-eval": 2,
4330
"no-inner-declarations": 2,
4431
"no-iterator": 2,
4532
"no-lonely-if": 2,
4633
"no-loop-func": 2,
47-
"no-mixed-spaces-and-tabs": 2,
48-
"no-multiple-empty-lines": [2, {"max": 2}],
49-
"no-multi-spaces": 2,
5034
"no-multi-str": 2,
5135
"no-new": 2,
5236
"no-param-reassign": 1,
@@ -58,8 +42,6 @@
5842
"no-sequences": 2,
5943
"no-shadow": 2,
6044
"no-shadow-restricted-names": 2,
61-
"no-spaced-func": 2,
62-
"no-trailing-spaces": 2,
6345
"no-undef": 2,
6446
"no-undefined": 2,
6547
"no-underscore-dangle": 0,
@@ -69,20 +51,13 @@
6951
"no-useless-escape": 2,
7052
"no-warning-comments": 0,
7153
"no-with": 2,
72-
"object-curly-spacing": [2, "always"],
73-
"quotes": [2, "single", "avoid-escape"],
74-
"semi": [2, "always"],
75-
"semi-spacing": [2, {"before": false, "after": true}],
76-
"space-before-blocks": 2,
77-
"space-before-function-paren": [2, {"anonymous": "always", "named": "never"}],
78-
"space-in-parens": 2,
79-
"space-infix-ops": 2,
80-
"space-unary-ops": 2,
8154
"spaced-comment": [2, "always"],
8255
"strict": [2, "global"],
8356
"valid-jsdoc": 0,
8457
"valid-typeof": 2,
85-
"wrap-iife": [2, "inside"],
8658
"yoda": [2, "never"]
87-
}
59+
},
60+
"extends": [
61+
"prettier"
62+
]
8863
}

lib/client.js

Lines changed: 70 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ nodeUtil.inherits(Raven, events.EventEmitter);
2525
extend(Raven.prototype, {
2626
config: function config(dsn, options) {
2727
// We get lots of users using raven-node when they want raven-js, hence this warning if it seems like a browser
28-
if (typeof window !== 'undefined' && typeof document !== 'undefined' && typeof navigator !== 'undefined') {
29-
utils.consoleAlertOnce('This looks like a browser environment; are you sure you don\'t want Raven.js for browser JavaScript? https://sentry.io/for/javascript');
28+
if (
29+
typeof window !== 'undefined' &&
30+
typeof document !== 'undefined' &&
31+
typeof navigator !== 'undefined'
32+
) {
33+
utils.consoleAlertOnce(
34+
"This looks like a browser environment; are you sure you don't want Raven.js for browser JavaScript? https://sentry.io/for/javascript"
35+
);
3036
}
3137

3238
if (arguments.length === 0) {
@@ -75,21 +81,21 @@ extend(Raven.prototype, {
7581
// enabled if a dsn is set
7682
this._enabled = !!this.dsn;
7783

78-
var globalContext = this._globalContext = {};
84+
var globalContext = (this._globalContext = {});
7985
if (options.tags) {
8086
globalContext.tags = options.tags;
8187
}
8288
if (options.extra) {
8389
globalContext.extra = options.extra;
8490
}
8591

86-
this.onFatalError = this.defaultOnFatalError = function (err, sendErr, eventId) {
92+
this.onFatalError = this.defaultOnFatalError = function(err, sendErr, eventId) {
8793
console.error(err && err.stack ? err.stack : err);
8894
process.exit(1);
8995
};
9096
this.uncaughtErrorHandler = this.makeErrorHandler();
9197

92-
this.on('error', function (err) {
98+
this.on('error', function(err) {
9399
utils.consoleAlert('failed to send exception to sentry: ' + err.message);
94100
});
95101

@@ -107,8 +113,8 @@ extend(Raven.prototype, {
107113

108114
if (this.captureUnhandledRejections) {
109115
var self = this;
110-
process.on('unhandledRejection', function (reason) {
111-
self.captureException(reason, function (sendErr, eventId) {
116+
process.on('unhandledRejection', function(reason) {
117+
self.captureException(reason, function(sendErr, eventId) {
112118
if (!sendErr) utils.consoleAlert('unhandledRejection captured: ' + eventId);
113119
});
114120
});
@@ -135,28 +141,30 @@ extend(Raven.prototype, {
135141
return this;
136142
},
137143

138-
makeErrorHandler: function () {
144+
makeErrorHandler: function() {
139145
var self = this;
140146
var caughtFirstError = false;
141147
var caughtSecondError = false;
142148
var calledFatalError = false;
143149
var firstError;
144-
return function (err) {
150+
return function(err) {
145151
if (!caughtFirstError) {
146152
// this is the first uncaught error and the ultimate reason for shutting down
147153
// we want to do absolutely everything possible to ensure it gets captured
148154
// also we want to make sure we don't go recursion crazy if more errors happen after this one
149155
firstError = err;
150156
caughtFirstError = true;
151-
self.captureException(err, function (sendErr, eventId) {
157+
self.captureException(err, function(sendErr, eventId) {
152158
if (!calledFatalError) {
153159
calledFatalError = true;
154160
self.onFatalError(err, sendErr, eventId);
155161
}
156162
});
157163
} else if (calledFatalError) {
158164
// we hit an error *after* calling onFatalError - pretty boned at this point, just shut it down
159-
utils.consoleAlert('uncaught exception after calling fatal error shutdown callback - this is bad! forcing shutdown');
165+
utils.consoleAlert(
166+
'uncaught exception after calling fatal error shutdown callback - this is bad! forcing shutdown'
167+
);
160168
self.defaultOnFatalError(err);
161169
} else if (!caughtSecondError) {
162170
// two cases for how we can hit this branch:
@@ -174,7 +182,7 @@ extend(Raven.prototype, {
174182
// note that after hitting this branch, we might catch more errors where (caughtSecondError && !calledFatalError)
175183
// we ignore them - they don't matter to us, we're just waiting for the second error timeout to finish
176184
caughtSecondError = true;
177-
setTimeout(function () {
185+
setTimeout(function() {
178186
if (!calledFatalError) {
179187
// it was probably case 1, let's treat err as the sendErr and call onFatalError
180188
calledFatalError = true;
@@ -199,10 +207,15 @@ extend(Raven.prototype, {
199207
eventId = this.generateEventId();
200208
}
201209

202-
var domainContext = domain.active && domain.active.sentryContext || {};
210+
var domainContext = (domain.active && domain.active.sentryContext) || {};
203211
kwargs.user = extend({}, this._globalContext.user, domainContext.user, kwargs.user);
204212
kwargs.tags = extend({}, this._globalContext.tags, domainContext.tags, kwargs.tags);
205-
kwargs.extra = extend({}, this._globalContext.extra, domainContext.extra, kwargs.extra);
213+
kwargs.extra = extend(
214+
{},
215+
this._globalContext.extra,
216+
domainContext.extra,
217+
kwargs.extra
218+
);
206219
kwargs.breadcrumbs = {
207220
values: domainContext.breadcrumbs || this._globalContext.breadcrumbs || []
208221
};
@@ -215,7 +228,12 @@ extend(Raven.prototype, {
215228
so we only parse a `req` property if the `request` property is absent/empty (and hence we won't clobber)
216229
parseUser returns a partial kwargs object with a `request` property and possibly a `user` property
217230
*/
218-
kwargs.request = extend({}, this._globalContext.request, domainContext.request, kwargs.request);
231+
kwargs.request = extend(
232+
{},
233+
this._globalContext.request,
234+
domainContext.request,
235+
kwargs.request
236+
);
219237
if (Object.keys(kwargs.request).length === 0) {
220238
var req = extend({}, this._globalContext.req, domainContext.req, kwargs.req);
221239
if (Object.keys(req).length > 0) {
@@ -259,9 +277,10 @@ extend(Raven.prototype, {
259277
// wish there was a good way to communicate to cb why we didn't send; worth considering cb api change?
260278
// could be shouldSendCallback, could be disabled, could be sample rate
261279
// avoiding setImmediate here because node 0.8
262-
cb && setTimeout(function () {
263-
cb(null, eventId);
264-
}, 0);
280+
cb &&
281+
setTimeout(function() {
282+
cb(null, eventId);
283+
}, 0);
265284
}
266285
},
267286

@@ -270,14 +289,18 @@ extend(Raven.prototype, {
270289
var skwargs = stringify(kwargs);
271290
var eventId = kwargs.event_id;
272291

273-
zlib.deflate(skwargs, function (err, buff) {
292+
zlib.deflate(skwargs, function(err, buff) {
274293
var message = buff.toString('base64'),
275-
timestamp = new Date().getTime(),
276-
headers = {
277-
'X-Sentry-Auth': utils.getAuthHeader(timestamp, self.dsn.public_key, self.dsn.private_key),
278-
'Content-Type': 'application/octet-stream',
279-
'Content-Length': message.length
280-
};
294+
timestamp = new Date().getTime(),
295+
headers = {
296+
'X-Sentry-Auth': utils.getAuthHeader(
297+
timestamp,
298+
self.dsn.public_key,
299+
self.dsn.private_key
300+
),
301+
'Content-Type': 'application/octet-stream',
302+
'Content-Length': message.length
303+
};
281304

282305
self.transport.send(self, message, headers, eventId, cb);
283306
});
@@ -313,14 +336,14 @@ extend(Raven.prototype, {
313336

314337
var self = this;
315338
var eventId = this.generateEventId();
316-
parsers.parseError(err, kwargs, function (kw) {
339+
parsers.parseError(err, kwargs, function(kw) {
317340
self.process(eventId, kw, cb);
318341
});
319342

320343
return eventId;
321344
},
322345

323-
context: function (ctx, func) {
346+
context: function(ctx, func) {
324347
if (!func && typeof ctx === 'function') {
325348
func = ctx;
326349
ctx = {};
@@ -332,7 +355,7 @@ extend(Raven.prototype, {
332355
return this.wrap(ctx, func).apply(null);
333356
},
334357

335-
wrap: function (options, func) {
358+
wrap: function(options, func) {
336359
if (!func && typeof options === 'function') {
337360
func = options;
338361
options = {};
@@ -359,13 +382,13 @@ extend(Raven.prototype, {
359382
return wrapped;
360383
},
361384

362-
interceptErr: function (options, func) {
385+
interceptErr: function(options, func) {
363386
if (!func && typeof options === 'function') {
364387
func = options;
365388
options = {};
366389
}
367390
var self = this;
368-
var wrapped = function () {
391+
var wrapped = function() {
369392
var err = arguments[0];
370393
if (err instanceof Error) {
371394
self.captureException(err, options);
@@ -412,10 +435,10 @@ extend(Raven.prototype, {
412435
return this._globalContext;
413436
},
414437

415-
setCallbackHelper: function (propertyName, callback) {
438+
setCallbackHelper: function(propertyName, callback) {
416439
var original = this[propertyName];
417440
if (typeof callback === 'function') {
418-
this[propertyName] = function (data) {
441+
this[propertyName] = function(data) {
419442
return callback(data, original);
420443
};
421444
} else {
@@ -432,7 +455,7 @@ extend(Raven.prototype, {
432455
* data blob to be mutated before sending
433456
* @return {Raven}
434457
*/
435-
setDataCallback: function (callback) {
458+
setDataCallback: function(callback) {
436459
return this.setCallbackHelper('dataCallback', callback);
437460
},
438461

@@ -443,42 +466,45 @@ extend(Raven.prototype, {
443466
* introspecting the blob before sending
444467
* @return {Raven}
445468
*/
446-
setShouldSendCallback: function (callback) {
469+
setShouldSendCallback: function(callback) {
447470
return this.setCallbackHelper('shouldSendCallback', callback);
448471
},
449472

450-
requestHandler: function () {
473+
requestHandler: function() {
451474
var self = this;
452-
return function (req, res, next) {
453-
self.context({ req: req }, function () {
475+
return function(req, res, next) {
476+
self.context({req: req}, function() {
454477
domain.active.add(req);
455478
domain.active.add(res);
456479
next();
457480
});
458481
};
459482
},
460483

461-
errorHandler: function () {
484+
errorHandler: function() {
462485
var self = this;
463-
return function (err, req, res, next) {
486+
return function(err, req, res, next) {
464487
var status = err.status || err.statusCode || err.status_code || 500;
465488

466489
// skip anything not marked as an internal server error
467490
if (status < 500) return next(err);
468491

469-
var eventId = self.captureException(err, { req: req });
492+
var eventId = self.captureException(err, {req: req});
470493
res.sentry = eventId;
471494
return next(err);
472495
};
473496
},
474497

475-
captureBreadcrumb: function (breadcrumb) {
498+
captureBreadcrumb: function(breadcrumb) {
476499
// Avoid capturing global-scoped breadcrumbs before instrumentation finishes
477500
if (!this.installed) return;
478501

479-
breadcrumb = extend({
480-
timestamp: +new Date / 1000
481-
}, breadcrumb);
502+
breadcrumb = extend(
503+
{
504+
timestamp: +new Date() / 1000
505+
},
506+
breadcrumb
507+
);
482508
var currCtx = this.getContext();
483509
if (!currCtx.breadcrumbs) currCtx.breadcrumbs = [];
484510
currCtx.breadcrumbs.push(breadcrumb);

0 commit comments

Comments
 (0)