Skip to content

Commit 19c8d29

Browse files
committed
more changes
1 parent 5c21faf commit 19c8d29

File tree

22 files changed

+280
-161
lines changed

22 files changed

+280
-161
lines changed

.eslintrc.js

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,101 @@ module.exports = {
44
node: true,
55
},
66
extends: ['prettier', 'eslint:recommended'],
7-
plugins: ['sentry-sdk'],
7+
plugins: ['sentry-sdk', 'jsdoc'],
8+
ignorePatterns: ['eslint-plugin-sentry-sdk'],
89
overrides: [
910
{
11+
// Configuration for JavaScript files
1012
files: ['*.js'],
1113
rules: {
1214
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
1315
},
1416
},
1517
{
16-
files: ['*.ts'],
18+
// Configuration for typescript files
19+
files: ['*.ts', '*.tsx'],
1720
extends: ['plugin:@typescript-eslint/recommended', 'prettier/@typescript-eslint'],
1821
plugins: ['@typescript-eslint'],
1922
parser: '@typescript-eslint/parser',
2023
rules: {
24+
// We want to prevent async await usage in our files to prevent uncessary bundle size.
2125
'sentry-sdk/no-async-await': 'error',
26+
2227
// Make sure variables marked with _ are ignored (ex. _varName)
2328
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
29+
30+
// Make sure that all ts-ignore comments are given a description
31+
'@typescript-eslint/ban-ts-comment': [
32+
'warn',
33+
{
34+
'ts-ignore': 'allow-with-description',
35+
},
36+
],
37+
38+
// Types usage should be explicit as possible, so we prevent usage of inferrable types.
39+
// This is especially important because we have a public API, so usage needs to be as
40+
// easy to understand as possible
41+
'@typescript-eslint/no-inferrable-types': 'off',
42+
43+
// Enforce type annotations to maintain consistency. This is especially important as
44+
// we have a public API, so we want changes to be very explicit.
45+
'@typescript-eslint/typedef': ['error', { arrowParameter: false }],
46+
'@typescript-eslint/explicit-function-return-type': 'error',
47+
48+
// Consistent ordering of fields, methods and constructors for classes should be enforced
49+
'@typescript-eslint/member-ordering': 'error',
50+
51+
// Private and protected members of a class should be prefixed with a leading underscore
52+
'@typescript-eslint/naming-convention': [
53+
'error',
54+
{
55+
selector: 'memberLike',
56+
modifiers: ['private'],
57+
format: ['camelCase'],
58+
leadingUnderscore: 'require',
59+
},
60+
{
61+
selector: 'memberLike',
62+
modifiers: ['protected'],
63+
format: ['camelCase'],
64+
leadingUnderscore: 'require',
65+
},
66+
],
67+
68+
// JSDOC comments are required for classes and methods
69+
'jsdoc/require-jsdoc': [
70+
'error',
71+
{ require: { ClassDeclaration: true, MethodDefinition: true }, checkConstructors: false },
72+
],
2473
},
2574
},
2675
{
76+
// Configuration for test files
2777
env: {
2878
jest: true,
2979
},
30-
files: ['*.test.ts'],
80+
files: ['*.test.ts', '*.test.tsx', '*.test.js', '*.test.jsx'],
81+
rules: {
82+
'sentry-sdk/no-async-await': 'off',
83+
'jsdoc/require-jsdoc': 'off',
84+
},
3185
},
3286
{
87+
// Configuration for config files like webpack/rollback
3388
files: ['*.config.js'],
3489
parserOptions: {
3590
sourceType: 'module',
3691
ecmaVersion: 2018,
3792
},
3893
},
3994
],
40-
rules: {},
95+
96+
rules: {
97+
// We want to prevent usage of unary operators outside of for loops
98+
'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
99+
100+
// disallow usage of console and alert
101+
'no-console': 'error',
102+
'no-alert': 'error',
103+
},
41104
};

eslint-plugin-sentry-sdk/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ const noAsyncAwait = {
2929
});
3030
}
3131
},
32+
33+
ArrowFunctionExpression(node) {
34+
if (node.async) {
35+
context.report({
36+
node,
37+
message:
38+
'Using async-await can add a lot to bundle size. Please do not use it outside of tests, use Promises instead',
39+
});
40+
}
41+
},
3242
};
3343
},
3444
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"danger-plugin-tslint": "^2.0.0",
5252
"eslint": "^7.5.0",
5353
"eslint-config-prettier": "^6.11.0",
54+
"eslint-plugin-jsdoc": "^30.0.3",
5455
"eslint-plugin-sentry-sdk": "file:./eslint-plugin-sentry-sdk",
5556
"jest": "^24.7.1",
5657
"karma-browserstack-launcher": "^1.5.1",

packages/browser/.eslintrc.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@ module.exports = {
44
es6: true,
55
browser: true,
66
},
7+
parserOptions: {
8+
ecmaVersion: 2018,
9+
},
710
extends: ['../../.eslintrc.js'],
811
ignorePatterns: ['build/**/*', 'dist/**/*', 'esm/**/*', 'examples/**/*', 'scripts/**/*', 'src/loader.js'],
912
overrides: [
13+
{
14+
files: ['test/**/*'],
15+
rules: {
16+
'jsdoc/require-jsdoc': 'off',
17+
'no-console': 'off',
18+
},
19+
},
1020
{
1121
files: ['test/integration/**/*'],
1222
env: {
@@ -17,7 +27,7 @@ module.exports = {
1727
},
1828
},
1929
{
20-
files: ['test/integration/common/**/*'],
30+
files: ['test/integration/common/**/*', 'test/integration/suites/**/*'],
2131
rules: {
2232
'no-unused-vars': 'off',
2333
},

packages/browser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"build:watch": "run-p build:dist:watch build:esm:watch build:bundle:watch",
6464
"clean": "rimraf dist coverage .rpt2_cache build esm",
6565
"link:yarn": "yarn link",
66-
"lint": "run-s lint:eslint lint:tslint",
66+
"lint": "run-s lint:prettier lint:eslint",
6767
"lint:prettier": "prettier-check \"{src,test}/**/*.ts\"",
6868
"lint:eslint": "eslint . --format stylish",
6969
"lint:eslint:json": "eslint . --format json | tee lint-results.json",

packages/browser/src/backend.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ export interface BrowserOptions extends Options {
3636
* @hidden
3737
*/
3838
export class BrowserBackend extends BaseBackend<BrowserOptions> {
39+
/**
40+
* @inheritDoc
41+
*/
42+
public eventFromException(exception: unknown, hint?: EventHint): PromiseLike<Event> {
43+
return eventFromException(this._options, exception, hint);
44+
}
45+
/**
46+
* @inheritDoc
47+
*/
48+
public eventFromMessage(message: string, level: Severity = Severity.Info, hint?: EventHint): PromiseLike<Event> {
49+
return eventFromMessage(this._options, message, level, hint);
50+
}
51+
3952
/**
4053
* @inheritDoc
4154
*/
@@ -58,17 +71,4 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> {
5871
}
5972
return new XHRTransport(transportOptions);
6073
}
61-
62-
/**
63-
* @inheritDoc
64-
*/
65-
public eventFromException(exception: unknown, hint?: EventHint): PromiseLike<Event> {
66-
return eventFromException(this._options, exception, hint);
67-
}
68-
/**
69-
* @inheritDoc
70-
*/
71-
public eventFromMessage(message: string, level: Severity = Severity.Info, hint?: EventHint): PromiseLike<Event> {
72-
return eventFromMessage(this._options, message, level, hint);
73-
}
7474
}

packages/browser/src/client.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,29 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
2323
super(BrowserBackend, options);
2424
}
2525

26+
/**
27+
* Show a report dialog to the user to send feedback to a specific event.
28+
*
29+
* @param options Set individual options for the dialog
30+
*/
31+
public showReportDialog(options: ReportDialogOptions = {}): void {
32+
// doesn't work without a document (React Native)
33+
const document = getGlobalObject<Window>().document;
34+
if (!document) {
35+
return;
36+
}
37+
38+
if (!this._isEnabled()) {
39+
logger.error('Trying to call showReportDialog with Sentry Client disabled');
40+
return;
41+
}
42+
43+
injectReportDialog({
44+
...options,
45+
dsn: options.dsn || this.getDsn(),
46+
});
47+
}
48+
2649
/**
2750
* @inheritDoc
2851
*/
@@ -54,27 +77,4 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
5477
}
5578
super._sendEvent(event);
5679
}
57-
58-
/**
59-
* Show a report dialog to the user to send feedback to a specific event.
60-
*
61-
* @param options Set individual options for the dialog
62-
*/
63-
public showReportDialog(options: ReportDialogOptions = {}): void {
64-
// doesn't work without a document (React Native)
65-
const document = getGlobalObject<Window>().document;
66-
if (!document) {
67-
return;
68-
}
69-
70-
if (!this._isEnabled()) {
71-
logger.error('Trying to call showReportDialog with Sentry Client disabled');
72-
return;
73-
}
74-
75-
injectReportDialog({
76-
...options,
77-
dsn: options.dsn || this.getDsn(),
78-
});
79-
}
8080
}

packages/browser/src/integrations/breadcrumbs.ts

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ export class Breadcrumbs implements Integration {
4040
/**
4141
* @inheritDoc
4242
*/
43-
public name: string = Breadcrumbs.id;
43+
public static id: string = 'Breadcrumbs';
4444

4545
/**
4646
* @inheritDoc
4747
*/
48-
public static id = 'Breadcrumbs';
48+
public name: string = Breadcrumbs.id;
4949

5050
/** JSDoc */
5151
private readonly _options: BreadcrumbsOptions;
@@ -85,6 +85,57 @@ export class Breadcrumbs implements Integration {
8585
);
8686
}
8787

88+
/**
89+
* Instrument browser built-ins w/ breadcrumb capturing
90+
* - Console API
91+
* - DOM API (click/typing)
92+
* - XMLHttpRequest API
93+
* - Fetch API
94+
* - History API
95+
*/
96+
public setupOnce(): void {
97+
if (this._options.console) {
98+
addInstrumentationHandler({
99+
callback: (...args) => {
100+
this._consoleBreadcrumb(...args);
101+
},
102+
type: 'console',
103+
});
104+
}
105+
if (this._options.dom) {
106+
addInstrumentationHandler({
107+
callback: (...args) => {
108+
this._domBreadcrumb(...args);
109+
},
110+
type: 'dom',
111+
});
112+
}
113+
if (this._options.xhr) {
114+
addInstrumentationHandler({
115+
callback: (...args) => {
116+
this._xhrBreadcrumb(...args);
117+
},
118+
type: 'xhr',
119+
});
120+
}
121+
if (this._options.fetch) {
122+
addInstrumentationHandler({
123+
callback: (...args) => {
124+
this._fetchBreadcrumb(...args);
125+
},
126+
type: 'fetch',
127+
});
128+
}
129+
if (this._options.history) {
130+
addInstrumentationHandler({
131+
callback: (...args) => {
132+
this._historyBreadcrumb(...args);
133+
},
134+
type: 'history',
135+
});
136+
}
137+
}
138+
88139
/**
89140
* Creates breadcrumbs from console API calls
90141
*/
@@ -256,55 +307,4 @@ export class Breadcrumbs implements Integration {
256307
},
257308
});
258309
}
259-
260-
/**
261-
* Instrument browser built-ins w/ breadcrumb capturing
262-
* - Console API
263-
* - DOM API (click/typing)
264-
* - XMLHttpRequest API
265-
* - Fetch API
266-
* - History API
267-
*/
268-
public setupOnce(): void {
269-
if (this._options.console) {
270-
addInstrumentationHandler({
271-
callback: (...args) => {
272-
this._consoleBreadcrumb(...args);
273-
},
274-
type: 'console',
275-
});
276-
}
277-
if (this._options.dom) {
278-
addInstrumentationHandler({
279-
callback: (...args) => {
280-
this._domBreadcrumb(...args);
281-
},
282-
type: 'dom',
283-
});
284-
}
285-
if (this._options.xhr) {
286-
addInstrumentationHandler({
287-
callback: (...args) => {
288-
this._xhrBreadcrumb(...args);
289-
},
290-
type: 'xhr',
291-
});
292-
}
293-
if (this._options.fetch) {
294-
addInstrumentationHandler({
295-
callback: (...args) => {
296-
this._fetchBreadcrumb(...args);
297-
},
298-
type: 'fetch',
299-
});
300-
}
301-
if (this._options.history) {
302-
addInstrumentationHandler({
303-
callback: (...args) => {
304-
this._historyBreadcrumb(...args);
305-
},
306-
type: 'history',
307-
});
308-
}
309-
}
310310
}

0 commit comments

Comments
 (0)