Skip to content

Commit 970cf31

Browse files
authored
ref(eslint): Set no-unsafe-assignment & no-unsage-argument to error (#919)
1 parent d1e8e55 commit 970cf31

File tree

5 files changed

+41
-20
lines changed

5 files changed

+41
-20
lines changed

.eslintrc.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,10 @@ module.exports = {
5959
'@typescript-eslint/no-unsafe-call': 'error',
6060
'@typescript-eslint/restrict-template-expressions': 'error',
6161
'@typescript-eslint/no-unsafe-member-access': 'error',
62-
'@typescript-eslint/no-unsafe-assignment': 'warn',
63-
'@typescript-eslint/no-unsafe-argument': 'warn',
62+
'@typescript-eslint/no-unsafe-assignment': 'error',
63+
'@typescript-eslint/no-unsafe-argument': 'error',
6464
'@typescript-eslint/no-unsafe-return': 'error',
6565
'@typescript-eslint/no-var-requires': 'error',
66-
// '@typescript-eslint/restrict-template-expressions': 'warn',
6766
'@typescript-eslint/no-unused-vars': [
6867
'error',
6968
{ argsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' },

e2e-tests/utils/index.ts

+25-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,31 @@ export const log = {
3030
info: (message: string) => {
3131
dim(`[INFO] ${message}`);
3232
},
33-
error: (message: string) => {
34-
red(`[ERROR] ${message}`);
33+
error: (message: unknown) => {
34+
function formatMessage(message: unknown, depth: number): string {
35+
if (depth > 3) {
36+
return '...';
37+
}
38+
39+
if (message instanceof Error) {
40+
return JSON.stringify(
41+
{
42+
name: message.name,
43+
message: message.message,
44+
stack: message.stack,
45+
...(message.cause
46+
? {
47+
cause: formatMessage(message.cause, depth + 1),
48+
}
49+
: {}),
50+
},
51+
null,
52+
2,
53+
);
54+
}
55+
return String(message);
56+
}
57+
red(`[ERROR] ${formatMessage(message, 0)}`);
3558
},
3659
};
3760

lib/Helper/File.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ const IGNORE_PATTERN = ['node_modules/**', 'ios/Pods/**', '**/Pods/**'];
55

66
export function patchMatchingFile(
77
globPattern: string,
8-
func: (content: string, match: string, ...args: unknown[]) => void,
8+
func: (
9+
content: string,
10+
match: string,
11+
...args: unknown[]
12+
) => Promise<string | void>,
913
...args: unknown[]
1014
): Promise<void> {
1115
const matches = glob.sync(globPattern, {
@@ -19,11 +23,7 @@ export function patchMatchingFile(
1923
rv = rv
2024
.then(() => func(contents, match, ...args))
2125
.then((newContents) => {
22-
if (
23-
newContents !== null &&
24-
newContents !== undefined &&
25-
contents !== newContents
26-
) {
26+
if (newContents != null && contents !== newContents) {
2727
fs.writeFileSync(match, newContents);
2828
}
2929
});

lib/Steps/Integrations/Cordova.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import xcode from 'xcode';
77
import type { Args } from '../../Constants';
88
import { exists, matchesContent, patchMatchingFile } from '../../Helper/File';
99
import { green } from '../../Helper/Logging';
10-
import { SentryCli } from '../../Helper/SentryCli';
10+
import { SentryCli, SentryCliProps } from '../../Helper/SentryCli';
1111
import { BaseIntegration } from './BaseIntegration';
1212

1313
export class Cordova extends BaseIntegration {
@@ -31,7 +31,7 @@ export class Cordova extends BaseIntegration {
3131

3232
await patchMatchingFile(
3333
`${this._folderPrefix}/ios/*.xcodeproj/project.pbxproj`,
34-
this._patchXcodeProj.bind(this),
34+
(contents, filename) => this._patchXcodeProj(contents, filename),
3535
);
3636

3737
await this._addSentryProperties(sentryCliProperties);
@@ -41,9 +41,8 @@ export class Cordova extends BaseIntegration {
4141
}
4242

4343
public async uninstall(_answers: Answers): Promise<Answers> {
44-
await patchMatchingFile(
45-
'**/*.xcodeproj/project.pbxproj',
46-
this._unpatchXcodeProj.bind(this),
44+
await patchMatchingFile('**/*.xcodeproj/project.pbxproj', (_, filename) =>
45+
this._unpatchXcodeProj(filename),
4746
);
4847

4948
return {};
@@ -135,7 +134,7 @@ export class Cordova extends BaseIntegration {
135134
private _patchXcodeProj(
136135
contents: string,
137136
filename: string,
138-
): Promise<void | string> {
137+
): Promise<string | void> {
139138
const proj = xcode.project(filename);
140139
return new Promise((resolve, reject) => {
141140
proj.parse((err: any) => {
@@ -282,7 +281,7 @@ export class Cordova extends BaseIntegration {
282281
);
283282
}
284283

285-
private _addSentryProperties(properties: any): Promise<void> {
284+
private _addSentryProperties(properties: SentryCliProps): Promise<void> {
286285
let rv = Promise.resolve();
287286
const fn = path.join('sentry.properties');
288287
if (exists(fn)) {

lib/Steps/Integrations/MobileProject.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export abstract class MobileProject extends BaseIntegration {
3030
const isPlatformSet =
3131
this._argv.platform &&
3232
Array.isArray(this._argv.platform) &&
33-
this._argv.platform.length;
33+
!!this._argv.platform.length;
3434

3535
this._platforms = isPlatformSet
3636
? this._argv.platform
@@ -52,7 +52,7 @@ export abstract class MobileProject extends BaseIntegration {
5252
return { shouldConfigurePlatforms };
5353
}
5454

55-
protected _platformSelector(): Promise<Answers> {
55+
protected _platformSelector(): Promise<Answers & { platform: Platform[] }> {
5656
if (this._argv.quiet) {
5757
throw new Error('You need to choose a platform');
5858
}

0 commit comments

Comments
 (0)