Skip to content

Commit 170c731

Browse files
committed
build: Switch @sentry/node to using eslint
1 parent 3c7b107 commit 170c731

24 files changed

+145
-103
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ module.exports = {
9494
files: ['src/**/*'],
9595
rules: {
9696
// We want to prevent async await usage in our files to prevent uncessary bundle size.
97-
'sentry-sdk/no-async-await': 'error',
97+
'sentry-sdks/no-async-await': 'error',
9898

9999
// JSDOC comments are required for classes and methods. As we have a public facing codebase, documentation,
100100
// even if it may seems excessive at times, is important to emphasize. Turned off in tests.

packages/node/.eslintrc.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
es6: true,
5+
node: true,
6+
},
7+
parserOptions: {
8+
ecmaVersion: 2018,
9+
},
10+
extends: ['../../.eslintrc.js'],
11+
ignorePatterns: ['build/**/*', 'dist/**/*', 'esm/**/*', 'examples/**/*', 'scripts/**/*', 'test/manual/**/*'],
12+
overrides: [
13+
{
14+
files: ['*.ts', '*.tsx', '*.d.ts'],
15+
parserOptions: {
16+
project: './tsconfig.json',
17+
},
18+
},
19+
{
20+
files: ['test/**/*'],
21+
rules: {
22+
'@typescript-eslint/no-explicit-any': 'off',
23+
'@typescript-eslint/no-non-null-assertion': 'off',
24+
},
25+
},
26+
{
27+
files: ['test/**/*.js'],
28+
rules: {
29+
'import/order': 'off',
30+
},
31+
},
32+
],
33+
rules: {
34+
'prefer-rest-params': 'off',
35+
'@typescript-eslint/no-var-requires': 'off',
36+
'sentry-sdks/no-async-await': 'off',
37+
},
38+
};

packages/node/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,12 @@
4949
"build:watch:esm": "tsc -p tsconfig.esm.json -w --preserveWatchOutput",
5050
"clean": "rimraf dist coverage",
5151
"link:yarn": "yarn link",
52-
"lint": "run-s lint:prettier lint:tslint",
52+
"lint": "run-s lint:prettier lint:eslint",
5353
"lint:prettier": "prettier-check \"{src,test}/**/*.ts\"",
54-
"lint:tslint": "tslint -t stylish -p .",
55-
"lint:tslint:json": "tslint --format json -p . | tee lint-results.json",
56-
"fix": "run-s fix:tslint fix:prettier",
54+
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
55+
"fix": "run-s fix:eslint fix:prettier",
5756
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
58-
"fix:tslint": "tslint --fix -t stylish -p .",
57+
"fix:eslint": "eslint . --format stylish --fix",
5958
"test": "run-s test:jest test:express test:webpack",
6059
"test:jest": "jest",
6160
"test:watch": "jest --watch",

packages/node/src/backend.ts

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ import { HTTPSTransport, HTTPTransport } from './transports';
1919
* @see NodeClient for more information.
2020
*/
2121
export interface NodeOptions extends Options {
22-
/** Callback that is executed when a fatal global error occurs. */
23-
onFatalError?(error: Error): void;
24-
2522
/** Sets an optional server name (device name) */
2623
serverName?: string;
2724

@@ -39,6 +36,9 @@ export interface NodeOptions extends Options {
3936

4037
/** Sets the number of context lines for each frame when loading a file. */
4138
frameContextLines?: number;
39+
40+
/** Callback that is executed when a fatal global error occurs. */
41+
onFatalError?(error: Error): void;
4242
}
4343

4444
/**
@@ -49,35 +49,9 @@ export class NodeBackend extends BaseBackend<NodeOptions> {
4949
/**
5050
* @inheritDoc
5151
*/
52-
protected _setupTransport(): Transport {
53-
if (!this._options.dsn) {
54-
// We return the noop transport here in case there is no Dsn.
55-
return super._setupTransport();
56-
}
57-
58-
const dsn = new Dsn(this._options.dsn);
59-
60-
const transportOptions: TransportOptions = {
61-
...this._options.transportOptions,
62-
...(this._options.httpProxy && { httpProxy: this._options.httpProxy }),
63-
...(this._options.httpsProxy && { httpsProxy: this._options.httpsProxy }),
64-
...(this._options.caCerts && { caCerts: this._options.caCerts }),
65-
dsn: this._options.dsn,
66-
};
67-
68-
if (this._options.transport) {
69-
return new this._options.transport(transportOptions);
70-
}
71-
if (dsn.protocol === 'http') {
72-
return new HTTPTransport(transportOptions);
73-
}
74-
return new HTTPSTransport(transportOptions);
75-
}
76-
77-
/**
78-
* @inheritDoc
79-
*/
52+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
8053
public eventFromException(exception: any, hint?: EventHint): PromiseLike<Event> {
54+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8155
let ex: any = exception;
8256
const mechanism: Mechanism = {
8357
handled: true,
@@ -91,7 +65,7 @@ export class NodeBackend extends BaseBackend<NodeOptions> {
9165
const message = `Non-Error exception captured with keys: ${extractExceptionKeysForMessage(exception)}`;
9266

9367
getCurrentHub().configureScope(scope => {
94-
scope.setExtra('__serialized__', normalizeToSize(exception as {}));
68+
scope.setExtra('__serialized__', normalizeToSize(exception as Record<string, unknown>));
9569
});
9670

9771
ex = (hint && hint.syntheticException) || new Error(message);
@@ -147,4 +121,32 @@ export class NodeBackend extends BaseBackend<NodeOptions> {
147121
}
148122
});
149123
}
124+
125+
/**
126+
* @inheritDoc
127+
*/
128+
protected _setupTransport(): Transport {
129+
if (!this._options.dsn) {
130+
// We return the noop transport here in case there is no Dsn.
131+
return super._setupTransport();
132+
}
133+
134+
const dsn = new Dsn(this._options.dsn);
135+
136+
const transportOptions: TransportOptions = {
137+
...this._options.transportOptions,
138+
...(this._options.httpProxy && { httpProxy: this._options.httpProxy }),
139+
...(this._options.httpsProxy && { httpsProxy: this._options.httpsProxy }),
140+
...(this._options.caCerts && { caCerts: this._options.caCerts }),
141+
dsn: this._options.dsn,
142+
};
143+
144+
if (this._options.transport) {
145+
return new this._options.transport(transportOptions);
146+
}
147+
if (dsn.protocol === 'http') {
148+
return new HTTPTransport(transportOptions);
149+
}
150+
return new HTTPSTransport(transportOptions);
151+
}
150152
}

packages/node/src/handlers.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable max-lines */
2+
/* eslint-disable @typescript-eslint/no-explicit-any */
13
import { Span } from '@sentry/apm';
24
import { captureException, getCurrentHub, startTransaction, withScope } from '@sentry/core';
35
import { Event } from '@sentry/types';
@@ -253,7 +255,7 @@ export function parseRequest(
253255
},
254256
options?: ParseRequestOptions,
255257
): Event {
256-
// tslint:disable-next-line:no-parameter-reassignment
258+
// eslint-disable-next-line no-param-reassign
257259
options = {
258260
ip: false,
259261
request: true,
@@ -334,7 +336,7 @@ export function requestHandler(
334336
next: (error?: any) => void,
335337
): void {
336338
if (options && options.flushTimeout && options.flushTimeout > 0) {
337-
// tslint:disable-next-line: no-unbound-method
339+
// eslint-disable-next-line @typescript-eslint/unbound-method
338340
const _end = res.end;
339341
res.end = function(chunk?: any | (() => void), encoding?: string | (() => void), cb?: () => void): void {
340342
flush(options.flushTimeout)
@@ -403,6 +405,7 @@ export function errorHandler(options?: {
403405
res: http.ServerResponse,
404406
next: (error: MiddlewareError) => void,
405407
): void {
408+
// eslint-disable-next-line @typescript-eslint/unbound-method
406409
const shouldHandleError = (options && options.shouldHandleError) || defaultShouldHandleError;
407410

408411
if (shouldHandleError(error)) {
@@ -428,6 +431,7 @@ export function errorHandler(options?: {
428431
* @hidden
429432
*/
430433
export function logAndExitProcess(error: Error): void {
434+
// eslint-disable-next-line no-console
431435
console.error(error && error.stack ? error.stack : error);
432436

433437
const client = getCurrentHub().getClient<NodeClient>();

packages/node/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const carrier = getMainCarrier();
6363
if (carrier.__SENTRY__) {
6464
carrier.__SENTRY__.extensions = carrier.__SENTRY__.extensions || {};
6565
if (!carrier.__SENTRY__.extensions.domain) {
66-
// @ts-ignore
66+
// @ts-ignore domain is missing from extensions Type
6767
carrier.__SENTRY__.extensions.domain = domain;
6868
}
6969
}

packages/node/src/integrations/console.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ export class Console implements Integration {
88
/**
99
* @inheritDoc
1010
*/
11-
public name: string = Console.id;
11+
public static id: string = 'Console';
12+
1213
/**
1314
* @inheritDoc
1415
*/
15-
public static id: string = 'Console';
16+
public name: string = Console.id;
1617

1718
/**
1819
* @inheritDoc

packages/node/src/integrations/http.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ export class Http implements Integration {
1111
/**
1212
* @inheritDoc
1313
*/
14-
public name: string = Http.id;
14+
public static id: string = 'Http';
15+
1516
/**
1617
* @inheritDoc
1718
*/
18-
public static id: string = 'Http';
19+
public name: string = Http.id;
1920

2021
/**
2122
* @inheritDoc

packages/node/src/integrations/linkederrors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ export class LinkedErrors implements Integration {
1212
/**
1313
* @inheritDoc
1414
*/
15-
public readonly name: string = LinkedErrors.id;
15+
public static id: string = 'LinkedErrors';
1616

1717
/**
1818
* @inheritDoc
1919
*/
20-
public static id: string = 'LinkedErrors';
20+
public readonly name: string = LinkedErrors.id;
2121

2222
/**
2323
* @inheritDoc

packages/node/src/integrations/modules.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function collectModules(): {
99
[name: string]: string;
1010
} {
1111
const mainPaths = (require.main && require.main.paths) || [];
12-
const paths = require.cache ? Object.keys(require.cache as {}) : [];
12+
const paths = require.cache ? Object.keys(require.cache as Record<string, unknown>) : [];
1313
const infos: {
1414
[name: string]: string;
1515
} = {};
@@ -61,11 +61,12 @@ export class Modules implements Integration {
6161
/**
6262
* @inheritDoc
6363
*/
64-
public name: string = Modules.id;
64+
public static id: string = 'Modules';
65+
6566
/**
6667
* @inheritDoc
6768
*/
68-
public static id: string = 'Modules';
69+
public name: string = Modules.id;
6970

7071
/**
7172
* @inheritDoc

0 commit comments

Comments
 (0)