Skip to content

Commit dcd549b

Browse files
authored
ref(eslint): Convert all packages to use central eslint config (#4111)
Convert nextjs, react, node, and serverless to using the central eslint config. This should make sure all packages use a consistent eslint config. In our central eslint config, I've disabled our no-async-await rule in tests and made jsdoc required for only exported methods/classes. For browser we've kept ignorePatterns: ['test/integration/**', 'src/loader.js'],. I think it's fine to not lint the loader, and the integration tests are going to be refactored with the release stability work, so we can keep this for now. Note: Ember is not converted as it's special cased (part of the build) - so I kept it separate. We can have a discussion about what we wanna do with ember, but my opinion is that it's fine to keep it a special case.
1 parent ac20799 commit dcd549b

File tree

22 files changed

+48
-153
lines changed

22 files changed

+48
-153
lines changed

.eslintrc.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ module.exports = {
2222
parserOptions: {
2323
project: './tsconfig.json',
2424
},
25-
}
25+
},
26+
{
27+
files: ['*.tsx'],
28+
rules: {
29+
// Turn off jsdoc on tsx files until jsdoc is fixed for tsx files
30+
// See: https://github.com/getsentry/sentry-javascript/issues/3871
31+
'jsdoc/require-jsdoc': 'off',
32+
},
33+
},
2634
],
2735
};

packages/browser/.eslintrc.js

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,7 @@
11
module.exports = {
2-
root: true,
32
env: {
4-
es6: true,
53
browser: true,
64
},
7-
parserOptions: {
8-
ecmaVersion: 2018,
9-
},
10-
extends: ['@sentry-internal/sdk'],
11-
ignorePatterns: ['build/**', 'dist/**', 'esm/**', 'examples/**', 'scripts/**', 'coverage/**', 'src/loader.js'],
12-
overrides: [
13-
{
14-
files: ['*.ts', '*.tsx', '*.d.ts'],
15-
parserOptions: {
16-
project: './tsconfig.json',
17-
},
18-
},
19-
{
20-
files: ['test/**'],
21-
rules: {
22-
'jsdoc/require-jsdoc': 'off',
23-
'no-console': 'off',
24-
'max-lines': 'off',
25-
'prefer-template': 'off',
26-
'no-unused-expressions': 'off',
27-
'guard-for-in': 'off',
28-
'@typescript-eslint/no-explicit-any': 'off',
29-
'@typescript-eslint/no-non-null-assertion': 'off',
30-
},
31-
},
32-
{
33-
files: ['test/integration/**'],
34-
env: {
35-
mocha: true,
36-
},
37-
rules: {
38-
'no-undef': 'off',
39-
},
40-
},
41-
{
42-
files: ['test/integration/common/**', 'test/integration/suites/**'],
43-
rules: {
44-
'no-unused-vars': 'off',
45-
},
46-
},
47-
],
48-
rules: {
49-
'no-prototype-builtins': 'off',
50-
},
5+
ignorePatterns: ['test/integration/**', 'src/loader.js'],
6+
extends: ['../../.eslintrc.js'],
517
};

packages/browser/src/integrations/trycatch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export class TryCatch implements Integration {
149149
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
150150
const proto = global[target] && global[target].prototype;
151151

152-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
152+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-prototype-builtins
153153
if (!proto || !proto.hasOwnProperty || !proto.hasOwnProperty('addEventListener')) {
154154
return;
155155
}

packages/browser/src/transports/xhr.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export class XHRTransport extends BaseTransport {
5656

5757
request.open('POST', sentryRequest.url);
5858
for (const header in this.options.headers) {
59+
// eslint-disable-next-line no-prototype-builtins
5960
if (this.options.headers.hasOwnProperty(header)) {
6061
request.setRequestHeader(header, this.options.headers[header]);
6162
}

packages/browser/test/package/npm-build.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
const fs = require('fs');
23
const path = require('path');
34

@@ -42,7 +43,7 @@ function runTests() {
4243
const bundlePath = path.join(__dirname, 'tmp.js');
4344
const { window } = new JSDOM(``, { runScripts: 'dangerously' });
4445

45-
window.onerror = function() {
46+
window.onerror = function () {
4647
console.error('ERROR thrown in manual test:');
4748
console.error(arguments);
4849
console.error('------------------');

packages/browser/test/package/test-code.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
const Sentry = require('../../dist/index.js');
23
const Integrations = require('../../../integrations/dist/dedupe.js');
34

packages/eslint-config-sdk/src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ module.exports = {
141141
},
142142
],
143143

144-
// We want to prevent async await usage in our files to prevent uncessary bundle size.
144+
// We want to prevent async await usage in our files to prevent uncessary bundle size. Turned off in tests.
145145
'@sentry-internal/sdk/no-async-await': 'error',
146146

147147
// JSDOC comments are required for classes and methods. As we have a public facing codebase, documentation,
@@ -151,6 +151,7 @@ module.exports = {
151151
{
152152
require: { ClassDeclaration: true, MethodDefinition: true },
153153
checkConstructors: false,
154+
publicOnly: true,
154155
},
155156
],
156157

@@ -173,6 +174,8 @@ module.exports = {
173174
'@typescript-eslint/explicit-member-accessibility': 'off',
174175
'@typescript-eslint/no-explicit-any': 'off',
175176
'@typescript-eslint/no-non-null-assertion': 'off',
177+
'@typescript-eslint/no-empty-function': 'off',
178+
'@sentry-internal/sdk/no-async-await': 'off',
176179
},
177180
},
178181
{

packages/nextjs/.eslintrc.js

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,14 @@
11
module.exports = {
2-
root: true,
32
env: {
4-
es6: true,
53
browser: true,
64
node: true,
75
},
86
parserOptions: {
9-
ecmaVersion: 2018,
7+
jsx: true,
108
},
11-
extends: ['@sentry-internal/sdk'],
12-
ignorePatterns: ['build/**', 'dist/**', 'esm/**', 'examples/**', 'scripts/**', 'test/integration/**'],
13-
overrides: [
14-
{
15-
files: ['*.ts', '*.tsx', '*.d.ts'],
16-
parserOptions: {
17-
project: './tsconfig.json',
18-
},
19-
},
20-
{
21-
files: ['test/**'],
22-
rules: {
23-
'@typescript-eslint/no-explicit-any': 'off',
24-
'@typescript-eslint/no-non-null-assertion': 'off',
25-
},
26-
},
27-
],
9+
ignorePatterns: ['test/integration/**'],
10+
extends: ['../../.eslintrc.js'],
2811
rules: {
29-
'max-lines': 'off',
3012
'@sentry-internal/sdk/no-async-await': 'off',
31-
'jsdoc/require-jsdoc': 0,
32-
},
13+
}
3314
};

packages/nextjs/src/config/webpack.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable max-lines */
12
import { getSentryRelease } from '@sentry/node';
23
import { dropUndefinedKeys, logger } from '@sentry/utils';
34
import { default as SentryWebpackPlugin } from '@sentry/webpack-plugin';

packages/nextjs/src/utils/instrumentServer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable max-lines */
12
import {
23
captureException,
34
configureScope,

packages/nextjs/src/utils/metadataBuilder.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ export class MetadataBuilder {
1818
this._packageNames = packages;
1919
}
2020

21+
/** JSDoc */
2122
public addSdkMetadata(): void {
2223
this._options._metadata = this._options._metadata || {};
2324
this._options._metadata.sdk = this._getSdkInfo();
2425
}
2526

27+
/** JSDoc */
2628
private _getSdkInfo(): SdkInfo {
2729
return {
2830
name: SDK_NAME,
@@ -31,6 +33,7 @@ export class MetadataBuilder {
3133
};
3234
}
3335

36+
/** JSDoc */
3437
private _getPackages(): Package[] {
3538
return this._packageNames.map((pkgName: string) => {
3639
return {

packages/node/.eslintrc.js

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

packages/node/src/integrations/console.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function createConsoleWrapper(level: string): (originalConsoleMethod: () => void
4949
sentryLevel = Severity.Log;
5050
}
5151

52+
/* eslint-disable prefer-rest-params */
5253
return function(this: typeof console): void {
5354
if (getCurrentHub().getIntegration(Console)) {
5455
getCurrentHub().addBreadcrumb(
@@ -66,5 +67,6 @@ function createConsoleWrapper(level: string): (originalConsoleMethod: () => void
6667

6768
originalConsoleMethod.apply(this, arguments);
6869
};
70+
/* eslint-enable prefer-rest-params */
6971
};
7072
}

packages/node/src/integrations/http.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export class Http implements Integration {
5656

5757
const wrappedHandlerMaker = _createWrappedRequestMethodFactory(this._breadcrumbs, this._tracing);
5858

59+
// eslint-disable-next-line @typescript-eslint/no-var-requires
5960
const httpModule = require('http');
6061
fill(httpModule, 'get', wrappedHandlerMaker);
6162
fill(httpModule, 'request', wrappedHandlerMaker);
@@ -64,6 +65,7 @@ export class Http implements Integration {
6465
// If we do, we'd get double breadcrumbs and double spans for `https` calls.
6566
// It has been changed in Node 9, so for all versions equal and above, we patch `https` separately.
6667
if (NODE_VERSION.major && NODE_VERSION.major > 8) {
68+
// eslint-disable-next-line @typescript-eslint/no-var-requires
6769
const httpsModule = require('https');
6870
fill(httpsModule, 'get', wrappedHandlerMaker);
6971
fill(httpsModule, 'request', wrappedHandlerMaker);

packages/react/.eslintrc.js

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,18 @@
11
module.exports = {
2-
root: true,
32
env: {
4-
es6: true,
53
browser: true,
64
},
75
parserOptions: {
8-
ecmaVersion: 2018,
96
jsx: true,
107
},
11-
extends: ['@sentry-internal/sdk', 'plugin:react/recommended', 'plugin:react-hooks/recommended'],
12-
ignorePatterns: ['build/**', 'dist/**', 'esm/**', 'examples/**', 'scripts/**'],
8+
extends: ['../../.eslintrc.js', 'plugin:react/recommended', 'plugin:react-hooks/recommended'],
139
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-
},
2610
{
2711
files: ['test/**'],
2812
rules: {
29-
'@typescript-eslint/no-explicit-any': 'off',
13+
// Prop types validation is not useful in test environments
14+
'react/prop-types': 'off',
3015
},
3116
},
3217
],
33-
rules: {
34-
'react/prop-types': 'off',
35-
'@typescript-eslint/no-unsafe-member-access': 'off',
36-
},
3718
};

packages/react/src/errorboundary.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ function withErrorBoundary<P extends Record<string, any>>(
157157
WrappedComponent: React.ComponentType<P>,
158158
errorBoundaryOptions: ErrorBoundaryProps,
159159
): React.FC<P> {
160+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
160161
const componentDisplayName = WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;
161162

162163
const Wrapped: React.FC<P> = (props: P) => (
@@ -165,6 +166,7 @@ function withErrorBoundary<P extends Record<string, any>>(
165166
</ErrorBoundary>
166167
);
167168

169+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
168170
Wrapped.displayName = `errorBoundary(${componentDisplayName})`;
169171

170172
// Copy over static methods from Wrapped component to Profiler HOC

packages/react/src/profiler.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
12
/* eslint-disable @typescript-eslint/no-explicit-any */
23
import { getCurrentHub, Hub } from '@sentry/browser';
34
import { Integration, IntegrationClass, Span, Transaction } from '@sentry/types';

packages/react/src/reactrouter.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function computeRootMatch(pathname: string): Match {
148148
return { path: '/', url: '/', params: {}, isExact: pathname === '/' };
149149
}
150150

151-
/* eslint-disable @typescript-eslint/no-explicit-any */
151+
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */
152152
export function withSentryRouting<P extends Record<string, any>, R extends React.ComponentType<P>>(Route: R): R {
153153
const componentDisplayName = (Route as any).displayName || (Route as any).name;
154154

@@ -170,4 +170,4 @@ export function withSentryRouting<P extends Record<string, any>, R extends React
170170
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164
171171
return WrappedRoute;
172172
}
173-
/* eslint-enable @typescript-eslint/no-explicit-any */
173+
/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */

packages/serverless/.eslintrc.js

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,9 @@
11
module.exports = {
2-
root: true,
32
env: {
4-
es6: true,
53
node: true,
64
},
7-
parserOptions: {
8-
ecmaVersion: 2018,
9-
},
10-
extends: ['@sentry-internal/sdk'],
11-
ignorePatterns: ['dist/**', 'esm/**'],
12-
overrides: [
13-
{
14-
files: ['*.ts', '*.d.ts'],
15-
parserOptions: {
16-
project: './tsconfig.json',
17-
},
18-
},
19-
{
20-
files: ['test/**'],
21-
rules: {
22-
'no-empty': 'off',
23-
'@typescript-eslint/no-empty-function': 'off',
24-
'@typescript-eslint/no-explicit-any': 'off',
25-
'@typescript-eslint/no-non-null-assertion': 'off',
26-
},
27-
},
28-
],
5+
extends: ['../../.eslintrc.js'],
296
rules: {
30-
'@typescript-eslint/no-var-requires': 'off',
317
'@sentry-internal/sdk/no-async-await': 'off',
32-
},
8+
}
339
};

packages/serverless/src/awsservices.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export class AWSServices implements Integration {
3838
*/
3939
public setupOnce(): void {
4040
try {
41+
// eslint-disable-next-line @typescript-eslint/no-var-requires
4142
const awsModule = require('aws-sdk/global') as typeof AWS;
4243
fill(awsModule.Service.prototype, 'makeRequest', wrapMakeRequest);
4344
} catch (e) {

0 commit comments

Comments
 (0)