Skip to content

Commit 8cbcff2

Browse files
authored
chore(build): Upgrade to Prettier 2.x (#4452)
This upgrades all of our packages to use the latest version of Prettier, which is currently 2.5.1, in order to have support for linting of code written in typescript 3.8 and above. When Prettier went to 2.0, it introduced some changes to its defaults[1], most notably: - casting between two unlike types, with a cast to `unknown` in between, no longer requires parentheses around the first cast, - inline functions defined with the `function` keyword now have a space after the word `function`, and - indentation of multi-line expressions and statements is adjusted, sometimes to make more lines, sometimes fewer. All three of these have been applied to all of the code in the repo. The final change to defaults - to make it so that parameter lists in arrow functions always have parentheses around them, even if they only consist of one parameter - led to a lot of visual noise, so it's been overridden to preserve the current formatting. [1] https://prettier.io/blog/2020/03/21/2.0.0.html
1 parent 3f3c75b commit 8cbcff2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+319
-338
lines changed

.prettierrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"arrowParens": "avoid",
23
"printWidth": 120,
34
"proseWrap": "always",
45
"singleQuote": true,

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"madge": "4.0.2",
6969
"mocha": "^6.1.4",
7070
"npm-run-all": "^4.1.5",
71-
"prettier": "1.19.1",
71+
"prettier": "2.5.1",
7272
"replace-in-file": "^4.0.0",
7373
"rimraf": "^3.0.2",
7474
"sinon": "^7.3.2",

packages/angular/src/tracing.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export function TraceClassDecorator(): ClassDecorator {
183183
return target => {
184184
const originalOnInit = target.prototype.ngOnInit;
185185
// eslint-disable-next-line @typescript-eslint/no-explicit-any
186-
target.prototype.ngOnInit = function(...args: any[]): ReturnType<typeof originalOnInit> {
186+
target.prototype.ngOnInit = function (...args: any[]): ReturnType<typeof originalOnInit> {
187187
const activeTransaction = getActiveTransaction();
188188
if (activeTransaction) {
189189
tracingSpan = activeTransaction.startChild({
@@ -198,7 +198,7 @@ export function TraceClassDecorator(): ClassDecorator {
198198

199199
const originalAfterViewInit = target.prototype.ngAfterViewInit;
200200
// eslint-disable-next-line @typescript-eslint/no-explicit-any
201-
target.prototype.ngAfterViewInit = function(...args: any[]): ReturnType<typeof originalAfterViewInit> {
201+
target.prototype.ngAfterViewInit = function (...args: any[]): ReturnType<typeof originalAfterViewInit> {
202202
if (tracingSpan) {
203203
tracingSpan.finish();
204204
}
@@ -218,7 +218,7 @@ export function TraceMethodDecorator(): MethodDecorator {
218218
return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
219219
const originalMethod = descriptor.value;
220220
// eslint-disable-next-line @typescript-eslint/no-explicit-any
221-
descriptor.value = function(...args: any[]): ReturnType<typeof originalMethod> {
221+
descriptor.value = function (...args: any[]): ReturnType<typeof originalMethod> {
222222
const now = timestampWithMs();
223223
const activeTransaction = getActiveTransaction();
224224
if (activeTransaction) {

packages/browser/src/helpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export function wrap(
8080

8181
/* eslint-disable prefer-rest-params */
8282
// eslint-disable-next-line @typescript-eslint/no-explicit-any
83-
const sentryWrapped: WrappedFunction = function(this: any): void {
83+
const sentryWrapped: WrappedFunction = function (this: any): void {
8484
const args = Array.prototype.slice.call(arguments);
8585

8686
try {

packages/browser/src/integrations/breadcrumbs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function _domBreadcrumb(dom: BreadcrumbsOptions['dom']): (handlerData: { [key: s
121121
try {
122122
target = handlerData.event.target
123123
? htmlTreeAsString(handlerData.event.target as Node, keyAttrs)
124-
: htmlTreeAsString((handlerData.event as unknown) as Node, keyAttrs);
124+
: htmlTreeAsString(handlerData.event as unknown as Node, keyAttrs);
125125
} catch (e) {
126126
target = '<unknown>';
127127
}

packages/browser/src/integrations/globalhandlers.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ function _eventFromRejectionWithPrimitive(reason: Primitive): Event {
181181
*/
182182
// eslint-disable-next-line @typescript-eslint/no-explicit-any
183183
function _eventFromIncompleteOnError(msg: any, url: any, line: any, column: any): Event {
184-
const ERROR_TYPES_RE = /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i;
184+
const ERROR_TYPES_RE =
185+
/^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i;
185186

186187
// If 'message' is ErrorEvent, get real message from inside
187188
let message = isErrorEvent(msg) ? msg.message : msg;

packages/browser/src/integrations/trycatch.ts

+53-47
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class TryCatch implements Integration {
109109
/** JSDoc */
110110
function _wrapTimeFunction(original: () => void): () => number {
111111
// eslint-disable-next-line @typescript-eslint/no-explicit-any
112-
return function(this: any, ...args: any[]): number {
112+
return function (this: any, ...args: any[]): number {
113113
const originalCallback = args[0];
114114
args[0] = wrap(originalCallback, {
115115
mechanism: {
@@ -126,7 +126,7 @@ function _wrapTimeFunction(original: () => void): () => number {
126126
// eslint-disable-next-line @typescript-eslint/no-explicit-any
127127
function _wrapRAF(original: any): (callback: () => void) => any {
128128
// eslint-disable-next-line @typescript-eslint/no-explicit-any
129-
return function(this: any, callback: () => void): () => void {
129+
return function (this: any, callback: () => void): () => void {
130130
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
131131
return original.call(
132132
this,
@@ -147,15 +147,15 @@ function _wrapRAF(original: any): (callback: () => void) => any {
147147
/** JSDoc */
148148
function _wrapXHR(originalSend: () => void): () => void {
149149
// eslint-disable-next-line @typescript-eslint/no-explicit-any
150-
return function(this: XMLHttpRequest, ...args: any[]): void {
150+
return function (this: XMLHttpRequest, ...args: any[]): void {
151151
// eslint-disable-next-line @typescript-eslint/no-this-alias
152152
const xhr = this;
153153
const xmlHttpRequestProps: XMLHttpRequestProp[] = ['onload', 'onerror', 'onprogress', 'onreadystatechange'];
154154

155155
xmlHttpRequestProps.forEach(prop => {
156156
if (prop in xhr && typeof xhr[prop] === 'function') {
157157
// eslint-disable-next-line @typescript-eslint/no-explicit-any
158-
fill(xhr, prop, function(original: WrappedFunction): () => any {
158+
fill(xhr, prop, function (original: WrappedFunction): () => any {
159159
const wrapOptions = {
160160
mechanism: {
161161
data: {
@@ -195,10 +195,12 @@ function _wrapEventTarget(target: string): void {
195195
return;
196196
}
197197

198-
fill(proto, 'addEventListener', function(
199-
original: () => void,
200-
): (eventName: string, fn: EventListenerObject, options?: boolean | AddEventListenerOptions) => void {
201-
return function(
198+
fill(proto, 'addEventListener', function (original: () => void): (
199+
eventName: string,
200+
fn: EventListenerObject,
201+
options?: boolean | AddEventListenerOptions,
202+
) => void {
203+
return function (
202204
// eslint-disable-next-line @typescript-eslint/no-explicit-any
203205
this: any,
204206
eventName: string,
@@ -227,7 +229,7 @@ function _wrapEventTarget(target: string): void {
227229
this,
228230
eventName,
229231
// eslint-disable-next-line @typescript-eslint/no-explicit-any
230-
wrap((fn as any) as WrappedFunction, {
232+
wrap(fn as any as WrappedFunction, {
231233
mechanism: {
232234
data: {
233235
function: 'addEventListener',
@@ -243,44 +245,48 @@ function _wrapEventTarget(target: string): void {
243245
};
244246
});
245247

246-
fill(proto, 'removeEventListener', function(
247-
originalRemoveEventListener: () => void,
248-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
249-
): (this: any, eventName: string, fn: EventListenerObject, options?: boolean | EventListenerOptions) => () => void {
250-
return function(
248+
fill(
249+
proto,
250+
'removeEventListener',
251+
function (
252+
originalRemoveEventListener: () => void,
251253
// eslint-disable-next-line @typescript-eslint/no-explicit-any
252-
this: any,
253-
eventName: string,
254-
fn: EventListenerObject,
255-
options?: boolean | EventListenerOptions,
256-
): () => void {
257-
/**
258-
* There are 2 possible scenarios here:
259-
*
260-
* 1. Someone passes a callback, which was attached prior to Sentry initialization, or by using unmodified
261-
* method, eg. `document.addEventListener.call(el, name, handler). In this case, we treat this function
262-
* as a pass-through, and call original `removeEventListener` with it.
263-
*
264-
* 2. Someone passes a callback, which was attached after Sentry was initialized, which means that it was using
265-
* our wrapped version of `addEventListener`, which internally calls `wrap` helper.
266-
* This helper "wraps" whole callback inside a try/catch statement, and attached appropriate metadata to it,
267-
* in order for us to make a distinction between wrapped/non-wrapped functions possible.
268-
* If a function was wrapped, it has additional property of `__sentry_wrapped__`, holding the handler.
269-
*
270-
* When someone adds a handler prior to initialization, and then do it again, but after,
271-
* then we have to detach both of them. Otherwise, if we'd detach only wrapped one, it'd be impossible
272-
* to get rid of the initial handler and it'd stick there forever.
273-
*/
274-
const wrappedEventHandler = (fn as unknown) as WrappedFunction;
275-
try {
276-
const originalEventHandler = wrappedEventHandler && wrappedEventHandler.__sentry_wrapped__;
277-
if (originalEventHandler) {
278-
originalRemoveEventListener.call(this, eventName, originalEventHandler, options);
254+
): (this: any, eventName: string, fn: EventListenerObject, options?: boolean | EventListenerOptions) => () => void {
255+
return function (
256+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
257+
this: any,
258+
eventName: string,
259+
fn: EventListenerObject,
260+
options?: boolean | EventListenerOptions,
261+
): () => void {
262+
/**
263+
* There are 2 possible scenarios here:
264+
*
265+
* 1. Someone passes a callback, which was attached prior to Sentry initialization, or by using unmodified
266+
* method, eg. `document.addEventListener.call(el, name, handler). In this case, we treat this function
267+
* as a pass-through, and call original `removeEventListener` with it.
268+
*
269+
* 2. Someone passes a callback, which was attached after Sentry was initialized, which means that it was using
270+
* our wrapped version of `addEventListener`, which internally calls `wrap` helper.
271+
* This helper "wraps" whole callback inside a try/catch statement, and attached appropriate metadata to it,
272+
* in order for us to make a distinction between wrapped/non-wrapped functions possible.
273+
* If a function was wrapped, it has additional property of `__sentry_wrapped__`, holding the handler.
274+
*
275+
* When someone adds a handler prior to initialization, and then do it again, but after,
276+
* then we have to detach both of them. Otherwise, if we'd detach only wrapped one, it'd be impossible
277+
* to get rid of the initial handler and it'd stick there forever.
278+
*/
279+
const wrappedEventHandler = fn as unknown as WrappedFunction;
280+
try {
281+
const originalEventHandler = wrappedEventHandler && wrappedEventHandler.__sentry_wrapped__;
282+
if (originalEventHandler) {
283+
originalRemoveEventListener.call(this, eventName, originalEventHandler, options);
284+
}
285+
} catch (e) {
286+
// ignore, accessing __sentry_wrapped__ will throw in some Selenium environments
279287
}
280-
} catch (e) {
281-
// ignore, accessing __sentry_wrapped__ will throw in some Selenium environments
282-
}
283-
return originalRemoveEventListener.call(this, eventName, wrappedEventHandler, options);
284-
};
285-
});
288+
return originalRemoveEventListener.call(this, eventName, wrappedEventHandler, options);
289+
};
290+
},
291+
);
286292
}

packages/browser/src/tracekit.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,15 @@ export interface StackTrace {
4242
const UNKNOWN_FUNCTION = '?';
4343

4444
// Chromium based browsers: Chrome, Brave, new Opera, new Edge
45-
const chrome = /^\s*at (?:(.*?) ?\()?((?:file|https?|blob|chrome-extension|address|native|eval|webpack|<anonymous>|[-a-z]+:|.*bundle|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
45+
const chrome =
46+
/^\s*at (?:(.*?) ?\()?((?:file|https?|blob|chrome-extension|address|native|eval|webpack|<anonymous>|[-a-z]+:|.*bundle|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
4647
// gecko regex: `(?:bundle|\d+\.js)`: `bundle` is for react native, `\d+\.js` also but specifically for ram bundles because it
4748
// generates filenames without a prefix like `file://` the filenames in the stacktrace are just 42.js
4849
// We need this specific case for now because we want no other regex to match.
49-
const gecko = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:file|https?|blob|chrome|webpack|resource|moz-extension|capacitor).*?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. /=]+)(?::(\d+))?(?::(\d+))?\s*$/i;
50-
const winjs = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i;
50+
const gecko =
51+
/^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:file|https?|blob|chrome|webpack|resource|moz-extension|capacitor).*?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. /=]+)(?::(\d+))?(?::(\d+))?\s*$/i;
52+
const winjs =
53+
/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i;
5154
const geckoEval = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
5255
const chromeEval = /\((\S*)(?::(\d+))(?::(\d+))\)/;
5356
// Based on our own mapping pattern - https://github.com/getsentry/sentry/blob/9f08305e09866c8bd6d0c24f5b0aabdd7dd6c59c/src/sentry/lang/javascript/errormapping.py#L83-L108
@@ -204,7 +207,8 @@ function computeStackTraceFromStacktraceProp(ex: any): StackTrace | null {
204207
// reliably in other circumstances.
205208
const stacktrace = ex.stacktrace;
206209
const opera10Regex = / line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i;
207-
const opera11Regex = / line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^)]+))\((.*)\))? in (.*):\s*$/i;
210+
const opera11Regex =
211+
/ line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^)]+))\((.*)\))? in (.*):\s*$/i;
208212
const lines = stacktrace.split('\n');
209213
const stack = [];
210214
let parts;

packages/browser/test/unit/index.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ describe('wrap()', () => {
325325

326326
it('should allow for passing this and arguments through binding', () => {
327327
const result = wrap(
328-
function(this: unknown, a: string, b: number): unknown[] {
328+
function (this: unknown, a: string, b: number): unknown[] {
329329
return [this, a, b];
330330
}.bind({ context: 'this' }, 'b', 42),
331331
);
@@ -335,7 +335,7 @@ describe('wrap()', () => {
335335
expect((result as unknown[])[2]).toBe(42);
336336

337337
const result2 = wrap(
338-
function(this: { x: number }): number {
338+
function (this: { x: number }): number {
339339
return this.x;
340340
}.bind({ x: 42 }),
341341
);

packages/browser/test/unit/integrations/helpers.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe('internal wrap()', () => {
135135
},
136136
};
137137
// @ts-ignore eventFn does not have property handleEvent
138-
context.eventFn.handleEvent = function(): void {
138+
context.eventFn.handleEvent = function (): void {
139139
expect(this).toBe(context);
140140
};
141141

packages/browser/test/unit/tracekit/custom.test.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -186,32 +186,28 @@ describe('Tracekit - Custom Tests', () => {
186186
const stacktrace = computeStackTrace(REACT_NATIVE_EXPO_EXCEPTION);
187187
expect(stacktrace.stack).toEqual([
188188
{
189-
url:
190-
'/data/user/0/com.sentrytest/files/.expo-internal/bundle-613EDD44F3305B9D75D4679663900F2BCDDDC326F247CA3202A3A4219FD412D3',
189+
url: '/data/user/0/com.sentrytest/files/.expo-internal/bundle-613EDD44F3305B9D75D4679663900F2BCDDDC326F247CA3202A3A4219FD412D3',
191190
func: 'onPress',
192191
args: [],
193192
line: 595,
194193
column: 658,
195194
},
196195
{
197-
url:
198-
'/data/user/0/com.sentrytest/files/.expo-internal/bundle-613EDD44F3305B9D75D4679663900F2BCDDDC326F247CA3202A3A4219FD412D3',
196+
url: '/data/user/0/com.sentrytest/files/.expo-internal/bundle-613EDD44F3305B9D75D4679663900F2BCDDDC326F247CA3202A3A4219FD412D3',
199197
func: 'value',
200198
args: [],
201199
line: 221,
202200
column: 7656,
203201
},
204202
{
205-
url:
206-
'/data/user/0/com.sentrytest/files/.expo-internal/bundle-613EDD44F3305B9D75D4679663900F2BCDDDC326F247CA3202A3A4219FD412D3',
203+
url: '/data/user/0/com.sentrytest/files/.expo-internal/bundle-613EDD44F3305B9D75D4679663900F2BCDDDC326F247CA3202A3A4219FD412D3',
207204
func: 'onResponderRelease',
208205
args: [],
209206
line: 221,
210207
column: 5666,
211208
},
212209
{
213-
url:
214-
'/data/user/0/com.sentrytest/files/.expo-internal/bundle-613EDD44F3305B9D75D4679663900F2BCDDDC326F247CA3202A3A4219FD412D3',
210+
url: '/data/user/0/com.sentrytest/files/.expo-internal/bundle-613EDD44F3305B9D75D4679663900F2BCDDDC326F247CA3202A3A4219FD412D3',
215211
func: 'p',
216212
args: [],
217213
line: 96,

packages/browser/test/unit/tracekit/original.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -881,8 +881,7 @@ describe('Tracekit - Original Tests', () => {
881881
column: 24,
882882
});
883883
expect(stackFrames.stack[7]).toEqual({
884-
url:
885-
'/home/username/sample-workspace/sampleapp.collect.react/node_modules/react-native/Libraries/Renderer/src/renderers/native/ReactNativeBaseComponent.js',
884+
url: '/home/username/sample-workspace/sampleapp.collect.react/node_modules/react-native/Libraries/Renderer/src/renderers/native/ReactNativeBaseComponent.js',
886885
func: 'this',
887886
args: [],
888887
line: 74,

packages/browser/test/unit/transports/base.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('BaseTransport', () => {
1414
navigator.sendBeacon = sendBeaconSpy;
1515
Object.defineProperty(document, 'visibilityState', {
1616
configurable: true,
17-
get: function() {
17+
get: function () {
1818
return visibilityState;
1919
},
2020
});

packages/core/src/integrations/functiontostring.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class FunctionToString implements Integration {
2323
originalFunctionToString = Function.prototype.toString;
2424

2525
// eslint-disable-next-line @typescript-eslint/no-explicit-any
26-
Function.prototype.toString = function(this: WrappedFunction, ...args: any[]): string {
26+
Function.prototype.toString = function (this: WrappedFunction, ...args: any[]): string {
2727
const context = getOriginalFunction(this) || this;
2828
return originalFunctionToString.apply(context, args);
2929
};

0 commit comments

Comments
 (0)