Skip to content

Commit

Permalink
build: Switch integrations, node, react, tracing to eslint (#2806)
Browse files Browse the repository at this point in the history
* build: Switch @sentry/integrations to using eslint

* build: Remove tslint danger

* build: Switch @sentry/node to using eslint

* build: Switch @sentry/react to using eslint

* build: Switch @sentry/tracing to using eslint

* remove remaining tslint references

* Add unsafe any rule
  • Loading branch information
AbhiPrasad authored Aug 12, 2020
1 parent 6229e27 commit 8eb7286
Show file tree
Hide file tree
Showing 114 changed files with 967 additions and 2,024 deletions.
4 changes: 0 additions & 4 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# THIS IS A TEMPORARY FILE
# THIS WILL BE REMOVED AFTER WE FINISH ESLINT UPGRADE

packages/integrations/**/*
packages/node/**/*
packages/react/**/*
packages/tracing/**/*
packages/typescript/**/*
26 changes: 22 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module.exports = {
node: true,
},
extends: ['prettier', 'eslint:recommended', 'plugin:import/errors', 'plugin:import/warnings'],
plugins: ['sentry-sdk', 'simple-import-sort'],
ignorePatterns: ['eslint-plugin-sentry-sdk'],
plugins: ['sentry-sdks', 'simple-import-sort'],
ignorePatterns: ['eslint-plugin-sentry-sdks'],
overrides: [
{
// Configuration for JavaScript files
Expand Down Expand Up @@ -43,7 +43,7 @@ module.exports = {
// Enforce type annotations to maintain consistency. This is especially important as
// we have a public API, so we want changes to be very explicit.
'@typescript-eslint/typedef': ['error', { arrowParameter: false }],
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/explicit-function-return-type': ['error', { allowExpressions: true }],

// Consistent ordering of fields, methods and constructors for classes should be enforced
'@typescript-eslint/member-ordering': 'error',
Expand Down Expand Up @@ -87,21 +87,35 @@ module.exports = {
'simple-import-sort/sort': 'error',
'sort-imports': 'off',
'import/order': 'off',

// Disallow delete operator. We should make this operation opt in (by disabling this rule).
'@typescript-eslint/no-dynamic-delete': 'error',

// We should prevent against overloads unless necessary.
'@typescript-eslint/unified-signatures': 'error',

// Disallow unsafe any usage. We should enforce that types be used as possible, or unknown be used
// instead of any. This is especially important for methods that expose a public API, as users
// should know exactly what they have to provide to use those methods. Turned off in tests.
'@typescript-eslint/no-unsafe-member-access': 'error',
},
},
{
// Configuration for files under src
files: ['src/**/*'],
rules: {
// We want to prevent async await usage in our files to prevent uncessary bundle size.
'sentry-sdk/no-async-await': 'error',
'sentry-sdks/no-async-await': 'error',

// JSDOC comments are required for classes and methods. As we have a public facing codebase, documentation,
// even if it may seems excessive at times, is important to emphasize. Turned off in tests.
'jsdoc/require-jsdoc': [
'error',
{ require: { ClassDeclaration: true, MethodDefinition: true }, checkConstructors: false },
],

// All imports should be accounted for
'import/no-extraneous-dependencies': 'error',
},
},
{
Expand All @@ -116,6 +130,7 @@ module.exports = {
'@typescript-eslint/explicit-function-return-type': 'off',
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
},
},
{
Expand Down Expand Up @@ -164,5 +179,8 @@ module.exports = {

// imports should be ordered.
'import/order': ['error', { 'newlines-between': 'always' }],

// Make sure for in loops check for properties
'guard-for-in': 'error',
},
};
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": ["esbenp.prettier-vscode", "ms-vscode.vscode-typescript-tslint-plugin", "dbaeumer.vscode-eslint"]
"recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"]
}
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"**/dist/": true
},
"typescript.tsdk": "./node_modules/typescript/lib",
"tslint.autoFixOnSave": true,
"[json]": {
"editor.formatOnType": false,
"editor.formatOnPaste": false,
Expand Down
33 changes: 0 additions & 33 deletions dangerfile.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { exec } from 'child_process';
import { danger, fail, message, schedule, warn } from 'danger';
import tslint from 'danger-plugin-tslint';
import { prettyResults } from 'danger-plugin-tslint/dist/prettyResults';
import { CLIEngine } from 'eslint';
import { resolve } from 'path';
import { promisify } from 'util';

const PACKAGES = ['integrations', 'node'];
const EXTENSIONS = ['.js', '.jsx', '.ts', '.tsx'];

/**
Expand Down Expand Up @@ -48,35 +44,6 @@ export default async (): Promise<void> => {
return;
}

schedule(async () => {
const tsLintResult = (
await Promise.all(
PACKAGES.map(packageName => {
return new Promise<string>(res => {
tslint({
lintResultsJsonPath: resolve(__dirname, 'packages', packageName, 'lint-results.json'),
handleResults: results => {
if (results.length > 0) {
const formattedResults = prettyResults(results);
res(`TSLint failed: **@sentry/${packageName}**\n\n${formattedResults}`);
} else {
res('');
}
},
});
});
}),
)
).filter(str => str.length);
if (tsLintResult.length) {
tsLintResult.forEach(tsLintFail => {
fail(`${tsLintFail}`);
});
} else {
message('✅ TSLint passed');
}
});

await eslint();

const hasChangelog = danger.git.modified_files.indexOf('CHANGELOG.md') !== -1;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "eslint-plugin-sentry-sdk",
"name": "eslint-plugin-sentry-sdks",
"version": "0.0.1",
"main": "index.js",
"devDependencies": {
Expand Down
13 changes: 4 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"fix": "lerna run --stream --concurrency 1 fix",
"link:yarn": "lerna run --stream --concurrency 1 link:yarn",
"lint": "lerna run --stream --concurrency 1 lint",
"lint:json": "lerna run --stream --concurrency 1 lint:tslint:json",
"test": "lerna run --stream --concurrency 1 --sort test",
"codecov": "codecov",
"postpublish": "make publish-docs"
Expand Down Expand Up @@ -44,19 +43,17 @@
"@types/mocha": "^5.2.0",
"@types/node": "^11.13.7",
"@types/sinon": "^7.0.11",
"@typescript-eslint/eslint-plugin": "^3.7.1",
"@typescript-eslint/parser": "^3.7.1",
"@typescript-eslint/eslint-plugin": "^3.9.0",
"@typescript-eslint/parser": "^3.9.0",
"chai": "^4.1.2",
"codecov": "^3.6.5",
"danger": "^7.1.3",
"danger-plugin-eslint": "^0.1.0",
"danger-plugin-tslint": "^2.0.0",
"eslint": "^7.5.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-deprecation": "^1.1.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jsdoc": "^30.0.3",
"eslint-plugin-sentry-sdk": "file:./eslint-plugin-sentry-sdk",
"eslint-plugin-sentry-sdks": "file:./eslint-plugin-sentry-sdks",
"eslint-plugin-simple-import-sort": "^5.0.3",
"jest": "^24.7.1",
"karma-browserstack-launcher": "^1.5.1",
Expand All @@ -71,10 +68,8 @@
"sinon": "^7.3.2",
"size-limit": "^4.5.5",
"ts-jest": "^24.0.2",
"tslint": "5.16.0",
"typedoc": "^0.14.2",
"typescript": "3.4.5",
"typescript-tslint-plugin": "^0.3.1"
"typescript": "3.4.5"
},
"resolutions": {
"**/agent-base": "5"
Expand Down
1 change: 0 additions & 1 deletion packages/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"prettier": "^1.17.0",
"prettier-check": "^2.0.0",
"rimraf": "^2.6.3",
"tslint": "^5.16.0",
"typescript": "^3.5.1"
},
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion packages/angular/src/errorhandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class SentryErrorHandler implements AngularErrorHandler {
// Allow custom overrides of extracting function
if (this._options.extractor) {
const defaultExtractor = this._defaultExtractor.bind(this);
// tslint:disable-next-line:no-unsafe-any
return this._options.extractor(error, defaultExtractor);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/angular/src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ export class TraceDirective implements OnInit, AfterViewInit {
export function TraceClassDecorator(): ClassDecorator {
let tracingSpan: Span;

/* eslint-disable @typescript-eslint/no-unsafe-member-access */
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
return target => {
// tslint:disable-next-line:no-unsafe-any
const originalOnInit = target.prototype.ngOnInit;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
target.prototype.ngOnInit = function(...args: any[]): ReturnType<typeof originalOnInit> {
Expand All @@ -171,11 +171,11 @@ export function TraceClassDecorator(): ClassDecorator {
tracingSpan.finish();
}
if (originalAfterViewInit) {
// tslint:disable-next-line:no-unsafe-any
return originalAfterViewInit.apply(this, args);
}
};
};
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
}

/**
Expand All @@ -198,7 +198,7 @@ export function TraceMethodDecorator(): MethodDecorator {
});
}
if (originalMethod) {
// tslint:disable-next-line:no-unsafe-any
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
return originalMethod.apply(this, args);
}
};
Expand Down
1 change: 0 additions & 1 deletion packages/apm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"rollup-plugin-node-resolve": "^4.2.3",
"rollup-plugin-terser": "^4.0.4",
"rollup-plugin-typescript2": "^0.21.0",
"tslint": "5.16.0",
"typescript": "3.4.5"
},
"scripts": {
Expand Down
2 changes: 0 additions & 2 deletions packages/apm/src/index.bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@ export { Span, TRACEPARENT_REGEXP } from './span';
let windowIntegrations = {};

// This block is needed to add compatibility with the integrations packages when used with a CDN
// tslint:disable: no-unsafe-any
const _window = getGlobalObject<Window>();
if (_window.Sentry && _window.Sentry.Integrations) {
windowIntegrations = _window.Sentry.Integrations;
}
// tslint:enable: no-unsafe-any

const INTEGRATIONS = {
...windowIntegrations,
Expand Down
15 changes: 7 additions & 8 deletions packages/apm/src/integrations/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export class Tracing implements Integration {
}
span.finish();
}
// tslint:disable-next-line: no-dynamic-delete
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete Tracing._activities[id];
}

Expand Down Expand Up @@ -630,6 +630,7 @@ export class Tracing implements Integration {
let entryScriptStartEndTime: number | undefined;
let tracingInitMarkStartTime: number | undefined;

/* eslint-disable @typescript-eslint/no-unsafe-member-access */
performance
.getEntries()
.slice(Tracing._performanceCursor)
Expand Down Expand Up @@ -687,6 +688,7 @@ export class Tracing implements Integration {
// Ignore other entry types.
}
});
/* eslint-enable @typescript-eslint/no-unsafe-member-access */

if (entryScriptStartEndTime !== undefined && tracingInitMarkStartTime !== undefined) {
_startChild(transactionSpan, {
Expand All @@ -698,7 +700,6 @@ export class Tracing implements Integration {
}

Tracing._performanceCursor = Math.max(performance.getEntries().length - 1, 0);
// tslint:enable: no-unsafe-any
}

/**
Expand Down Expand Up @@ -772,6 +773,7 @@ export class Tracing implements Integration {
return time / 1000;
}

/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/**
* Adds debug data to the span
*/
Expand All @@ -792,8 +794,8 @@ export class Tracing implements Integration {
}
debugData['Date.now()'] = Date.now();
span.setData('sentry_debug', debugData);
// tslint:enable: no-unsafe-any
}
/* eslint-enable @typescript-eslint/no-unsafe-member-access */

/**
* @inheritDoc
Expand Down Expand Up @@ -936,6 +938,7 @@ export class Tracing implements Integration {
}
}

/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/**
* Creates breadcrumbs from XHR API calls
*/
Expand All @@ -945,12 +948,10 @@ function xhrCallback(handlerData: { [key: string]: any }): void {
return;
}

// tslint:disable-next-line: no-unsafe-any
if (!handlerData || !handlerData.xhr || !handlerData.xhr.__sentry_xhr__) {
return;
}

// tslint:disable: no-unsafe-any
const xhr = handlerData.xhr.__sentry_xhr__;

if (!Tracing.options.shouldCreateSpanForRequest(xhr.url)) {
Expand Down Expand Up @@ -988,15 +989,13 @@ function xhrCallback(handlerData: { [key: string]: any }): void {
}
}
}
// tslint:enable: no-unsafe-any
}

/**
* Creates breadcrumbs from fetch API calls
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function fetchCallback(handlerData: { [key: string]: any }): void {
// tslint:disable: no-unsafe-any
if (!Tracing.options.traceFetch) {
return;
}
Expand Down Expand Up @@ -1043,8 +1042,8 @@ function fetchCallback(handlerData: { [key: string]: any }): void {
}
}
}
// tslint:enable: no-unsafe-any
}
/* eslint-enable @typescript-eslint/no-unsafe-member-access */

/**
* Creates transaction from navigation changes
Expand Down
2 changes: 1 addition & 1 deletion packages/apm/src/integrations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export interface Location {
*/
reload(): void;
/** @deprecated */
// tslint:disable-next-line: unified-signatures completed-docs
// eslint-disable-next-line @typescript-eslint/unified-signatures
reload(forcedReload: boolean): void;
/**
* Removes the current page from the session history and navigates to the given URL.
Expand Down
1 change: 0 additions & 1 deletion packages/apm/src/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// tslint:disable:max-classes-per-file
import { getCurrentHub, Hub } from '@sentry/hub';
import { TransactionContext } from '@sentry/types';
import { isInstanceOf, logger } from '@sentry/utils';
Expand Down
1 change: 1 addition & 0 deletions packages/browser/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = {
'max-lines': 'off',
'prefer-template': 'off',
'no-unused-expressions': 'off',
'guard-for-in': 'off',
},
},
{
Expand Down
Loading

0 comments on commit 8eb7286

Please sign in to comment.