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,

0 commit comments

Comments
 (0)