Skip to content

Commit c2e63f9

Browse files
committed
Merge branch 'lms-eslint'
2 parents ba647cc + 5cf29e1 commit c2e63f9

40 files changed

+684
-390
lines changed

.eslintrc.js

Lines changed: 112 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,123 @@
1-
/* eslint-env node */
1+
// TODO: Remove this file after migration!
2+
// TODO: Remove Sentry ESLint config package from package.json
3+
// Note: All paths are relative to the directory in which eslint is being run, rather than the directory where this file
4+
// lives
5+
6+
// ESLint config docs: https://eslint.org/docs/user-guide/configuring/
7+
28
module.exports = {
39
root: true,
4-
parser: '@typescript-eslint/parser',
5-
plugins: ['@typescript-eslint', 'simple-import-sort'],
6-
extends: [
7-
'eslint:recommended',
8-
'plugin:@typescript-eslint/recommended',
9-
'plugin:prettier/recommended', // Should be last
10+
env: {
11+
es6: true,
12+
},
13+
parserOptions: {
14+
ecmaVersion: 2018,
15+
},
16+
extends: ['@sentry-internal/sdk'],
17+
ignorePatterns: [
18+
'coverage/**',
19+
'build/**',
20+
'dist/**',
21+
'cjs/**',
22+
'esm/**',
23+
'examples/**',
24+
'test/manual/**',
25+
'types/**',
26+
// TODO: Remove these after migration
27+
'scripts/**',
28+
'config/**',
29+
'config/**',
30+
'__mocks__/**',
1031
],
11-
12-
settings: {},
13-
14-
globals: {},
15-
rules: {
16-
// note you must disable the base rule as it can report incorrect errors
17-
'no-unused-vars': 'off',
18-
'@typescript-eslint/no-unused-vars': [
19-
'error',
20-
{ vars: 'all', varsIgnorePattern: '^_', argsIgnorePattern: '^_' },
21-
],
22-
23-
'@typescript-eslint/no-explicit-any': 'off',
24-
25-
// Make sure that all ts-ignore comments are given a description.
26-
'@typescript-eslint/ban-ts-comment': [
27-
'warn',
28-
{
29-
'ts-ignore': 'allow-with-description',
32+
overrides: [
33+
{
34+
files: ['*.ts', '*.tsx', '*.d.ts'],
35+
parserOptions: {
36+
project: ['tsconfig.json'],
3037
},
31-
],
32-
33-
'simple-import-sort/imports': [
34-
'error',
35-
{
36-
groups: [
37-
// Side effect imports.
38-
['^\\u0000'],
39-
40-
// Node.js builtins.
41-
// eslint-disable-next-line @typescript-eslint/no-var-requires
42-
[`^(${require('module').builtinModules.join('|')})(/|$)`],
43-
44-
// Packages.
45-
['^@?\\w'],
46-
47-
// Internal packages.
48-
['^@$', '^(@/)(.*|$)'],
49-
50-
// Parent imports. Put `..` last.
51-
['^\\.\\.(?!/?$)', '^\\.\\./?$'],
52-
53-
// Other relative imports. Put same-folder imports and `.` last.
54-
['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'],
38+
},
39+
// TODO: Extract this to package-specific config after mgiration
40+
{
41+
files: ['worker/**/*.ts'],
42+
parserOptions: {
43+
project: ['config/tsconfig.worker.json'],
44+
},
45+
},
46+
{
47+
files: ['*.ts', '*.tsx', '*.d.ts'],
48+
rules: {
49+
// TODO (high-prio): Go through console logs and figure out which ones should be replaced with the SDK logger
50+
'no-console': 'off',
51+
// TODO (high-pio): Re-enable this after migration
52+
'no-restricted-globals': 'off',
53+
// TODO (high-prio): Re-enable this after migration
54+
'@typescript-eslint/explicit-member-accessibility': 'off',
55+
// TODO (high-prio): Remove this exception from naming convention after migration
56+
'@typescript-eslint/naming-convention': [
57+
'error',
58+
{
59+
selector: 'memberLike',
60+
modifiers: ['private'],
61+
format: ['camelCase'],
62+
leadingUnderscore: 'allow',
63+
},
64+
{
65+
selector: 'memberLike',
66+
modifiers: ['protected'],
67+
format: ['camelCase'],
68+
leadingUnderscore: 'allow',
69+
},
5570
],
71+
// TODO (high-prio): Re-enable this after migration
72+
'@sentry-internal/sdk/no-async-await': 'off',
73+
// TODO (high-prio): Re-enable this after migration
74+
'@typescript-eslint/no-floating-promises': 'off',
75+
// TODO (medium-prio): Re-enable this after migration
76+
'jsdoc/require-jsdoc': 'off',
77+
// TODO: Do we even want to turn this on? Why not enable ++?
78+
'no-plusplus': 'off',
5679
},
57-
],
58-
},
59-
overrides: [
80+
},
81+
{
82+
files: ['jest.setup.ts'],
83+
rules: {
84+
'no-console': 'off',
85+
},
86+
},
87+
{
88+
files: ['test/**/*.ts'],
89+
rules: {
90+
// TODO: decide if we want to keep our '@test' import paths
91+
'import/no-unresolved': 'off',
92+
// most of these errors come from `new Promise(process.nextTick)`
93+
'@typescript-eslint/unbound-method': 'off',
94+
// TODO: decide if we want to enable this again after the migration
95+
// We can take the freedom to be a bit more lenient with tests
96+
'@typescript-eslint/no-floating-promises': 'off',
97+
},
98+
},
99+
{
100+
files: ['src/worker/**/*.js'],
101+
parserOptions: {
102+
sourceType: 'module',
103+
},
104+
},
105+
// ----------------
60106
{
61-
files: ['*.spec.ts'],
107+
files: ['*.tsx'],
108+
rules: {
109+
// Turn off jsdoc on tsx files until jsdoc is fixed for tsx files
110+
// See: https://github.com/getsentry/sentry-javascript/issues/3871
111+
'jsdoc/require-jsdoc': 'off',
112+
},
113+
},
114+
{
115+
files: ['scenarios/**', 'rollup/**'],
116+
parserOptions: {
117+
sourceType: 'module',
118+
},
62119
rules: {
63-
'@typescript-eslint/no-var-requires': ['off'],
120+
'no-console': 'off',
64121
},
65122
},
66123
],

demo/yarn.lock

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,13 +1522,12 @@
15221522
tslib "^1.9.3"
15231523

15241524
"@sentry/replay@file:..":
1525-
version "0.6.14-3"
1525+
version "0.6.14"
15261526
dependencies:
15271527
"@sentry/core" "^7.7.0"
15281528
"@sentry/types" "^7.7.0"
15291529
"@sentry/utils" "^7.7.0"
15301530
lodash.debounce "^4.0.8"
1531-
pako "^2.0.4"
15321531
rrweb "^1.1.3"
15331532

15341533
"@sentry/tracing@^7.1.1":
@@ -6168,11 +6167,6 @@ p-try@^2.0.0:
61686167
version "2.2.0"
61696168
resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6"
61706169

6171-
pako@^2.0.4:
6172-
version "2.0.4"
6173-
resolved "https://registry.yarnpkg.com/pako/-/pako-2.0.4.tgz#6cebc4bbb0b6c73b0d5b8d7e8476e2b2fbea576d"
6174-
integrity sha512-v8tweI900AUkZN6heMU/4Uy4cXRc2AYNRggVmTR+dEncawDJgCdLMximOVA2p4qO57WMynangsfGRb5WD6L1Bg==
6175-
61766170
param-case@^3.0.4:
61776171
version "3.0.4"
61786172
resolved "https://registry.yarnpkg.com/param-case/-/param-case-3.0.4.tgz#7d17fe4aa12bde34d4a77d91acfb6219caad01c5"

jest.setup.ts

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
12
import { getCurrentHub } from '@sentry/core';
23
import { Transport } from '@sentry/types';
34

4-
import { Session } from './src/session/Session';
55
import { Replay } from './src';
6+
import { Session } from './src/session/Session';
67

78
// @ts-ignore TS error, this is replaced in prod builds bc of rollup
89
global.__SENTRY_REPLAY_VERSION__ = 'version:Test';
@@ -40,10 +41,8 @@ type SentReplayExpected = {
4041
events?: string | Uint8Array;
4142
};
4243

43-
const toHaveSameSession = function (
44-
received: jest.Mocked<Replay>,
45-
expected: undefined | Session
46-
) {
44+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
45+
const toHaveSameSession = function (received: jest.Mocked<Replay>, expected: undefined | Session) {
4746
const pass = this.equals(received.session?.id, expected?.id) as boolean;
4847

4948
const options = {
@@ -54,13 +53,7 @@ const toHaveSameSession = function (
5453
return {
5554
pass,
5655
message: () =>
57-
this.utils.matcherHint(
58-
'toHaveSameSession',
59-
undefined,
60-
undefined,
61-
options
62-
) +
63-
'\n\n' +
56+
`${this.utils.matcherHint('toHaveSameSession', undefined, undefined, options)}\n\n` +
6457
`Expected: ${pass ? 'not ' : ''}${this.utils.printExpected(expected)}\n` +
6558
`Received: ${this.utils.printReceived(received.session)}`,
6659
};
@@ -70,23 +63,17 @@ const toHaveSameSession = function (
7063
* Checks the last call to `fetch` and ensures a replay was uploaded by
7164
* checking the `fetch()` request's body.
7265
*/
66+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
7367
const toHaveSentReplay = function (
7468
_received: jest.Mocked<Replay>,
75-
expected?:
76-
| SentReplayExpected
77-
| { sample: SentReplayExpected; inverse: boolean }
69+
expected?: SentReplayExpected | { sample: SentReplayExpected; inverse: boolean },
7870
) {
79-
const { calls } = (
80-
getCurrentHub().getClient()?.getTransport()?.send as MockTransport
81-
).mock;
71+
const { calls } = (getCurrentHub().getClient()?.getTransport()?.send as MockTransport).mock;
8272
const lastCall = calls[calls.length - 1]?.[0];
8373

8474
const envelopeHeader = lastCall?.[0];
8575
const envelopeItems = lastCall?.[1] || [[], []];
86-
const [
87-
[replayEventHeader, replayEventPayload],
88-
[recordingHeader, recordingPayload] = [],
89-
] = envelopeItems;
76+
const [[replayEventHeader, replayEventPayload], [recordingHeader, recordingPayload] = []] = envelopeItems;
9077

9178
// @ts-ignore recordingPayload is always a string in our tests
9279
const [recordingPayloadHeader, events] = recordingPayload?.split('\n') || [];
@@ -100,39 +87,28 @@ const toHaveSentReplay = function (
10087
replayEventPayload: replayEventPayload,
10188
// @ts-ignore Custom envelope
10289
recordingHeader: recordingHeader,
103-
recordingPayloadHeader:
104-
recordingPayloadHeader && JSON.parse(recordingPayloadHeader),
90+
recordingPayloadHeader: recordingPayloadHeader && JSON.parse(recordingPayloadHeader),
10591
events,
10692
};
10793

108-
const isObjectContaining =
109-
expected && 'sample' in expected && 'inverse' in expected;
94+
const isObjectContaining = expected && 'sample' in expected && 'inverse' in expected;
11095
const expectedObj = isObjectContaining
11196
? (expected as { sample: SentReplayExpected }).sample
11297
: (expected as SentReplayExpected);
11398

11499
if (isObjectContaining) {
115-
console.warn(
116-
'`expect.objectContaining` is unnecessary when using the `toHaveSentReplay` matcher'
117-
);
100+
console.warn('`expect.objectContaining` is unnecessary when using the `toHaveSentReplay` matcher');
118101
}
119102

120103
const results = expected
121104
? Object.entries(actualObj)
122105
.map(([key, val]: [keyof SentReplayExpected, any]) => {
123-
return [
124-
!expectedObj?.[key] || this.equals(expectedObj[key], val),
125-
key,
126-
expectedObj?.[key],
127-
val,
128-
];
106+
return [!expectedObj?.[key] || this.equals(expectedObj[key], val), key, expectedObj?.[key], val];
129107
})
130108
.filter(([passed]) => !passed)
131109
: [];
132110

133-
const payloadPassed = Boolean(
134-
lastCall && (!expected || results.length === 0)
135-
);
111+
const payloadPassed = Boolean(lastCall && (!expected || results.length === 0));
136112

137113
const options = {
138114
isNot: this.isNot,
@@ -148,22 +124,13 @@ const toHaveSentReplay = function (
148124
? allPass
149125
? 'Expected Replay to not have been sent, but a request was attempted'
150126
: 'Expected Replay to have been sent, but a request was not attempted'
151-
: this.utils.matcherHint(
152-
'toHaveSentReplay',
153-
undefined,
154-
undefined,
155-
options
156-
) +
157-
'\n\n' +
158-
results
127+
: `${this.utils.matcherHint('toHaveSentReplay', undefined, undefined, options)}\n\n${results
159128
.map(
160129
([, key, expected, actual]) =>
161-
`Expected (key: ${key}): ${
162-
payloadPassed ? 'not ' : ''
163-
}${this.utils.printExpected(expected)}\n` +
164-
`Received (key: ${key}): ${this.utils.printReceived(actual)}`
130+
`Expected (key: ${key}): ${payloadPassed ? 'not ' : ''}${this.utils.printExpected(expected)}\n` +
131+
`Received (key: ${key}): ${this.utils.printReceived(actual)}`,
165132
)
166-
.join('\n'),
133+
.join('\n')}`,
167134
};
168135
};
169136

package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"fix:eslint": "eslint . --format stylish --fix",
2525
"fix:prettier": "prettier --write \"{src,test,scripts,worker}/**/*.ts\"",
2626
"lint": "run-s lint:prettier lint:eslint",
27-
"lint:eslint": "eslint . --ext .js,.jsx,.ts,.tsx #TODO: we might want to use eslintcache after migration",
27+
"lint:eslint": "eslint . --format stylish #TODO: we might want to use eslintcache after migration",
2828
"lint:prettier": "prettier --check \"{src,test,scripts,worker}/**/*.ts\"",
2929
"test": "jest",
3030
"test:watch": "jest --watch",
@@ -47,6 +47,7 @@
4747
"@rollup/plugin-node-resolve": "^13.3.0",
4848
"@rollup/plugin-replace": "^4.0.0",
4949
"@rollup/plugin-typescript": "^8.3.1",
50+
"@sentry-internal/eslint-config-sdk": "^7.20.1",
5051
"@sentry/browser": "^7.7.0",
5152
"@size-limit/file": "^8.1.0",
5253
"@size-limit/time": "^8.1.0",
@@ -55,12 +56,7 @@
5556
"@types/lodash.throttle": "^4.1.7",
5657
"@types/node": "^18.11.0",
5758
"@types/pako": "^2.0.0",
58-
"@typescript-eslint/eslint-plugin": "^5.31.0",
59-
"@typescript-eslint/parser": "^5.31.0",
6059
"eslint": "7.32.0",
61-
"eslint-config-prettier": "^8.5.0",
62-
"eslint-plugin-prettier": "^4.0.0",
63-
"eslint-plugin-simple-import-sort": "^7.0.0",
6460
"jest": "27.5.1",
6561
"jest-environment-jsdom": "27.5.1",
6662
"jsdom-worker": "^0.2.1",

src/coreHandlers/getBreadcrumbHandler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { InstrumentationTypeBreadcrumb } from '../types';
2-
32
import { handleDom } from './handleDom';
43
import { handleScope } from './handleScope';
54

5+
// TODO: Add return type
6+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
67
export function getBreadcrumbHandler(type: InstrumentationTypeBreadcrumb) {
78
if (type === 'scope') {
89
return handleScope;

src/coreHandlers/getSpanHandler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { InstrumentationTypeSpan } from '../types';
2-
32
import { handleFetch } from './handleFetch';
43
import { handleHistory } from './handleHistory';
54
import { handleXhr } from './handleXhr';
65

6+
// TODO: Add return type
7+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
78
export function getSpanHandler(type: InstrumentationTypeSpan) {
89
if (type === 'fetch') {
910
return handleFetch;

0 commit comments

Comments
 (0)