Skip to content

Commit d7401ac

Browse files
authored
chore: Add prettier settings and run prettier on the repo (#2950)
1 parent e445a1b commit d7401ac

Some content is hidden

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

81 files changed

+1284
-1675
lines changed

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/test/react-native/versions
2+

.prettierrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"arrowParens": "avoid",
3+
"printWidth": 120,
4+
"proseWrap": "always",
5+
"singleQuote": true,
6+
"trailingComma": "all"
7+
}

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
"build:tools": "tsc -p tsconfig.build.tools.json",
1818
"clean": "rimraf dist coverage",
1919
"test": "jest",
20-
"lint": "eslint --config .eslintrc.js .",
20+
"fix": "yarn fix:eslint && yarn fix:prettier",
21+
"fix:eslint": "eslint --config .eslintrc.js --fix .",
22+
"fix:prettier": "prettier --write \"{src,test,scripts}/**/**.ts\"",
23+
"lint": "yarn lint:eslint && yarn lint:prettier",
24+
"lint:eslint": "eslint --config .eslintrc.js .",
25+
"lint:prettier": "prettier --check \"{src,test,scripts}/**/**.ts\"",
2126
"test:watch": "jest --watch",
2227
"run-ios": "cd sample && yarn react-native run-ios",
2328
"run-android": "cd sample && yarn react-native run-android"

src/js/NativeRNSentry.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Package } from '@sentry/types';
2-
import type { TurboModule} from 'react-native';
2+
import type { TurboModule } from 'react-native';
33
import { TurboModuleRegistry } from 'react-native';
44
import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
55

@@ -10,7 +10,7 @@ export interface Spec extends TurboModule {
1010
captureEnvelope(
1111
bytes: number[],
1212
options: {
13-
store: boolean,
13+
store: boolean;
1414
},
1515
): Promise<boolean>;
1616
captureScreenshot(): Promise<NativeScreenshot[]>;
@@ -24,10 +24,7 @@ export interface Spec extends TurboModule {
2424
fetchNativeAppStart(): Promise<NativeAppStartResponse | null>;
2525
fetchNativeFrames(): Promise<NativeFramesResponse | null>;
2626
initNativeSdk(options: UnsafeObject): Promise<boolean>;
27-
setUser(
28-
defaultUserKeys: UnsafeObject | null,
29-
otherUserKeys: UnsafeObject | null
30-
): void;
27+
setUser(defaultUserKeys: UnsafeObject | null, otherUserKeys: UnsafeObject | null): void;
3128
setContext(key: string, value: UnsafeObject | null): void;
3229
setExtra(key: string, value: string): void;
3330
setTag(key: string, value: string): void;
@@ -89,7 +86,7 @@ export type NativeScreenshot = {
8986
data: number[];
9087
contentType: string;
9188
filename: string;
92-
}
89+
};
9390

9491
// The export must be here to pass codegen even if not used
9592
export default TurboModuleRegistry.getEnforcing<Spec>('RNSentry');

src/js/breadcrumb.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const DEFAULT_BREADCRUMB_LEVEL: SeverityLevel = 'info';
55

66
type BreadcrumbCandidate = {
77
[K in keyof Partial<Breadcrumb>]: unknown;
8-
}
8+
};
99

1010
/**
1111
* Convert plain object to a valid Breadcrumb
@@ -32,7 +32,7 @@ export function breadcrumbFromObject(candidate: BreadcrumbCandidate): Breadcrumb
3232
breadcrumb.data = candidate.data;
3333
}
3434
if (typeof candidate.timestamp === 'string') {
35-
const timestamp = Date.parse(candidate.timestamp)
35+
const timestamp = Date.parse(candidate.timestamp);
3636
if (!isNaN(timestamp)) {
3737
breadcrumb.timestamp = timestamp;
3838
}

src/js/client.ts

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import { NATIVE } from './wrapper';
3232
* @see SentryClient for usage documentation.
3333
*/
3434
export class ReactNativeClient extends BaseClient<ReactNativeClientOptions> {
35-
3635
private _outcomesBuffer: Outcome[];
3736

3837
/**
@@ -53,37 +52,31 @@ export class ReactNativeClient extends BaseClient<ReactNativeClientOptions> {
5352
* @inheritDoc
5453
*/
5554
public eventFromException(exception: unknown, hint: EventHint = {}): PromiseLike<Event> {
56-
return Screenshot.attachScreenshotToEventHint(hint, this._options)
57-
.then(hintWithScreenshot => eventFromException(
58-
this._options.stackParser,
59-
exception,
60-
hintWithScreenshot,
61-
this._options.attachStacktrace,
62-
));
55+
return Screenshot.attachScreenshotToEventHint(hint, this._options).then(hintWithScreenshot =>
56+
eventFromException(this._options.stackParser, exception, hintWithScreenshot, this._options.attachStacktrace),
57+
);
6358
}
6459

6560
/**
6661
* @inheritDoc
6762
*/
6863
public eventFromMessage(message: string, level?: SeverityLevel, hint?: EventHint): PromiseLike<Event> {
69-
return eventFromMessage(
70-
this._options.stackParser,
71-
message,
72-
level,
73-
hint,
74-
this._options.attachStacktrace,
75-
).then((event: Event) => {
76-
// TMP! Remove this function once JS SDK uses threads for messages
77-
if (!event.exception?.values || event.exception.values.length <= 0) {
64+
return eventFromMessage(this._options.stackParser, message, level, hint, this._options.attachStacktrace).then(
65+
(event: Event) => {
66+
// TMP! Remove this function once JS SDK uses threads for messages
67+
if (!event.exception?.values || event.exception.values.length <= 0) {
68+
return event;
69+
}
70+
const values = event.exception.values.map(
71+
(exception: Exception): Thread => ({
72+
stacktrace: exception.stacktrace,
73+
}),
74+
);
75+
(event as { threads?: { values: Thread[] } }).threads = { values };
76+
delete event.exception;
7877
return event;
79-
}
80-
const values = event.exception.values.map((exception: Exception): Thread => ({
81-
stacktrace: exception.stacktrace,
82-
}));
83-
(event as { threads?: { values: Thread[] } }).threads = { values };
84-
delete event.exception;
85-
return event;
86-
});
78+
},
79+
);
8780
}
8881

8982
/**
@@ -108,14 +101,11 @@ export class ReactNativeClient extends BaseClient<ReactNativeClientOptions> {
108101
* Sends user feedback to Sentry.
109102
*/
110103
public captureUserFeedback(feedback: UserFeedback): void {
111-
const envelope = createUserFeedbackEnvelope(
112-
feedback,
113-
{
114-
metadata: this._options._metadata,
115-
dsn: this.getDsn(),
116-
tunnel: this._options.tunnel,
117-
},
118-
);
104+
const envelope = createUserFeedbackEnvelope(feedback, {
105+
metadata: this._options._metadata,
106+
dsn: this.getDsn(),
107+
tunnel: this._options.tunnel,
108+
});
119109
this._sendEnvelope(envelope);
120110
}
121111

@@ -125,7 +115,7 @@ export class ReactNativeClient extends BaseClient<ReactNativeClientOptions> {
125115
public setupIntegrations(): void {
126116
super.setupIntegrations();
127117
const tracing = this.getIntegration(ReactNativeTracing);
128-
const routingName = tracing?.options.routingInstrumentation?.name
118+
const routingName = tracing?.options.routingInstrumentation?.name;
129119
if (routingName) {
130120
this.addIntegration(createIntegration(routingName));
131121
}
@@ -144,16 +134,16 @@ export class ReactNativeClient extends BaseClient<ReactNativeClientOptions> {
144134

145135
let shouldClearOutcomesBuffer = true;
146136
if (this._transport && this._dsn) {
147-
this._transport.send(envelope)
148-
.then(null, reason => {
149-
if (reason instanceof SentryError) { // SentryError is thrown by SyncPromise
150-
shouldClearOutcomesBuffer = false;
151-
// If this is called asynchronously we want the _outcomesBuffer to be cleared
152-
logger.error('SentryError while sending event, keeping outcomes buffer:', reason);
153-
} else {
154-
logger.error('Error while sending event:', reason);
155-
}
156-
});
137+
this._transport.send(envelope).then(null, reason => {
138+
if (reason instanceof SentryError) {
139+
// SentryError is thrown by SyncPromise
140+
shouldClearOutcomesBuffer = false;
141+
// If this is called asynchronously we want the _outcomesBuffer to be cleared
142+
logger.error('SentryError while sending event, keeping outcomes buffer:', reason);
143+
} else {
144+
logger.error('Error while sending event:', reason);
145+
}
146+
});
157147
} else {
158148
logger.error('Transport disabled');
159149
}
@@ -189,7 +179,7 @@ export class ReactNativeClient extends BaseClient<ReactNativeClientOptions> {
189179
if (__DEV__ && this._options.enableNativeNagger) {
190180
Alert.alert(
191181
'Sentry',
192-
'Warning, could not connect to Sentry native SDK.\nIf you do not want to use the native component please pass `enableNative: false` in the options.\nVisit: https://docs.sentry.io/platforms/react-native/#linking for more details.'
182+
'Warning, could not connect to Sentry native SDK.\nIf you do not want to use the native component please pass `enableNative: false` in the options.\nVisit: https://docs.sentry.io/platforms/react-native/#linking for more details.',
193183
);
194184
}
195185
}

src/js/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ export {
4848
withProfiler,
4949
} from '@sentry/react';
5050

51-
export {
52-
lastEventId,
53-
} from '@sentry/browser';
51+
export { lastEventId } from '@sentry/browser';
5452

5553
import * as Integrations from './integrations';
5654
import { SDK_NAME, SDK_VERSION } from './version';

src/js/integrations/debugsymbolicator.ts

Lines changed: 40 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import { addGlobalEventProcessor, getCurrentHub } from '@sentry/core';
22
import type { Event, EventHint, Integration, StackFrame } from '@sentry/types';
33
import { addContextToFrame, logger } from '@sentry/utils';
44

5-
const INTERNAL_CALLSITES_REGEX = new RegExp(
6-
['ReactNativeRenderer-dev\\.js$', 'MessageQueue\\.js$'].join('|')
7-
);
5+
const INTERNAL_CALLSITES_REGEX = new RegExp(['ReactNativeRenderer-dev\\.js$', 'MessageQueue\\.js$'].join('|'));
86

97
interface GetDevServer {
108
(): { url: string };
@@ -78,10 +76,7 @@ export class DebugSymbolicator implements Integration {
7876
* Symbolicates the stack on the device talking to local dev server.
7977
* Mutates the passed event.
8078
*/
81-
private async _symbolicate(
82-
event: Event,
83-
stack: string | undefined
84-
): Promise<void> {
79+
private async _symbolicate(event: Event, stack: string | undefined): Promise<void> {
8580
try {
8681
// eslint-disable-next-line @typescript-eslint/no-var-requires
8782
const symbolicateStackTrace = require('react-native/Libraries/Core/Devtools/symbolicateStackTrace');
@@ -99,12 +94,10 @@ export class DebugSymbolicator implements Integration {
9994
const stackWithoutInternalCallsites = newStack.filter(
10095
(frame: { file?: string }) =>
10196
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
102-
frame.file && frame.file.match(INTERNAL_CALLSITES_REGEX) === null
97+
frame.file && frame.file.match(INTERNAL_CALLSITES_REGEX) === null,
10398
);
10499

105-
const symbolicatedFrames = await this._convertReactNativeFramesToSentryFrames(
106-
stackWithoutInternalCallsites
107-
);
100+
const symbolicatedFrames = await this._convertReactNativeFramesToSentryFrames(stackWithoutInternalCallsites);
108101
this._replaceFramesInEvent(event, symbolicatedFrames);
109102
} else {
110103
logger.error('The stack is null');
@@ -120,9 +113,7 @@ export class DebugSymbolicator implements Integration {
120113
* Converts ReactNativeFrames to frames in the Sentry format
121114
* @param frames ReactNativeFrame[]
122115
*/
123-
private async _convertReactNativeFramesToSentryFrames(
124-
frames: ReactNativeFrame[]
125-
): Promise<StackFrame[]> {
116+
private async _convertReactNativeFramesToSentryFrames(frames: ReactNativeFrame[]): Promise<StackFrame[]> {
126117
let getDevServer: GetDevServer;
127118
try {
128119
getDevServer = require('react-native/Libraries/Core/Devtools/getDevServer');
@@ -132,44 +123,40 @@ export class DebugSymbolicator implements Integration {
132123
// Below you will find lines marked with :HACK to prevent showing errors in the sentry ui
133124
// But since this is a debug only feature: This is Fine (TM)
134125
return Promise.all(
135-
frames.map(
136-
async (frame: ReactNativeFrame): Promise<StackFrame> => {
137-
let inApp = !!frame.column && !!frame.lineNumber;
138-
inApp =
139-
inApp &&
140-
frame.file !== undefined &&
141-
!frame.file.includes('node_modules') &&
142-
!frame.file.includes('native code');
143-
144-
const newFrame: StackFrame = {
145-
colno: frame.column,
146-
filename: frame.file,
147-
function: frame.methodName,
148-
in_app: inApp,
149-
lineno: inApp ? frame.lineNumber : undefined, // :HACK
150-
platform: inApp ? 'javascript' : 'node', // :HACK
151-
};
152-
153-
// The upstream `[email protected]` delegates parsing of stacks to `stacktrace-parser`, which is buggy and
154-
// leaves a trailing `(address at` in the function name.
155-
// `[email protected]` seems to have custom logic to parse hermes frames specially.
156-
// Anyway, all we do here is throw away the bogus suffix.
157-
if (newFrame.function) {
158-
const addressAtPos = newFrame.function.indexOf('(address at');
159-
if (addressAtPos >= 0) {
160-
newFrame.function = newFrame.function
161-
.substr(0, addressAtPos)
162-
.trim();
163-
}
164-
}
165-
166-
if (inApp) {
167-
await this._addSourceContext(newFrame, getDevServer);
126+
frames.map(async (frame: ReactNativeFrame): Promise<StackFrame> => {
127+
let inApp = !!frame.column && !!frame.lineNumber;
128+
inApp =
129+
inApp &&
130+
frame.file !== undefined &&
131+
!frame.file.includes('node_modules') &&
132+
!frame.file.includes('native code');
133+
134+
const newFrame: StackFrame = {
135+
colno: frame.column,
136+
filename: frame.file,
137+
function: frame.methodName,
138+
in_app: inApp,
139+
lineno: inApp ? frame.lineNumber : undefined, // :HACK
140+
platform: inApp ? 'javascript' : 'node', // :HACK
141+
};
142+
143+
// The upstream `[email protected]` delegates parsing of stacks to `stacktrace-parser`, which is buggy and
144+
// leaves a trailing `(address at` in the function name.
145+
// `[email protected]` seems to have custom logic to parse hermes frames specially.
146+
// Anyway, all we do here is throw away the bogus suffix.
147+
if (newFrame.function) {
148+
const addressAtPos = newFrame.function.indexOf('(address at');
149+
if (addressAtPos >= 0) {
150+
newFrame.function = newFrame.function.substr(0, addressAtPos).trim();
168151
}
152+
}
169153

170-
return newFrame;
154+
if (inApp) {
155+
await this._addSourceContext(newFrame, getDevServer);
171156
}
172-
)
157+
158+
return newFrame;
159+
}),
173160
);
174161
}
175162

@@ -195,23 +182,17 @@ export class DebugSymbolicator implements Integration {
195182
* @param frame StackFrame
196183
* @param getDevServer function from RN to get DevServer URL
197184
*/
198-
private async _addSourceContext(
199-
frame: StackFrame,
200-
getDevServer?: GetDevServer
201-
): Promise<void> {
185+
private async _addSourceContext(frame: StackFrame, getDevServer?: GetDevServer): Promise<void> {
202186
let response;
203187

204188
const segments = frame.filename?.split('/') ?? [];
205189

206190
if (getDevServer) {
207191
for (const idx in segments) {
208192
if (Object.prototype.hasOwnProperty.call(segments, idx)) {
209-
response = await fetch(
210-
`${getDevServer().url}${segments.slice(-idx).join('/')}`,
211-
{
212-
method: 'GET',
213-
}
214-
);
193+
response = await fetch(`${getDevServer().url}${segments.slice(-idx).join('/')}`, {
194+
method: 'GET',
195+
});
215196

216197
if (response.ok) {
217198
break;

0 commit comments

Comments
 (0)