Skip to content

Commit 1d4b9cd

Browse files
committed
build: Switch @sentry/react to using eslint
1 parent 170c731 commit 1d4b9cd

File tree

19 files changed

+239
-92
lines changed

19 files changed

+239
-92
lines changed

.eslintignore

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

4-
packages/react/**/*
54
packages/tracing/**/*
65
packages/typescript/**/*

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = {
4343
// Enforce type annotations to maintain consistency. This is especially important as
4444
// we have a public API, so we want changes to be very explicit.
4545
'@typescript-eslint/typedef': ['error', { arrowParameter: false }],
46-
'@typescript-eslint/explicit-function-return-type': 'error',
46+
'@typescript-eslint/explicit-function-return-type': ['error', { allowExpressions: true }],
4747

4848
// Consistent ordering of fields, methods and constructors for classes should be enforced
4949
'@typescript-eslint/member-ordering': 'error',

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"fix": "lerna run --stream --concurrency 1 fix",
1010
"link:yarn": "lerna run --stream --concurrency 1 link:yarn",
1111
"lint": "lerna run --stream --concurrency 1 lint",
12-
"lint:json": "lerna run --stream --concurrency 1 lint:tslint:json",
1312
"test": "lerna run --stream --concurrency 1 --sort test",
1413
"codecov": "codecov",
1514
"postpublish": "make publish-docs"

packages/integrations/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"rollup-plugin-node-resolve": "^4.2.3",
3333
"rollup-plugin-terser": "^4.0.4",
3434
"rollup-plugin-typescript2": "^0.21.0",
35-
"tslint": "5.16.0",
3635
"typescript": "3.4.5"
3736
},
3837
"scripts": {

packages/node/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"prettier": "^1.17.0",
3838
"prettier-check": "^2.0.0",
3939
"rimraf": "^2.6.3",
40-
"tslint": "5.16.0",
4140
"typescript": "3.4.5"
4241
},
4342
"scripts": {

packages/react/.eslintrc.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
es6: true,
5+
browser: true,
6+
},
7+
parserOptions: {
8+
ecmaVersion: 2018,
9+
jsx: true,
10+
},
11+
extends: ['../../.eslintrc.js', 'plugin:react/recommended', 'plugin:react-hooks/recommended'],
12+
ignorePatterns: ['build/**/*', 'dist/**/*', 'esm/**/*', 'examples/**/*', 'scripts/**/*'],
13+
overrides: [
14+
{
15+
files: ['*.ts', '*.tsx', '*.d.ts'],
16+
parserOptions: {
17+
project: './tsconfig.json',
18+
},
19+
},
20+
{
21+
files: ['*.tsx'],
22+
rules: {
23+
'jsdoc/require-jsdoc': 'off',
24+
},
25+
},
26+
{
27+
files: ['test/**/*'],
28+
rules: {
29+
'@typescript-eslint/no-explicit-any': 'off',
30+
},
31+
},
32+
],
33+
rules: {
34+
'react/prop-types': 'off',
35+
},
36+
};

packages/react/package.json

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
"@types/react-router-3": "npm:@types/[email protected]",
3838
"@types/react-router-4": "npm:@types/[email protected]",
3939
"@types/react-router-5": "npm:@types/[email protected]",
40+
"eslint-plugin-react": "^7.20.5",
41+
"eslint-plugin-react-hooks": "^4.0.8",
4042
"history-4": "npm:[email protected]",
4143
"history-5": "npm:[email protected]",
4244
"jest": "^24.7.1",
@@ -52,9 +54,6 @@
5254
"react-test-renderer": "^16.13.1",
5355
"redux": "^4.0.5",
5456
"rimraf": "^2.6.3",
55-
"tslint": "5.16.0",
56-
"tslint-react": "^5.0.0",
57-
"tslint-react-hooks": "^2.2.2",
5857
"typescript": "3.4.5"
5958
},
6059
"scripts": {
@@ -66,13 +65,12 @@
6665
"build:watch:esm": "tsc -p tsconfig.esm.json -w --preserveWatchOutput",
6766
"clean": "rimraf dist coverage build esm",
6867
"link:yarn": "yarn link",
69-
"lint": "run-s lint:prettier lint:tslint",
70-
"lint:prettier": "prettier-check \"{src,test}/**/*.{ts,tsx}\"",
71-
"lint:tslint": "tslint -t stylish -p .",
72-
"lint:tslint:json": "tslint --format json -p . | tee lint-results.json",
73-
"fix": "run-s fix:tslint fix:prettier",
74-
"fix:prettier": "prettier --write \"{src,test}/**/*.{ts,tsx}\"",
75-
"fix:tslint": "tslint --fix -t stylish -p .",
68+
"lint": "run-s lint:prettier lint:eslint",
69+
"lint:prettier": "prettier-check \"{src,test}/**/*.ts\"",
70+
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
71+
"fix": "run-s fix:eslint fix:prettier",
72+
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
73+
"fix:eslint": "eslint . --format stylish --fix",
7674
"test": "jest",
7775
"test:watch": "jest --watch"
7876
},

packages/react/src/errorboundary.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export const UNKNOWN_COMPONENT = 'unknown';
77
export type FallbackRender = (fallback: {
88
error: Error | null;
99
componentStack: string | null;
10-
resetError(): void;
1110
eventId: string | null;
11+
resetError(): void;
1212
}) => React.ReactNode;
1313

1414
export type ErrorBoundaryProps = {
@@ -97,7 +97,7 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
9797
}
9898
}
9999

100-
public resetErrorBoundary = () => {
100+
public resetErrorBoundary: () => void = () => {
101101
const { onReset } = this.props;
102102
const { error, componentStack, eventId } = this.state;
103103
if (onReset) {
@@ -126,7 +126,7 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
126126
}
127127
}
128128

129-
function withErrorBoundary<P extends object>(
129+
function withErrorBoundary<P extends Record<string, unknown>>(
130130
WrappedComponent: React.ComponentType<P>,
131131
errorBoundaryOptions: ErrorBoundaryProps,
132132
): React.FC<P> {

packages/react/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { addGlobalEventProcessor, SDK_VERSION } from '@sentry/browser';
22

3+
/**
4+
* A global side effect that makes sure Sentry events that user
5+
* `@sentry/react` will correctly have Sentry events associated
6+
* with it.
7+
*/
38
function createReactEventProcessor(): void {
49
if (addGlobalEventProcessor) {
510
addGlobalEventProcessor(event => {

packages/react/src/profiler.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
import { getCurrentHub, Hub } from '@sentry/browser';
23
import { Integration, IntegrationClass, Span, Transaction } from '@sentry/types';
34
import { timestampWithMs } from '@sentry/utils';
@@ -12,7 +13,7 @@ const TRACING_GETTER = ({
1213

1314
let globalTracingIntegration: Integration | null = null;
1415
/** @deprecated remove when @sentry/apm no longer used */
15-
const getTracingIntegration = () => {
16+
const getTracingIntegration = (): Integration | null => {
1617
if (globalTracingIntegration) {
1718
return globalTracingIntegration;
1819
}
@@ -32,7 +33,6 @@ function pushActivity(name: string, op: string): number | null {
3233
return null;
3334
}
3435

35-
// tslint:disable-next-line:no-unsafe-any
3636
return (globalTracingIntegration as any).constructor.pushActivity(name, {
3737
description: `<${name}>`,
3838
op: `react.${op}`,
@@ -50,7 +50,6 @@ function popActivity(activity: number | null): void {
5050
return;
5151
}
5252

53-
// tslint:disable-next-line:no-unsafe-any
5453
(globalTracingIntegration as any).constructor.popActivity(activity);
5554
}
5655

@@ -93,6 +92,7 @@ class Profiler extends React.Component<ProfilerProps> {
9392
// The span of the mount activity
9493
private _mountSpan: Span | undefined = undefined;
9594

95+
// eslint-disable-next-line @typescript-eslint/member-ordering
9696
public static defaultProps: Partial<ProfilerProps> = {
9797
disabled: false,
9898
includeRender: true,
@@ -108,9 +108,9 @@ class Profiler extends React.Component<ProfilerProps> {
108108
}
109109

110110
// If they are using @sentry/apm, we need to push/pop activities
111-
// tslint:disable-next-line: deprecation
111+
// eslint-disable-next-line deprecation/deprecation
112112
if (getTracingIntegration()) {
113-
// tslint:disable-next-line: deprecation
113+
// eslint-disable-next-line deprecation/deprecation
114114
this._mountActivity = pushActivity(name, 'mount');
115115
} else {
116116
const activeTransaction = getActiveTransaction();
@@ -128,9 +128,9 @@ class Profiler extends React.Component<ProfilerProps> {
128128
if (this._mountSpan) {
129129
this._mountSpan.finish();
130130
} else {
131-
// tslint:disable-next-line: deprecation
131+
// eslint-disable-next-line deprecation/deprecation
132132
this._mountSpan = getActivitySpan(this._mountActivity);
133-
// tslint:disable-next-line: deprecation
133+
// eslint-disable-next-line deprecation/deprecation
134134
popActivity(this._mountActivity);
135135
this._mountActivity = null;
136136
}
@@ -191,7 +191,7 @@ class Profiler extends React.Component<ProfilerProps> {
191191
* @param WrappedComponent component that is wrapped by Profiler
192192
* @param options the {@link ProfilerProps} you can pass into the Profiler
193193
*/
194-
function withProfiler<P extends object>(
194+
function withProfiler<P extends Record<string, unknown>>(
195195
WrappedComponent: React.ComponentType<P>,
196196
// We do not want to have `updateProps` given in options, it is instead filled through the HOC.
197197
options?: Pick<Partial<ProfilerProps>, Exclude<keyof ProfilerProps, 'updateProps'>>,
@@ -248,7 +248,7 @@ function useProfiler(
248248
mountSpan.finish();
249249
}
250250

251-
return () => {
251+
return (): void => {
252252
if (mountSpan && options.hasRenderSpan) {
253253
mountSpan.startChild({
254254
description: `<${name}>`,
@@ -258,6 +258,8 @@ function useProfiler(
258258
});
259259
}
260260
};
261+
// We only want this to run once.
262+
// eslint-disable-next-line react-hooks/exhaustive-deps
261263
}, []);
262264
}
263265

0 commit comments

Comments
 (0)