Skip to content

Commit 6229e27

Browse files
authored
build: Convert utils, apm, angular, gatsby, ember to eslint (getsentry#2804)
* build: Switch @sentry/utils to using eslint * build: Switch @sentry/apm to using eslint * clean up other files * feat: Use eslint cache * build: Switch @sentry/angular to using eslint * build: Switch @sentry/gatsby to using eslint * build: Switch @sentry/ember to using eslint * gitignore * dangerfile * add plugins for import * cleanup * fix
1 parent b2e191f commit 6229e27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1058
-1401
lines changed

.eslintignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
# THIS IS A TEMPORARY FILE
22
# THIS WILL BE REMOVED AFTER WE FINISH ESLINT UPGRADE
33

4-
packages/apm/**/*
5-
packages/ember/**/*
6-
packages/gatsby/**/*
74
packages/integrations/**/*
85
packages/node/**/*
96
packages/react/**/*
107
packages/tracing/**/*
118
packages/typescript/**/*
12-
packages/utils/**/*

.eslintrc.js

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module.exports = {
33
env: {
44
node: true,
55
},
6-
extends: ['prettier', 'eslint:recommended'],
7-
plugins: ['sentry-sdk', 'jsdoc'],
6+
extends: ['prettier', 'eslint:recommended', 'plugin:import/errors', 'plugin:import/warnings'],
7+
plugins: ['sentry-sdk', 'simple-import-sort'],
88
ignorePatterns: ['eslint-plugin-sentry-sdk'],
99
overrides: [
1010
{
@@ -17,8 +17,8 @@ module.exports = {
1717
{
1818
// Configuration for typescript files
1919
files: ['*.ts', '*.tsx', '*.d.ts'],
20-
extends: ['plugin:@typescript-eslint/recommended', 'prettier/@typescript-eslint'],
21-
plugins: ['@typescript-eslint'],
20+
extends: ['plugin:@typescript-eslint/recommended', 'prettier/@typescript-eslint', 'plugin:import/typescript'],
21+
plugins: ['@typescript-eslint', 'jsdoc', 'deprecation'],
2222
parser: '@typescript-eslint/parser',
2323
parserOptions: {
2424
project: './tsconfig.json',
@@ -68,6 +68,25 @@ module.exports = {
6868
leadingUnderscore: 'require',
6969
},
7070
],
71+
72+
// Prefer for-of loop over for loop if index is only used to access array
73+
'@typescript-eslint/prefer-for-of': 'error',
74+
75+
// Make sure all expressions are used. Turned off in tests
76+
// Must disable base rule to prevent false positives
77+
'no-unused-expressions': 'off',
78+
'@typescript-eslint/no-unused-expressions': 'error',
79+
80+
// Make sure Promises are handled appropriately
81+
'@typescript-eslint/no-floating-promises': 'error',
82+
83+
// Do not use deprecated methods
84+
'deprecation/deprecation': 'error',
85+
86+
// sort imports
87+
'simple-import-sort/sort': 'error',
88+
'sort-imports': 'off',
89+
'import/order': 'off',
7190
},
7291
},
7392
{
@@ -95,6 +114,8 @@ module.exports = {
95114
'max-lines': 'off',
96115

97116
'@typescript-eslint/explicit-function-return-type': 'off',
117+
'no-unused-expressions': 'off',
118+
'@typescript-eslint/no-unused-expressions': 'off',
98119
},
99120
},
100121
{
@@ -128,5 +149,20 @@ module.exports = {
128149

129150
// We should require a whitespace beginning a comment
130151
'spaced-comment': 'error',
152+
153+
// Disallow usage of bitwise operators - this makes it an opt in operation
154+
'no-bitwise': 'error',
155+
156+
// Limit cyclomatic complexity
157+
complexity: 'error',
158+
159+
// Make sure all expressions are used. Turn off on tests.
160+
'no-unused-expressions': 'error',
161+
162+
// We shouldn't make assumptions about imports/exports being dereferenced.
163+
'import/namespace': 'off',
164+
165+
// imports should be ordered.
166+
'import/order': ['error', { 'newlines-between': 'always' }],
131167
},
132168
};

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ lint-results.json
3434

3535
# legacy
3636
tmp.js
37+
38+
# eslint
39+
.eslintcache
40+
eslintcache/*

dangerfile.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { exec } from 'child_process';
22
import { danger, fail, message, schedule, warn } from 'danger';
3-
import { promisify } from 'util';
4-
import { resolve } from 'path';
53
import tslint from 'danger-plugin-tslint';
64
import { prettyResults } from 'danger-plugin-tslint/dist/prettyResults';
75
import { CLIEngine } from 'eslint';
6+
import { resolve } from 'path';
7+
import { promisify } from 'util';
88

9-
const PACKAGES = ['apm', 'integrations', 'node', 'utils'];
9+
const PACKAGES = ['integrations', 'node'];
1010
const EXTENSIONS = ['.js', '.jsx', '.ts', '.tsx'];
1111

1212
/**
@@ -15,13 +15,15 @@ const EXTENSIONS = ['.js', '.jsx', '.ts', '.tsx'];
1515
*/
1616
async function eslint(): Promise<void[]> {
1717
const allFiles = danger.git.created_files.concat(danger.git.modified_files);
18+
// eslint-disable-next-line deprecation/deprecation
1819
const cli = new CLIEngine({});
1920
// let eslint filter down to non-ignored, matching the extensions expected
2021
const filesToLint = allFiles.filter(f => !cli.isPathIgnored(f) && EXTENSIONS.some(ext => f.endsWith(ext)));
2122
return Promise.all(filesToLint.map(f => lintFile(cli, f)));
2223
}
2324

2425
/** JSDoc */
26+
// eslint-disable-next-line deprecation/deprecation
2527
async function lintFile(linter: CLIEngine, path: string): Promise<void> {
2628
const contents = await danger.github.utils.fileContents(path);
2729
const report = linter.executeOnText(contents, path);

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"yarn": "1.13.0"
2020
},
2121
"workspaces": [
22+
"packages/angular",
2223
"packages/apm",
2324
"packages/browser",
2425
"packages/core",
@@ -52,8 +53,11 @@
5253
"danger-plugin-tslint": "^2.0.0",
5354
"eslint": "^7.5.0",
5455
"eslint-config-prettier": "^6.11.0",
56+
"eslint-plugin-deprecation": "^1.1.0",
57+
"eslint-plugin-import": "^2.22.0",
5558
"eslint-plugin-jsdoc": "^30.0.3",
5659
"eslint-plugin-sentry-sdk": "file:./eslint-plugin-sentry-sdk",
60+
"eslint-plugin-simple-import-sort": "^5.0.3",
5761
"jest": "^24.7.1",
5862
"karma-browserstack-launcher": "^1.5.1",
5963
"karma-firefox-launcher": "^1.1.0",

packages/angular/.eslintrc.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
es6: true,
5+
browser: true,
6+
},
7+
parserOptions: {
8+
ecmaVersion: 2018,
9+
},
10+
extends: ['../../.eslintrc.js'],
11+
ignorePatterns: ['build/**/*', 'dist/**/*', 'esm/**/*', 'examples/**/*', 'scripts/**/*'],
12+
overrides: [
13+
{
14+
files: ['*.ts', '*.tsx', '*.d.ts'],
15+
parserOptions: {
16+
project: './tsconfig.json',
17+
},
18+
},
19+
],
20+
};

packages/angular/package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@
4242
"build:watch:esm": "tsc -p tsconfig.esm.json -w --preserveWatchOutput",
4343
"clean": "rimraf dist coverage build esm",
4444
"link:yarn": "yarn link",
45-
"lint": "run-s lint:prettier lint:tslint",
46-
"lint:prettier": "prettier-check \"{src,test}/**/*.{ts,tsx}\"",
47-
"lint:tslint": "tslint -t stylish -p .",
48-
"lint:tslint:json": "tslint --format json -p . | tee lint-results.json",
49-
"fix": "run-s fix:tslint fix:prettier",
50-
"fix:prettier": "prettier --write \"{src,test}/**/*.{ts,tsx}\"",
51-
"fix:tslint": "tslint --fix -t stylish -p ."
45+
"lint": "run-s lint:prettier lint:eslint",
46+
"lint:prettier": "prettier-check \"{src,test}/**/*.ts\"",
47+
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
48+
"fix": "run-s fix:eslint fix:prettier",
49+
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
50+
"fix:eslint": "eslint . --format stylish --fix"
5251
},
5352
"sideEffects": false
5453
}

packages/angular/src/errorhandler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class SentryErrorHandler implements AngularErrorHandler {
6161

6262
// When in development mode, log the error to console for immediate feedback.
6363
if (this._options.logErrors) {
64+
// eslint-disable-next-line no-console
6465
console.error(extractedError);
6566
}
6667

packages/angular/src/tracing.ts

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// tslint:disable:max-classes-per-file
2-
31
import { AfterViewInit, Directive, Injectable, Input, OnInit } from '@angular/core';
42
import { Event, NavigationEnd, NavigationStart, Router } from '@angular/router';
53
import { getCurrentHub } from '@sentry/browser';
@@ -54,14 +52,7 @@ export function getActiveTransaction(): Transaction | undefined {
5452
*/
5553
@Injectable({ providedIn: 'root' })
5654
export class TraceService {
57-
private routingSpan?: Span;
58-
59-
public constructor(private readonly router: Router) {
60-
this.navStart$.subscribe();
61-
this.navEnd$.subscribe();
62-
}
63-
64-
public navStart$: Observable<Event> = this.router.events.pipe(
55+
public navStart$: Observable<Event> = this._router.events.pipe(
6556
filter(event => event instanceof NavigationStart),
6657
tap(event => {
6758
if (!instrumentationInitialized) {
@@ -80,7 +71,7 @@ export class TraceService {
8071
}
8172

8273
if (activeTransaction) {
83-
this.routingSpan = activeTransaction.startChild({
74+
this._routingSpan = activeTransaction.startChild({
8475
description: `${navigationEvent.url}`,
8576
op: `angular.routing`,
8677
tags: {
@@ -95,15 +86,22 @@ export class TraceService {
9586
}),
9687
);
9788

98-
public navEnd$: Observable<Event> = this.router.events.pipe(
89+
public navEnd$: Observable<Event> = this._router.events.pipe(
9990
filter(event => event instanceof NavigationEnd),
10091
tap(() => {
101-
if (this.routingSpan) {
102-
this.routingSpan.finish();
103-
delete this.routingSpan;
92+
if (this._routingSpan) {
93+
this._routingSpan.finish();
94+
delete this._routingSpan;
10495
}
10596
}),
10697
);
98+
99+
private _routingSpan?: Span;
100+
101+
public constructor(private readonly _router: Router) {
102+
this.navStart$.subscribe();
103+
this.navEnd$.subscribe();
104+
}
107105
}
108106

109107
const UNKNOWN_COMPONENT = 'unknown';
@@ -113,18 +111,18 @@ const UNKNOWN_COMPONENT = 'unknown';
113111
*/
114112
@Directive({ selector: '[trace]' })
115113
export class TraceDirective implements OnInit, AfterViewInit {
116-
private tracingSpan?: Span;
117-
118114
@Input('trace') public componentName: string = UNKNOWN_COMPONENT;
119115

116+
private _tracingSpan?: Span;
117+
120118
/**
121119
* Implementation of OnInit lifecycle method
122120
* @inheritdoc
123121
*/
124122
public ngOnInit(): void {
125123
const activeTransaction = getActiveTransaction();
126124
if (activeTransaction) {
127-
this.tracingSpan = activeTransaction.startChild({
125+
this._tracingSpan = activeTransaction.startChild({
128126
description: `<${this.componentName}>`,
129127
op: `angular.initialize`,
130128
});
@@ -136,8 +134,8 @@ export class TraceDirective implements OnInit, AfterViewInit {
136134
* @inheritdoc
137135
*/
138136
public ngAfterViewInit(): void {
139-
if (this.tracingSpan) {
140-
this.tracingSpan.finish();
137+
if (this._tracingSpan) {
138+
this._tracingSpan.finish();
141139
}
142140
}
143141
}
@@ -148,10 +146,11 @@ export class TraceDirective implements OnInit, AfterViewInit {
148146
export function TraceClassDecorator(): ClassDecorator {
149147
let tracingSpan: Span;
150148

151-
return (target: Function) => {
149+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
150+
return target => {
152151
// tslint:disable-next-line:no-unsafe-any
153152
const originalOnInit = target.prototype.ngOnInit;
154-
// tslint:disable-next-line:no-unsafe-any
153+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
155154
target.prototype.ngOnInit = function(...args: any[]): ReturnType<typeof originalOnInit> {
156155
const activeTransaction = getActiveTransaction();
157156
if (activeTransaction) {
@@ -161,14 +160,12 @@ export function TraceClassDecorator(): ClassDecorator {
161160
});
162161
}
163162
if (originalOnInit) {
164-
// tslint:disable-next-line:no-unsafe-any
165163
return originalOnInit.apply(this, args);
166164
}
167165
};
168166

169-
// tslint:disable-next-line:no-unsafe-any
170167
const originalAfterViewInit = target.prototype.ngAfterViewInit;
171-
// tslint:disable-next-line:no-unsafe-any
168+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
172169
target.prototype.ngAfterViewInit = function(...args: any[]): ReturnType<typeof originalAfterViewInit> {
173170
if (tracingSpan) {
174171
tracingSpan.finish();
@@ -185,8 +182,10 @@ export function TraceClassDecorator(): ClassDecorator {
185182
* Decorator function that can be used to capture a single lifecycle methods of the component.
186183
*/
187184
export function TraceMethodDecorator(): MethodDecorator {
185+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/ban-types
188186
return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
189187
const originalMethod = descriptor.value;
188+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
190189
descriptor.value = function(...args: any[]): ReturnType<typeof originalMethod> {
191190
const now = timestampWithMs();
192191
const activeTransaction = getActiveTransaction();

packages/angular/tslint.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)