Skip to content

Commit

Permalink
style: eslint no-explicit-any fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jrassa committed Aug 21, 2024
1 parent 6712683 commit ab39954
Show file tree
Hide file tree
Showing 69 changed files with 423 additions and 524 deletions.
10 changes: 9 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@angular-eslint/use-component-view-encapsulation": ["error"],
"@angular-eslint/use-injectable-provided-in": ["error"],
"@angular-eslint/use-lifecycle-interface": ["error"],
"@typescript-eslint/no-explicit-any": ["off"],
"@typescript-eslint/no-explicit-any": ["error"],
"@typescript-eslint/no-unused-vars": [
"error",
{
Expand Down Expand Up @@ -106,6 +106,14 @@
]
}
},
{
"files": [
"*.spec.ts"
],
"rules": {
"@typescript-eslint/no-explicit-any": ["off"]
}
},
{
"files": [
"*.html"
Expand Down
39 changes: 23 additions & 16 deletions src/app/common/abstract-entity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { inject } from '@angular/core';
import { Router } from '@angular/router';

import { Observable, of } from 'rxjs';
import { catchError, map, tap } from 'rxjs/operators';
import { catchError, map } from 'rxjs/operators';

import { ErrorState } from '../core';
import { NULL_PAGING_RESULTS, PagingOptions, PagingResults } from './paging.model';
import { SystemAlertService } from './system-alert/system-alert.service';
import { SystemAlertService } from './system-alert';

export enum ServiceMethod {
create = 'create',
Expand All @@ -18,7 +18,7 @@ export enum ServiceMethod {
}

export abstract class AbstractEntityService<T extends { _id: string }> {
headers: any = { 'Content-Type': 'application/json' };
headers = { 'Content-Type': 'application/json' };

protected readonly router = inject(Router);
protected readonly http = inject(HttpClient);
Expand Down Expand Up @@ -66,11 +66,11 @@ export abstract class AbstractEntityService<T extends { _id: string }> {
.pipe(map((model) => this.mapToType(model)));
}

update(t: T, params: any = null): Observable<T | null> {
update(t: T, params?: object): Observable<T | null> {
return this.http
.post(this.getMethodUrl(ServiceMethod.update, t), t, {
headers: this.headers,
params
params: { ...params },
headers: this.headers
})
.pipe(
map((model) => this.mapToType(model)),
Expand All @@ -87,11 +87,11 @@ export abstract class AbstractEntityService<T extends { _id: string }> {

search(
paging: PagingOptions,
query: Record<string, any> = {},
query: object = {},
search = '',
body: any = null,
params: any = null,
options: any = {},
body?: object,
params?: object,
options: object = {},
urlOverride?: string
): Observable<PagingResults<T>> {
return this.http
Expand All @@ -104,16 +104,23 @@ export abstract class AbstractEntityService<T extends { _id: string }> {
}
)
.pipe(
tap((pagingResult) => {
pagingResult.elements = pagingResult.elements.map((model: any) =>
this.mapToType(model)
);
map((pagingResults) => {
return {
...pagingResults,
elements: pagingResults.elements.map((model) => this.mapToType(model))
} as PagingResults<T>;
}),
catchError((error: unknown) => this.handleError(error, NULL_PAGING_RESULTS))
catchError((error: unknown) =>
this.handleError(error, NULL_PAGING_RESULTS as PagingResults<T>)
)
);
}

updateAction(action: string, t: Pick<T, '_id'>, body: any | null = null): Observable<T | null> {
updateAction(
action: string,
t: Pick<T, '_id'>,
body: object | null = null
): Observable<T | null> {
return this.http
.post(`${this.getMethodUrl(ServiceMethod.update, t)}/${action}`, body, {
headers: this.headers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[cancelText]="data.cancelText ?? 'Cancel'"
[disableOk]="!modalForm.form.valid"
[hideCancel]="data.hideCancel ?? false"
[okText]="data.okText"
[okText]="data.okText ?? 'OK'"
(cancel)="cancel()"
(ok)="ok()"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,23 @@ export type DialogInput = {
required: boolean;
};

export class ConfigurableDialogData {
export type DialogData = {
title: string;
okText: string;
message: string;
okText?: string;
cancelText?: string;
hideCancel?: boolean;
message: string;
};

export type PromptDialogData = DialogData & {
inputLabel: string;
};

export type ConfigurableDialogData = DialogData & {
inputs?: DialogInput[];
}
};

export type ConfigurableDialogReturn = DialogReturn<any>;
export type ConfigurableDialogReturn = DialogReturn<Record<string, string>>;

@Component({
standalone: true,
Expand All @@ -34,14 +41,14 @@ export class ConfigurableDialogComponent {
dialogRef: DialogRef<ConfigurableDialogReturn> = inject(DialogRef);
data: ConfigurableDialogData = inject(DIALOG_DATA);

formData: Record<string, unknown> = {};
formData: Record<string, string> = {};

cancel() {
this.dialogRef.close({ action: DialogAction.CANCEL });
}

ok() {
const event: DialogReturn<any> = { action: DialogAction.OK };
const event: ConfigurableDialogReturn = { action: DialogAction.OK };
if (this.data.inputs) {
event.data = this.formData;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/common/dialog/dialog.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export enum DialogAction {
CANCEL
}

export class DialogReturn<T> {
export class DialogReturn<T = void> {
action: DialogAction;
data?: T;
}
Expand Down
8 changes: 6 additions & 2 deletions src/app/common/dialog/dialog.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { Injectable, inject } from '@angular/core';

import {
ConfigurableDialogComponent,
ConfigurableDialogData
ConfigurableDialogData,
ConfigurableDialogReturn
} from './configurable-dialog/configurable-dialog.component';
import { DialogReturn } from './dialog.model';

Expand Down Expand Up @@ -72,7 +73,10 @@ export class DialogService {
/**
* The show method will display a modal that can include a message and a form
*/
show<R = unknown>(contentConfig: ConfigurableDialogData, modalOptions: DialogConfig = {}) {
show<R = ConfigurableDialogReturn>(
contentConfig: ConfigurableDialogData,
modalOptions: DialogConfig = {}
) {
const config = {
disableClose: true,
data: contentConfig,
Expand Down
2 changes: 1 addition & 1 deletion src/app/common/notification/notification.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
changeDetection: ChangeDetectionStrategy.OnPush
})
export class NotificationComponent {
readonly actionTemplate = contentChild<TemplateRef<any>>('notificationActions');
readonly actionTemplate = contentChild<TemplateRef<unknown>>('notificationActions');

readonly notificationType = input<'info' | 'success' | 'warning' | 'danger'>('info');
readonly message = input('');
Expand Down
9 changes: 7 additions & 2 deletions src/app/common/paging.model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SortDir } from './sorting.model';

export interface PagingResults<T = any> {
export interface PagingResults<T = unknown> {
pageNumber: number;
pageSize: number;
totalPages: number;
Expand Down Expand Up @@ -54,7 +54,12 @@ export class PagingOptions {
this.pageNumber = pageNumber;
}

toObj(): any {
toObj(): {
page: PagingOptions['pageNumber'];
size: PagingOptions['pageSize'];
sort?: PagingOptions['sortField'];
dir?: PagingOptions['sortDir'];
} {
return {
page: this.pageNumber,
size: this.pageSize,
Expand Down
2 changes: 1 addition & 1 deletion src/app/common/pipes/join.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Pipe, PipeTransform } from '@angular/core';
standalone: true
})
export class JoinPipe implements PipeTransform {
transform(input: any, separator: string): any {
transform(input: string | Array<string>, separator: string): string {
if (!Array.isArray(input)) {
return input;
}
Expand Down
10 changes: 2 additions & 8 deletions src/app/common/pipes/keys.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { Pipe, PipeTransform } from '@angular/core';

import forOwn from 'lodash/forOwn';

@Pipe({
name: 'keys',
standalone: true
})
export class KeysPipe implements PipeTransform {
transform(obj: any): any {
const values: any[] = [];
forOwn(obj, (val: any, key: any) => {
values.push({ key, value: val });
});
return values;
transform<V>(obj: object): Array<{ key: string; value: V }> {
return Object.entries(obj).map(([key, value]) => ({ key, value }));
}
}
23 changes: 12 additions & 11 deletions src/app/common/pipes/sort-object-keys.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@ import _isObject from 'lodash/isObject';
})
export class SortObjectKeysPipe implements PipeTransform {
// Derived from http://stackoverflow.com/a/1359808 and http://stackoverflow.com/a/23124958
transform(obj: any): any {
if (null == obj || !_isObject(obj)) {
transform(obj: unknown): unknown {
if (!obj || !_isObject(obj)) {
return obj;
}

// Maintain the order of arrays, but sort keys of the array elements
if (Array.isArray(obj)) {
return obj.map((o: any) => this.transform(o));
return obj.map((o) => this.transform(o)) as Array<Record<string, unknown>>;
}

const sorted: any = {};
const keys: string[] = Object.keys(obj).sort();

for (const key of keys) {
sorted[key] = this.transform((obj as any)[key]);
}

return sorted;
return Object.keys(obj)
.sort()
.reduce(
(newObj, key) => {
newObj[key] = this.transform((obj as Record<string, unknown>)[key]);
return newObj;
},
{} as Record<string, unknown>
);
}
}
4 changes: 2 additions & 2 deletions src/app/common/string-utils.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ export class StringUtils {
/**
* Returns true if input is a string and it is not empty.
*/
public static isNonEmptyString(s: any): boolean {
public static isNonEmptyString(s: unknown): boolean {
return isString(s) && s.trim().length > 0;
}

/**
* Returns true if input is not a string or if input is empty
*/
public static isInvalid(s: any): boolean {
public static isInvalid(s: unknown): boolean {
return !StringUtils.isNonEmptyString(s);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { AsyAbstractColumnComponent } from '../columns/asy-abstract-column.compo

@Directive({ selector: '[actions-menu-tmp]', standalone: true })
export class ActionsMenuTemplateDirective {
constructor(public template: TemplateRef<any>) {}
constructor(public template: TemplateRef<unknown>) {}
}

@Component({
Expand Down
24 changes: 16 additions & 8 deletions src/app/common/table/asy-table-data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { SessionStorageService } from '../storage/session-storage.service';
export type LoadPageFunction<T> = (options: {
pagingOptions: PagingOptions;
search: string;
filter: any;
filter: object;
}) => Observable<PagingResults<T>>;

type State = {
Expand All @@ -22,7 +22,7 @@ type State = {

export class AsyTableDataSource<T> extends DataSource<T> {
readonly sortEvent$: BehaviorSubject<SortChange>;
readonly filterEvent$: BehaviorSubject<any>;
readonly filterEvent$: BehaviorSubject<object>;
readonly searchEvent$: BehaviorSubject<string>;
readonly pageChangeEvent$: BehaviorSubject<PageChange>;
readonly pagingResults$: BehaviorSubject<PagingResults<T>>;
Expand All @@ -38,7 +38,7 @@ export class AsyTableDataSource<T> extends DataSource<T> {
public storageKey?: string,
initialSort: SortChange = {} as SortChange,
initialSearch = '',
initialFilter: any = {},
initialFilter: object = {},
initialPageSize = 20,
private debounceTimeMs = 100
) {
Expand All @@ -53,7 +53,9 @@ export class AsyTableDataSource<T> extends DataSource<T> {
pageNumber: 0,
pageSize: state.pageSize ?? initialPageSize
});
this.pagingResults$ = new BehaviorSubject<PagingResults<T>>(NULL_PAGING_RESULTS);
this.pagingResults$ = new BehaviorSubject<PagingResults<T>>(
NULL_PAGING_RESULTS as PagingResults<T>
);

const param$ = combineLatest([this.searchEvent$, this.filterEvent$]);

Expand Down Expand Up @@ -84,14 +86,20 @@ export class AsyTableDataSource<T> extends DataSource<T> {
});
}),
switchMap(([search, filter]) =>
pagingOptions$.pipe(map((pagingOptions) => [pagingOptions, search, filter]))
pagingOptions$.pipe(
map((pagingOptions) => ({
pagingOptions,
search,
filter
}))
)
),
tap(() => {
this.loading$.next(true);
this.pagingResults$.next(NULL_PAGING_RESULTS);
this.pagingResults$.next(NULL_PAGING_RESULTS as PagingResults<T>);
}),
debounceTime(this.debounceTimeMs),
switchMap(([pagingOptions, search, filter]) =>
switchMap(({ pagingOptions, search, filter }) =>
loadPageFunc({
pagingOptions,
search,
Expand All @@ -116,7 +124,7 @@ export class AsyTableDataSource<T> extends DataSource<T> {
this.saveState();
}

filter(filter: any) {
filter(filter: object) {
this.filterEvent$.next(filter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AsyAbstractValueColumnComponent } from '../asy-abstract-value-column.co

@Directive({ selector: '[lc-item-tmp]', standalone: true })
export class ItemTemplateDirective {
constructor(public template: TemplateRef<any>) {}
constructor(public template: TemplateRef<unknown>) {}
}

@Component({
Expand Down
Loading

0 comments on commit ab39954

Please sign in to comment.