Skip to content

Commit

Permalink
NAS-132933 / 25.04 / Enable no-implicit-any-catch (#11152)
Browse files Browse the repository at this point in the history
  • Loading branch information
undsoft authored Dec 9, 2024
1 parent 0df2882 commit 04a97f6
Show file tree
Hide file tree
Showing 210 changed files with 405 additions and 541 deletions.
14 changes: 4 additions & 10 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import eslint from "@eslint/js";
import tsEslint from "typescript-eslint";
import angular from "angular-eslint";
import stylistic from "@stylistic/eslint-plugin";
import {fixupConfigRules, fixupPluginRules} from "@eslint/compat";
import { FlatCompat } from "@eslint/eslintrc";
import {dirname} from "node:path";
import {fileURLToPath} from "node:url";
import { fixupPluginRules } from "@eslint/compat";
import rxjsAngular from "eslint-plugin-rxjs-angular";
import angularFileNaming from "eslint-plugin-angular-file-naming";
import importPlugin from "eslint-plugin-import";
Expand All @@ -17,11 +14,7 @@ import { eslintSpec } from "./eslint/eslint-spec.mjs";
import { fixLaterRules } from "./eslint/eslint-ts-rules-fix-later.mjs";
import { ruleOverrides } from "./eslint/eslint-ts-rules-overrides.mjs";
import { extraRules } from "./eslint/eslint-ts-rules-extra.mjs";

const __dirname = dirname(fileURLToPath(import.meta.url));
const compat = new FlatCompat({
baseDirectory: __dirname,
});
import rxjs from "@smarttools/eslint-plugin-rxjs";

export default tsEslint.config(
{
Expand All @@ -48,6 +41,7 @@ export default tsEslint.config(
},
plugins: {
unicorn,
rxjs,
"rxjs-angular": fixupPluginRules(rxjsAngular),
"angular-file-naming": fixupPluginRules(angularFileNaming),
"unused-imports": unusedImports,
Expand All @@ -68,7 +62,7 @@ export default tsEslint.config(
}),
importPlugin.flatConfigs.recommended,
sonarjs.configs.recommended,
...fixupConfigRules(compat.extends('plugin:rxjs/recommended')),
rxjs.configs.recommended,
],
rules: {
...ruleOverrides,
Expand Down
6 changes: 3 additions & 3 deletions eslint/eslint-ts-rules-extra.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import airbnbVariables from "eslint-config-airbnb-base/rules/variables";
*/
export const extraRules = {
// RxJS
"rxjs/no-unsafe-takeuntil": ["error", {
"@smarttools/rxjs/no-unsafe-takeuntil": ["error", {
"alias": ["untilDestroyed"]
}],
"rxjs-angular/prefer-takeuntil": ["error", {
Expand All @@ -16,14 +16,14 @@ export const extraRules = {
"checkDecorators": ["Component"],
"checkDestroy": false
}],
"rxjs/finnish": ["error", {
"@smarttools/rxjs/finnish": ["error", {
"parameters": true,
"properties": false, // TODO: Should be true, hard to implement now.
"variables": true,
"functions": false,
"methods": false,
}],
"rxjs/prefer-observer": ["error"],
"@smarttools/rxjs/prefer-observer": ["error"],

// Angular
"@angular-eslint/use-lifecycle-interface": ["error"],
Expand Down
3 changes: 1 addition & 2 deletions eslint/eslint-ts-rules-fix-later.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ export const fixLaterRules = {
"@typescript-eslint/no-dynamic-delete": ["off"],
"@typescript-eslint/class-literal-property-style": ["off"],
"no-prototype-builtins": ["off"],
"rxjs/no-implicit-any-catch": ["off"],
"rxjs/no-nested-subscribe": ["off"],
"@smarttools/rxjs/no-nested-subscribe": ["off"],

"sonarjs/prefer-nullish-coalescing": ["off"],
"sonarjs/deprecation": ["off"],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"@sentry/angular": "5.30.0",
"@sentry/utils": "~7.42.0",
"@shopify/eslint-plugin": "~46.0.0",
"@smarttools/eslint-plugin-rxjs": "~1.0.7",
"@stylistic/eslint-plugin": "~2.9.0",
"@types/cheerio": "~0.22.35",
"@types/d3": "~7.4.3",
Expand Down Expand Up @@ -147,7 +148,6 @@
"eslint-plugin-angular-test-ids": "~1.0.6",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest": "~28.8.3",
"eslint-plugin-rxjs": "^5.0.3",
"eslint-plugin-rxjs-angular": "^2.0.1",
"eslint-plugin-sonarjs": "~2.0.3",
"eslint-plugin-unicorn": "^56.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/guards/translations-loaded.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class TranslationsLoadedGuard {
return waitForTranslations$.pipe(
timeout(this.maxLanguageLoadingTime),
map(() => true),
catchError((error) => {
catchError((error: unknown) => {
console.error('Error loading translations: ', error);
return of(true);
}),
Expand Down
3 changes: 3 additions & 0 deletions src/app/helpers/api.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export function isErrorResponse(something: unknown): something is ErrorResponse
&& Boolean(something.error);
}

/**
* Extract api error if it's available. Otherwise returns undefined.
*/
export function extractApiError(someError: unknown): ApiError | undefined {
if (isErrorResponse(someError)) {
return someError.error.data;
Expand Down
5 changes: 2 additions & 3 deletions src/app/helpers/operators/to-loading-state.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { of, OperatorFunction, pipe } from 'rxjs';
import {
catchError, map, startWith,
} from 'rxjs/operators';
import { ApiError } from 'app/interfaces/api-error.interface';

export interface LoadingState<T> {
isLoading: boolean;
value?: T;
error?: ApiError | Error;
error?: unknown;
}

/**
Expand All @@ -25,7 +24,7 @@ export interface LoadingState<T> {
export function toLoadingState<T>(): OperatorFunction<T, LoadingState<T>> {
return pipe(
map((value) => ({ isLoading: false, value })),
catchError((error: ApiError | Error) => of({ isLoading: false, error })),
catchError((error: unknown) => of({ isLoading: false, error })),
startWith({ isLoading: true }),
);
}
10 changes: 5 additions & 5 deletions src/app/modules/alerts/store/alert.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class AlertEffects {
switchMap(() => {
return this.api.call('alert.list').pipe(
map((alerts) => alertsLoaded({ alerts })),
catchError((error) => {
catchError((error: unknown) => {
console.error(error);
// TODO: See if it would make sense to parse middleware error.
return of(alertsNotLoaded({
Expand Down Expand Up @@ -81,7 +81,7 @@ export class AlertEffects {
ofType(dismissAlertPressed),
mergeMap(({ id }) => {
return this.api.call('alert.dismiss', [id]).pipe(
catchError((error) => {
catchError((error: unknown) => {
this.errorHandler.showErrorModal(error);
this.store$.dispatch(alertChanged({ alert: { id, dismissed: false } as Alert }));
return of(EMPTY);
Expand All @@ -94,7 +94,7 @@ export class AlertEffects {
ofType(reopenAlertPressed),
mergeMap(({ id }) => {
return this.api.call('alert.restore', [id]).pipe(
catchError((error) => {
catchError((error: unknown) => {
this.errorHandler.showErrorModal(error);
this.store$.dispatch(alertChanged({ alert: { id, dismissed: true } as Alert }));
return of(EMPTY);
Expand All @@ -109,7 +109,7 @@ export class AlertEffects {
mergeMap(([, [unreadAlerts]]) => {
const requests = unreadAlerts.map((alert) => this.api.call('alert.dismiss', [alert.id]));
return forkJoin(requests).pipe(
catchError((error) => {
catchError((error: unknown) => {
this.errorHandler.showErrorModal(error);
this.store$.dispatch(alertsDismissedChanged({ dismissed: false }));
return of(EMPTY);
Expand All @@ -125,7 +125,7 @@ export class AlertEffects {
mergeMap(([, [dismissedAlerts]]) => {
const requests = dismissedAlerts.map((alert) => this.api.call('alert.restore', [alert.id]));
return forkJoin(requests).pipe(
catchError((error) => {
catchError((error: unknown) => {
this.errorHandler.showErrorModal(error);
this.store$.dispatch(alertsDismissedChanged({ dismissed: true }));
return of(EMPTY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class ExportButtonComponent<T, M extends ApiJobMethod> {
return this.api.call('core.download', [downloadMethod, [customArguments], url]);
}),
switchMap(([, url]) => this.download.downloadUrl(url, `${this.filename()}.${this.fileType()}`, this.fileMimeType())),
catchError((error) => {
catchError((error: unknown) => {
this.isLoading = false;
this.cdr.markForCheck();
this.dialogService.error(this.errorHandler.parseError(error));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { HttpErrorResponse } from '@angular/common/http';
import {
ChangeDetectionStrategy, Component, ElementRef, ViewChild,
} from '@angular/core';
Expand Down Expand Up @@ -71,15 +70,15 @@ export class ErrorDialogComponent {
this.dialogRef.close();
}
},
error: (err: HttpErrorResponse) => {
error: (err: unknown) => {
if (this.dialogRef) {
this.dialogRef.close();
}
this.dialogService.error(this.errorHandler.parseHttpError(err));
this.dialogService.error(this.errorHandler.parseError(err));
},
});
},
error: (err) => {
error: (err: unknown) => {
this.dialogService.error(this.errorHandler.parseError(err));
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { HttpErrorResponse } from '@angular/common/http';
import {
ChangeDetectionStrategy, Component, ElementRef, input, ViewChild,
} from '@angular/core';
Expand Down Expand Up @@ -77,8 +76,8 @@ export class ErrorTemplateComponent {
next: (file) => {
this.download.downloadBlob(file, `${this.logs().id}.log`);
},
error: (error: HttpErrorResponse) => {
this.dialogService.error(this.errorHandler.parseHttpError(error));
error: (error: unknown) => {
this.dialogService.error(this.errorHandler.parseError(error));
},
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { HttpErrorResponse } from '@angular/common/http';
import { ChangeDetectionStrategy, Component, Inject } from '@angular/core';
import { MatButton } from '@angular/material/button';
import {
Expand Down Expand Up @@ -44,7 +43,7 @@ export class ShowLogsDialogComponent {
downloadLogs(): void {
this.api.call('core.job_download_logs', [this.job.id, `${this.job.id}.log`]).pipe(
switchMap((url) => this.download.downloadUrl(url, `${this.job.id}.log`, 'text/plain')),
catchError((error: HttpErrorResponse | Job) => {
catchError((error: unknown) => {
this.dialogService.error(this.errorHandler.parseError(error));
return EMPTY;
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class FileTicketLicensedComponent {
untilDestroyed(this),
).subscribe({
next: (createdTicket) => this.onSuccess(createdTicket.url),
error: (error) => this.formErrorHandler.handleValidationErrors(error, this.form),
error: (error: unknown) => this.formErrorHandler.handleValidationErrors(error, this.form),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class FileTicketComponent {
untilDestroyed(this),
).subscribe({
next: (createdTicket) => this.onSuccess(createdTicket.url),
error: (error) => this.formErrorHandler.handleValidationErrors(error, this.form),
error: (error: unknown) => this.formErrorHandler.handleValidationErrors(error, this.form),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class CreateDatasetDialogComponent implements OnInit {
this.isLoading$.next(false);
this.dialogRef.close(dataset);
},
error: (error) => {
error: (error: unknown) => {
this.isLoading$.next(false);
this.dialog.error(this.errorHandler.parseError(error));
},
Expand All @@ -116,7 +116,7 @@ export class CreateDatasetDialogComponent implements OnInit {
this.cdr.markForCheck();
this.addNameValidators();
},
error: (error) => {
error: (error: unknown) => {
this.isLoading$.next(false);
this.dialog.error(this.errorHandler.parseError(error));
this.dialogRef.close(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
AbstractControl, FormControl, ValidationErrors, ValidatorFn, Validators,
} from '@angular/forms';
import { TranslateService } from '@ngx-translate/core';
import isCidr from 'is-cidr';
import * as isCidr from 'is-cidr';

@Injectable({
providedIn: 'root',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function forbiddenAsyncValues(
): AsyncValidatorFn {
const request$ = arrayOfValues$.pipe(
shareReplay({ refCount: false, bufferSize: 1 }),
catchError((error) => {
catchError((error: unknown) => {
console.error(error);
return of(null);
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class ImageValidatorService {
take(screenshots.length),
concatMap((file: File): Observable<ValidatedFile> => {
return this.validateImage(file, sizeLimitBytes).pipe(
catchError((error: ValidatedFile) => of(error)),
catchError((error: unknown) => of(error as ValidatedFile)),
);
}),
toArray(),
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/forms/ix-forms/validators/ip-validation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FormControl, ValidatorFn } from '@angular/forms';
import ipRegex from 'ip-regex';
import isCidr from 'is-cidr';
import * as isCidr from 'is-cidr';
import { indexOf } from 'lodash-es';

// Accepts ipv4 or ipv6 addresses with no CIDR (ie, /24)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
} from 'rxjs';
import { EmptyType } from 'app/enums/empty-type.enum';
import { ApiCallParams, ApiCallResponseType, QueryMethods } from 'app/interfaces/api/api-call-directory.interface';
import { ApiError } from 'app/interfaces/api-error.interface';
import { QueryFilters } from 'app/interfaces/query-api.interface';
import { PaginationServerSide } from 'app/modules/ix-table/classes/api-data-provider/pagination-server-side.class';
import { SortingServerSide } from 'app/modules/ix-table/classes/api-data-provider/sorting-server-side.class';
Expand Down Expand Up @@ -46,7 +45,7 @@ export class ApiDataProvider<T extends QueryMethods> extends BaseDataProvider<Ap
this.currentPage$.next(this.rows);
this.emptyType$.next(rows.length ? EmptyType.NoSearchResults : EmptyType.NoPageData);
},
error: (error: ApiError) => {
error: (error: unknown) => {
console.error(this.method, error);
this.totalRows = 0;
this.rows = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class IxCellStateButtonComponent<T> extends ColumnComponent<T> implements
canMinimize: true,
},
).afterClosed().pipe(
catchError((error) => {
catchError((error: unknown) => {
this.errorHandler.showErrorModal(error);
return EMPTY;
}),
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/jobs/store/job.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class JobEffects {
map(([notCompletedJobs, recentlyCompletedJobs]) => {
return jobsLoaded({ jobs: [...notCompletedJobs, ...recentlyCompletedJobs] });
}),
catchError((error) => {
catchError((error: unknown) => {
console.error(error);
// TODO: See if it would make sense to parse middleware error.
return of(jobsNotLoaded({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class AppDetailsSimilarComponent implements OnChanges {
this.isLoading.set(false);
this.similarApps.set(apps.slice(0, this.maxSimilarApps));
},
error: (error) => {
error: (error: unknown) => {
this.isLoading.set(false);
console.error(error);
this.loadingError.set(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { RequiresRolesDirective } from 'app/directives/requires-roles/requires-r
import { DynamicFormSchemaType } from 'app/enums/dynamic-form-schema-type.enum';
import { Role } from 'app/enums/role.enum';
import { helptextApps } from 'app/helptext/apps/apps';
import { ApiError } from 'app/interfaces/api-error.interface';
import { AppDetailsRouteParams } from 'app/interfaces/app-details-route-params.interface';
import {
ChartFormValue,
Expand Down Expand Up @@ -202,7 +201,7 @@ export class AppWizardComponent implements OnInit, OnDestroy {
});
this.afterAppLoaded();
},
error: (error: ApiError) => this.afterAppLoadError(error),
error: (error: unknown) => this.afterAppLoadError(error),
});
}

Expand Down Expand Up @@ -334,7 +333,7 @@ export class AppWizardComponent implements OnInit, OnDestroy {
this.setAppForEdit(releases[0]);
this.afterAppLoaded();
},
error: (error: ApiError) => this.afterAppLoadError(error),
error: (error: unknown) => this.afterAppLoadError(error),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class CustomAppFormComponent implements OnInit {
this.router.navigate(['/apps', 'installed', this.data.metadata.train, this.data.name]);
}
},
error: (error) => {
error: (error: unknown) => {
this.isLoading.set(false);
this.errorHandler.showErrorModal(error);
},
Expand Down
Loading

0 comments on commit 04a97f6

Please sign in to comment.