Skip to content

Commit 9af6477

Browse files
authored
style(lint): Introduce no-console rule to some pkg (getsentry#2112)
Adds [no-console](https://palantir.github.io/tslint/rules/no-console/) TSLint rule to integrations and browser repos and fixes these warnings.
1 parent 0d1c971 commit 9af6477

File tree

7 files changed

+23
-21
lines changed

7 files changed

+23
-21
lines changed

packages/browser/tslint.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"extends": "@sentry/typescript/tslint"
2+
"extends": "@sentry/typescript/tslint",
3+
"rules": {
4+
"no-console": true
5+
}
36
}

packages/integrations/src/angular.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Event, EventProcessor, Hub, Integration } from '@sentry/types';
2-
import { getGlobalObject } from '@sentry/utils';
2+
import { getGlobalObject, logger } from '@sentry/utils';
33

44
// See https://github.com/angular/angular.js/blob/v1.4.7/src/minErr.js
55
const angularPattern = /^\[((?:[$a-zA-Z0-9]+:)?(?:[$a-zA-Z0-9]+))\] (.*?)\n?(\S+)$/;
@@ -48,7 +48,7 @@ export class Angular implements Integration {
4848
*/
4949
public setupOnce(_: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
5050
if (!this._angular) {
51-
console.error('AngularIntegration is missing an Angular instance');
51+
logger.error('AngularIntegration is missing an Angular instance');
5252
return;
5353
}
5454

packages/integrations/src/ember.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { EventProcessor, Hub, Integration } from '@sentry/types';
2-
import { getGlobalObject } from '@sentry/utils';
2+
import { getGlobalObject, logger } from '@sentry/utils';
33

44
/** JSDoc */
55
export class Ember implements Integration {
@@ -32,7 +32,7 @@ export class Ember implements Integration {
3232
// tslint:disable:no-unsafe-any
3333

3434
if (!this._Ember) {
35-
console.error('EmberIntegration is missing an Ember instance');
35+
logger.error('EmberIntegration is missing an Ember instance');
3636
return;
3737
}
3838

packages/integrations/src/extraerrordata.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Event, EventHint, EventProcessor, ExtendedError, Hub, Integration } from '@sentry/types';
2-
import { isError, isPlainObject, normalize } from '@sentry/utils';
2+
import { isError, isPlainObject, logger, normalize } from '@sentry/utils';
33

44
/** JSDoc */
55
interface ExtraErrorDataOptions {
@@ -94,7 +94,7 @@ export class ExtraErrorData implements Integration {
9494
};
9595
}
9696
} catch (oO) {
97-
console.error('Unable to extract extra data from the Error object:', oO);
97+
logger.error('Unable to extract extra data from the Error object:', oO);
9898
}
9999

100100
return result;

packages/integrations/src/tracing.ts

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { EventProcessor, Hub, Integration } from '@sentry/types';
2-
import { consoleSandbox, fill, getGlobalObject, isMatchingPattern, supportsNativeFetch } from '@sentry/utils';
2+
import { fill, getGlobalObject, isMatchingPattern, logger, supportsNativeFetch } from '@sentry/utils';
33

44
/** JSDoc */
55
interface TracingOptions {
@@ -37,16 +37,12 @@ export class Tracing implements Integration {
3737
*/
3838
public constructor(private readonly _options: TracingOptions = {}) {
3939
if (!Array.isArray(_options.tracingOrigins) || _options.tracingOrigins.length === 0) {
40-
consoleSandbox(() => {
41-
const defaultTracingOrigins = ['localhost', /^\//];
42-
// @ts-ignore
43-
console.warn(
44-
'Sentry: You need to define `tracingOrigins` in the options. Set an array of urls or patterns to trace.',
45-
);
46-
// @ts-ignore
47-
console.warn(`Sentry: We added a reasonable default for you: ${defaultTracingOrigins}`);
48-
_options.tracingOrigins = defaultTracingOrigins;
49-
});
40+
const defaultTracingOrigins = ['localhost', /^\//];
41+
logger.warn(
42+
'Sentry: You need to define `tracingOrigins` in the options. Set an array of urls or patterns to trace.',
43+
);
44+
logger.warn(`Sentry: We added a reasonable default for you: ${defaultTracingOrigins}`);
45+
_options.tracingOrigins = defaultTracingOrigins;
5046
}
5147
}
5248

packages/integrations/src/vue.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { EventProcessor, Hub, Integration } from '@sentry/types';
2-
import { getGlobalObject, isPlainObject } from '@sentry/utils';
2+
import { getGlobalObject, isPlainObject, logger } from '@sentry/utils';
33

44
/** JSDoc */
55
interface Metadata {
@@ -65,7 +65,7 @@ export class Vue implements Integration {
6565
// tslint:disable:no-unsafe-any
6666

6767
if (!this._Vue || !this._Vue.config) {
68-
console.error('VueIntegration is missing a Vue instance');
68+
logger.error('VueIntegration is missing a Vue instance');
6969
return;
7070
}
7171

packages/integrations/tslint.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"extends": "@sentry/typescript/tslint"
2+
"extends": "@sentry/typescript/tslint",
3+
"rules": {
4+
"no-console": true
5+
}
36
}

0 commit comments

Comments
 (0)