Skip to content

build: Convert core, hub, minimal and types to use eslint #2794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
# THIS WILL BE REMOVED AFTER WE FINISH ESLINT UPGRADE

packages/apm/**/*
packages/core/**/*
packages/ember/**/*
packages/gatsby/**/*
packages/hub/**/*
packages/integrations/**/*
packages/minimal/**/*
packages/node/**/*
packages/react/**/*
packages/tracing/**/*
packages/types/**/*
packages/typescript/**/*
packages/utils/**/*
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ module.exports = {
files: ['*.test.ts', '*.test.tsx', '*.test.js', '*.test.jsx'],
rules: {
'max-lines': 'off',

'@typescript-eslint/explicit-function-return-type': 'off',
},
},
{
Expand Down Expand Up @@ -123,5 +125,8 @@ module.exports = {

// Limit maximum file size to reduce complexity. Turned off in tests.
'max-lines': 'error',

// We should require a whitespace beginning a comment
'spaced-comment': 'error',
},
};
2 changes: 1 addition & 1 deletion dangerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tslint from 'danger-plugin-tslint';
import { prettyResults } from 'danger-plugin-tslint/dist/prettyResults';
import { CLIEngine } from 'eslint';

const PACKAGES = ['apm', 'core', 'hub', 'integrations', 'minimal', 'node', 'types', 'utils'];
const PACKAGES = ['apm', 'integrations', 'node', 'utils'];
const EXTENSIONS = ['.js', '.jsx', '.ts', '.tsx'];

/**
Expand Down
5 changes: 2 additions & 3 deletions packages/browser/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,8 @@ export function wrap(
},
});
}
} catch (_oO) {
/*no-empty*/
}
// eslint-disable-next-line no-empty
} catch (_oO) {}

return sentryWrapped;
}
Expand Down
1 change: 1 addition & 0 deletions packages/browser/test/integration/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function supportsOnunhandledRejection() {
}

function isBelowIE11() {
// eslint-disable-next-line spaced-comment
return /*@cc_on!@*/ false == !false;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/browser/test/integration/polyfills/fetch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*!
/* !
* @overview whatwg-fetch - an implementation of Fetch API.
* @copyright Copyright (c) 2014-2016 GitHub, Inc.
* @license Licensed under MIT license
Expand Down
8 changes: 4 additions & 4 deletions packages/browser/test/integration/polyfills/promise.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*!
/* !
* @overview es6-promise - an implementation of Promise API.
* @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
* @license Licensed under MIT license
Expand Down Expand Up @@ -222,7 +222,7 @@
`value`
*/
function resolve$1(object) {
/*jshint validthis:true */
/* jshint validthis:true */
var Constructor = this;

if (
Expand Down Expand Up @@ -722,7 +722,7 @@
promise to settle.
*/
function race(entries) {
/*jshint validthis:true */
/* jshint validthis:true */
var Constructor = this;

if (!isArray(entries)) {
Expand Down Expand Up @@ -774,7 +774,7 @@
@return {Promise} a promise rejected with the given `reason`.
*/
function reject$1(reason) {
/*jshint validthis:true */
/* jshint validthis:true */
var Constructor = this;
var promise = new Constructor(noop);
reject(promise, reason);
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/test/integration/suites/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ if (IS_LOADER) {
setTimeout(function() {
Sentry.captureMessage("test");
});
undefinedMethod(); //trigger error
undefinedMethod(); // trigger error
}).then(function(summary) {
assert.ok(summary.events[0].breadcrumbs);
assert.lengthOf(summary.events[0].breadcrumbs, 1);
Expand Down
26 changes: 26 additions & 0 deletions packages/core/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
root: true,
env: {
es6: true,
},
parserOptions: {
ecmaVersion: 2018,
},
extends: ['../../.eslintrc.js'],
ignorePatterns: ['build/**/*', 'dist/**/*', 'esm/**/*', 'examples/**/*', 'scripts/**/*'],
overrides: [
{
files: ['*.ts', '*.tsx', '*.d.ts'],
parserOptions: {
project: './tsconfig.json',
},
},
{
files: ['test/**/*'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
},
},
],
};
11 changes: 5 additions & 6 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"prettier": "^1.17.0",
"prettier-check": "^2.0.0",
"rimraf": "^2.6.3",
"tslint": "5.16.0",
"typescript": "3.4.5"
},
"scripts": {
Expand All @@ -40,13 +39,13 @@
"build:watch:esm": "tsc -p tsconfig.esm.json -w --preserveWatchOutput",
"clean": "rimraf dist coverage",
"link:yarn": "yarn link",
"lint": "run-s lint:prettier lint:tslint",
"lint": "run-s lint:prettier lint:eslint",
"lint:prettier": "prettier-check \"{src,test}/**/*.ts\"",
"lint:tslint": "tslint -t stylish -p .",
"lint:tslint:json": "tslint --format json -p . | tee lint-results.json",
"fix": "run-s fix:tslint fix:prettier",
"lint:eslint": "eslint . --format stylish",
"lint:eslint:json": "eslint . --format json | tee lint-results.json",
"fix": "run-s fix:eslint fix:prettier",
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
"fix:tslint": "tslint --fix -t stylish -p .",
"fix:eslint": "lint:eslint --fix",
"test": "jest",
"test:watch": "jest --watch"
},
Expand Down
49 changes: 25 additions & 24 deletions packages/core/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,6 @@ export class API {
return this._getIngestEndpoint('store');
}

/** Returns the envelope endpoint URL. */
private _getEnvelopeEndpoint(): string {
return this._getIngestEndpoint('envelope');
}

/** Returns the ingest API endpoint for target. */
private _getIngestEndpoint(target: 'store' | 'envelope'): string {
const base = this.getBaseApiEndpoint();
const dsn = this._dsnObject;
return `${base}${dsn.projectId}/${target}/`;
}

/**
* Returns the store endpoint URL with auth in the query string.
*
Expand All @@ -60,18 +48,6 @@ export class API {
return `${this._getEnvelopeEndpoint()}?${this._encodedAuth()}`;
}

/** Returns a URL-encoded string with auth config suitable for a query string. */
private _encodedAuth(): string {
const dsn = this._dsnObject;
const auth = {
// We send only the minimum set of required information. See
// https://github.com/getsentry/sentry-javascript/issues/2572.
sentry_key: dsn.user,
sentry_version: SENTRY_API_VERSION,
};
return urlEncode(auth);
}

/** Returns only the path component for the store endpoint. */
public getStoreEndpointPath(): string {
const dsn = this._dsnObject;
Expand Down Expand Up @@ -99,6 +75,7 @@ export class API {
/** Returns the url to the report dialog endpoint. */
public getReportDialogEndpoint(
dialogOptions: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
user?: { name?: string; email?: string };
} = {},
Expand Down Expand Up @@ -129,4 +106,28 @@ export class API {

return endpoint;
}

/** Returns the envelope endpoint URL. */
private _getEnvelopeEndpoint(): string {
return this._getIngestEndpoint('envelope');
}

/** Returns the ingest API endpoint for target. */
private _getIngestEndpoint(target: 'store' | 'envelope'): string {
const base = this.getBaseApiEndpoint();
const dsn = this._dsnObject;
return `${base}${dsn.projectId}/${target}/`;
}

/** Returns a URL-encoded string with auth config suitable for a query string. */
private _encodedAuth(): string {
const dsn = this._dsnObject;
const auth = {
// We send only the minimum set of required information. See
// https://github.com/getsentry/sentry-javascript/issues/2572.
sentry_key: dsn.user,
sentry_version: SENTRY_API_VERSION,
};
return urlEncode(auth);
}
}
16 changes: 9 additions & 7 deletions packages/core/src/basebackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { NoopTransport } from './transports/noop';
*/
export interface Backend {
/** Creates a {@link Event} from an exception. */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
eventFromException(exception: any, hint?: EventHint): PromiseLike<Event>;

/** Creates a {@link Event} from a plain message. */
Expand Down Expand Up @@ -68,16 +69,10 @@ export abstract class BaseBackend<O extends Options> implements Backend {
this._transport = this._setupTransport();
}

/**
* Sets up the transport so it can be used later to send requests.
*/
protected _setupTransport(): Transport {
return new NoopTransport();
}

/**
* @inheritDoc
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
public eventFromException(_exception: any, _hint?: EventHint): PromiseLike<Event> {
throw new SentryError('Backend has to implement `eventFromException` method');
}
Expand All @@ -104,4 +99,11 @@ export abstract class BaseBackend<O extends Options> implements Backend {
public getTransport(): Transport {
return this._transport;
}

/**
* Sets up the transport so it can be used later to send requests.
*/
protected _setupTransport(): Transport {
return new NoopTransport();
}
}
9 changes: 5 additions & 4 deletions packages/core/src/baseclient.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-lines */
import { Scope } from '@sentry/hub';
import { Client, Event, EventHint, Integration, IntegrationClass, Options, Severity } from '@sentry/types';
import {
Expand Down Expand Up @@ -85,6 +86,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
/**
* @inheritDoc
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
public captureException(exception: any, hint?: EventHint, scope?: Scope): string | undefined {
let eventId: string | undefined = hint && hint.event_id;
this._processing = true;
Expand Down Expand Up @@ -276,7 +278,6 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
}

return result.then(evt => {
// tslint:disable-next-line:strict-type-predicates
if (typeof normalizeDepth === 'number' && normalizeDepth > 0) {
return this._normalizeEvent(evt, normalizeDepth);
}
Expand All @@ -299,7 +300,6 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
return null;
}

// tslint:disable:no-unsafe-any
const normalized = {
...event,
...(event.breadcrumbs && {
Expand Down Expand Up @@ -403,6 +403,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
* @returns A SyncPromise that resolves with the event or rejects in case event was/will not be send.
*/
protected _processEvent(event: Event, hint?: EventHint, scope?: Scope): PromiseLike<Event> {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { beforeSend, sampleRate } = this.getOptions();

if (!this._isEnabled()) {
Expand All @@ -427,7 +428,8 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement

let finalEvent: Event | null = prepared;

const isInternalException = hint && hint.data && (hint.data as { [key: string]: any }).__sentry__ === true;
const isInternalException =
hint && hint.data && (hint.data as { [key: string]: unknown }).__sentry__ === true;
// We skip beforeSend in case of transactions
if (isInternalException || !beforeSend || isTransaction) {
this._sendEvent(finalEvent);
Expand All @@ -436,7 +438,6 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
}

const beforeSendResult = beforeSend(prepared, hint);
// tslint:disable-next-line:strict-type-predicates
if (typeof beforeSendResult === 'undefined') {
logger.error('`beforeSend` method has to return `null` or a valid event.');
} else if (isThenable(beforeSendResult)) {
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/integrations/functiontostring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ export class FunctionToString implements Integration {
/**
* @inheritDoc
*/
public name: string = FunctionToString.id;
public static id: string = 'FunctionToString';

/**
* @inheritDoc
*/
public static id: string = 'FunctionToString';
public name: string = FunctionToString.id;

/**
* @inheritDoc
*/
public setupOnce(): void {
// eslint-disable-next-line @typescript-eslint/unbound-method
originalFunctionToString = Function.prototype.toString;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Function.prototype.toString = function(this: WrappedFunction, ...args: any[]): string {
const context = this.__sentry_original__ || this;
// tslint:disable-next-line:no-unsafe-any
return originalFunctionToString.apply(context, args);
};
}
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/integrations/inboundfilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ export class InboundFilters implements Integration {
/**
* @inheritDoc
*/
public name: string = InboundFilters.id;
public static id: string = 'InboundFilters';

/**
* @inheritDoc
*/
public static id: string = 'InboundFilters';
public name: string = InboundFilters.id;

public constructor(private readonly _options: Partial<InboundFiltersOptions> = {}) {}

Expand Down Expand Up @@ -139,7 +140,6 @@ export class InboundFilters implements Integration {

/** JSDoc */
private _mergeOptions(clientOptions: Partial<InboundFiltersOptions> = {}): Partial<InboundFiltersOptions> {
// tslint:disable:deprecation
return {
allowUrls: [
...(this._options.whitelistUrls || []),
Expand Down
2 changes: 0 additions & 2 deletions packages/core/test/lib/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ describe('API', () => {
});

test('getRequestHeaders', () => {
// tslint:disable-next-line:deprecation
expect(new API(dsnPublic).getRequestHeaders('a', '1.0')).toMatchObject({
'Content-Type': 'application/json',
'X-Sentry-Auth': expect.stringMatching(/^Sentry sentry_version=\d, sentry_client=a\/1\.0, sentry_key=abc$/),
});

// tslint:disable-next-line:deprecation
expect(new API(legacyDsn).getRequestHeaders('a', '1.0')).toMatchObject({
'Content-Type': 'application/json',
'X-Sentry-Auth': expect.stringMatching(
Expand Down
Loading