From 4becbfa80c379a925b16838703ecd3f667c0e4fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Tue, 5 Oct 2021 22:22:15 +0300 Subject: [PATCH] Eslint --- .eslintrc.json | 64 ++++++++++++++----- src/lib/error/server-error-interceptor.ts | 8 +-- src/lib/filtering/filter-utils.ts | 14 ++-- src/lib/listing/services/entities.service.ts | 15 +++-- .../confirmation-dialog.component.ts | 12 ++-- src/lib/services/error-message.service.ts | 4 +- src/lib/services/generic.service.ts | 22 ++++--- src/lib/utils/custom-route-reuse.strategy.ts | 10 ++- 8 files changed, 93 insertions(+), 56 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index ab8195e..c4d3222 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,9 +1,15 @@ { - "extends": ["../../.eslintrc.json"], - "ignorePatterns": ["!**/*"], + "extends": [ + "../../.eslintrc.json" + ], + "ignorePatterns": [ + "!**/*" + ], "overrides": [ { - "files": ["*.ts"], + "files": [ + "*.ts" + ], "extends": [ "plugin:@nrwl/nx/angular", "plugin:@angular-eslint/template/process-inline-templates", @@ -14,7 +20,9 @@ "plugin:@angular-eslint/recommended--extra" ], "parserOptions": { - "project": ["libs/common-ui/tsconfig.*?.json"] + "project": [ + "libs/common-ui/tsconfig.*?.json" + ] }, "rules": { "@angular-eslint/directive-selector": [ @@ -47,20 +55,33 @@ "error", { "selector": "memberLike", - "modifiers": ["private"], - "format": ["camelCase"], + "modifiers": [ + "private" + ], + "format": [ + "camelCase" + ], "leadingUnderscore": "require" }, { "selector": "memberLike", - "modifiers": ["protected"], - "format": ["camelCase"], + "modifiers": [ + "protected" + ], + "format": [ + "camelCase" + ], "leadingUnderscore": "require" }, { "selector": "memberLike", - "modifiers": ["private"], - "format": ["UPPER_CASE", "camelCase"], + "modifiers": [ + "private" + ], + "format": [ + "UPPER_CASE", + "camelCase" + ], "leadingUnderscore": "require" } ], @@ -68,14 +89,27 @@ "no-underscore-dangle": "off", "no-param-reassign": "error", "consistent-return": "off", - "class-methods-use-this": "off" + "class-methods-use-this": "off", + "@typescript-eslint/no-unsafe-call": "off", + "@typescript-eslint/no-unsafe-member-access": "off", + "@typescript-eslint/restrict-template-expressions": "off" }, - "plugins": ["@angular-eslint/eslint-plugin", "@typescript-eslint"] + "plugins": [ + "@angular-eslint/eslint-plugin", + "@typescript-eslint" + ] }, { - "files": ["*.html"], - "extends": ["plugin:@nrwl/nx/angular-template", "plugin:@angular-eslint/template/recommended"], - "plugins": ["prettier"], + "files": [ + "*.html" + ], + "extends": [ + "plugin:@nrwl/nx/angular-template", + "plugin:@angular-eslint/template/recommended" + ], + "plugins": [ + "prettier" + ], "rules": {} } ] diff --git a/src/lib/error/server-error-interceptor.ts b/src/lib/error/server-error-interceptor.ts index 2124e5f..32b55e0 100644 --- a/src/lib/error/server-error-interceptor.ts +++ b/src/lib/error/server-error-interceptor.ts @@ -26,8 +26,8 @@ function backoffOnServerError(maxRetries = 3): MonoTypeOperatorFunction, next: HttpHandler): Observable> { @@ -46,7 +46,7 @@ export class ServerErrorInterceptor implements HttpInterceptor { } return throwError(error); }), - backoffOnServerError(this._maxRetries || 3) + backoffOnServerError(this._maxRetries || 3), ); } } diff --git a/src/lib/filtering/filter-utils.ts b/src/lib/filtering/filter-utils.ts index f6e893a..cf05f1e 100644 --- a/src/lib/filtering/filter-utils.ts +++ b/src/lib/filtering/filter-utils.ts @@ -1,8 +1,8 @@ /* eslint-disable no-param-reassign */ -import { INestedFilter } from "./models/nested-filter.model"; -import { IFilterGroup } from "./models/filter-group.model"; -import { IFilter } from "./models/filter.model"; -import { NestedFilter } from "./models/nested-filter"; +import { INestedFilter } from './models/nested-filter.model'; +import { IFilterGroup } from './models/filter-group.model'; +import { IFilter } from './models/filter.model'; +import { NestedFilter } from './models/nested-filter'; function copySettings(oldFilters: INestedFilter[], newFilters: INestedFilter[]) { if (!oldFilters || !newFilters) { @@ -50,7 +50,7 @@ export function checkFilter( validate?: (...args: unknown[]) => boolean, // eslint-disable-next-line @typescript-eslint/no-explicit-any validateArgs: any = [], - matchAll = false + matchAll = false, ): boolean { const hasChecked = filters.find(f => f.checked); @@ -72,8 +72,8 @@ export function checkFilter( return filterMatched; } -// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types -export const keyChecker = (key: string) => (entity: Record, filter: INestedFilter) => entity[key] === filter.id; +export const keyChecker = (key: string) => (entity: Record, filter: INestedFilter) => + entity[key] === filter.id; export function getFilteredEntities(entities: T[], filters: IFilterGroup[]): T[] { const filteredEntities: T[] = []; diff --git a/src/lib/listing/services/entities.service.ts b/src/lib/listing/services/entities.service.ts index 262c719..6bab44f 100644 --- a/src/lib/listing/services/entities.service.ts +++ b/src/lib/listing/services/entities.service.ts @@ -39,7 +39,10 @@ export class EntitiesService extends GenericService< private _displayed: E[] = []; private readonly _selected$ = new BehaviorSubject<(string | number)[]>([]); - constructor(protected readonly _injector: Injector, @Optional() @Inject(ENTITY_PATH) protected readonly _defaultModelPath = '') { + constructor( + protected readonly _injector: Injector, + @Optional() @Inject(ENTITY_PATH) protected readonly _defaultModelPath = '', + ) { super(_injector, _defaultModelPath); this.all$ = this._all$.asObservable(); this.allLength$ = this._all$.pipe(getLength); @@ -75,35 +78,35 @@ export class EntitiesService extends GenericService< map(entities => this._searchService.searchIn(entities)), tap(displayed => { this._displayed = displayed; - }) + }), ); } private get _areAllSelected$(): Observable { return combineLatest([this.displayedLength$, this.selectedLength$]).pipe( map(([displayedLength, selectedLength]) => !!displayedLength && displayedLength === selectedLength), - distinctUntilChanged() + distinctUntilChanged(), ); } private get _areSomeSelected$(): Observable { return this.selectedLength$.pipe( map(length => !!length), - distinctUntilChanged() + distinctUntilChanged(), ); } private get _notAllSelected$(): Observable { return combineLatest([this.areAllSelected$, this.areSomeSelected$]).pipe( map(([allAreSelected, someAreSelected]) => !allAreSelected && someAreSelected), - distinctUntilChanged() + distinctUntilChanged(), ); } private get _noData$(): Observable { return this.allLength$.pipe( map(length => length === 0), - distinctUntilChanged() + distinctUntilChanged(), ); } diff --git a/src/lib/misc/confirmation-dialog/confirmation-dialog.component.ts b/src/lib/misc/confirmation-dialog/confirmation-dialog.component.ts index 4c8e84f..b8e3e78 100644 --- a/src/lib/misc/confirmation-dialog/confirmation-dialog.component.ts +++ b/src/lib/misc/confirmation-dialog/confirmation-dialog.component.ts @@ -7,7 +7,7 @@ export type TitleColor = 'default' | 'primary'; export enum TitleColors { DEFAULT = 'default', - PRIMARY = 'primary' + PRIMARY = 'primary', } export class ConfirmationDialogInput { @@ -37,7 +37,7 @@ export class ConfirmationDialogInput { @Component({ templateUrl: './confirmation-dialog.component.html', styleUrls: ['./confirmation-dialog.component.scss'], - changeDetection: ChangeDetectionStrategy.OnPush + changeDetection: ChangeDetectionStrategy.OnPush, }) export class ConfirmationDialogComponent { config: ConfirmationDialogInput; @@ -47,11 +47,11 @@ export class ConfirmationDialogComponent { constructor( private readonly _dialogRef: MatDialogRef, private readonly _translateService: TranslateService, - @Inject(MAT_DIALOG_DATA) private readonly _confirmationDialogInput: ConfirmationDialogInput + @Inject(MAT_DIALOG_DATA) private readonly _confirmationDialogInput: ConfirmationDialogInput, ) { this.config = _confirmationDialogInput ?? new ConfirmationDialogInput(); this.translate(this.config); - this.inputLabel = `${this._translateService.instant('confirmation-dialog.input-label') as string} '${ + this.inputLabel = `${this._translateService.instant('confirmation-dialog.input-label')} '${ this.config.confirmationText || '' }'`; } @@ -86,14 +86,14 @@ export class ConfirmationDialogComponent { 'details', 'confirmationText', 'alternativeConfirmationText', - 'denyText' + 'denyText', ]; translateKeys .filter(key => !!obj[key]) .forEach(key => { Object.assign(obj, { - [key]: this._translateService.instant(obj[key] as string, this.config.translateParams) as string + [key]: this._translateService.instant(obj[key] as string, this.config.translateParams) as string, }); }); } diff --git a/src/lib/services/error-message.service.ts b/src/lib/services/error-message.service.ts index f13674f..cc186f1 100644 --- a/src/lib/services/error-message.service.ts +++ b/src/lib/services/error-message.service.ts @@ -3,7 +3,7 @@ import { TranslateService } from '@ngx-translate/core'; import { HttpErrorResponse } from '@angular/common/http'; @Injectable({ - providedIn: 'root' + providedIn: 'root', }) export class ErrorMessageService { constructor(private readonly _translateService: TranslateService) {} @@ -13,8 +13,6 @@ export class ErrorMessageService { } private _parseErrorResponse(err: HttpErrorResponse): string { - // eslint-disable-next-line max-len - // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/restrict-template-expressions return err?.error?.message?.includes('message') ? ` ${err.error.message.match('"message":"(.*?)\\"')[1]}` : ''; } } diff --git a/src/lib/services/generic.service.ts b/src/lib/services/generic.service.ts index 92816db..0bd5988 100644 --- a/src/lib/services/generic.service.ts +++ b/src/lib/services/generic.service.ts @@ -24,12 +24,16 @@ export abstract class GenericService { getAll(modelPath = this._defaultModelPath): Observable { return this._http.get(`/${encodeURI(modelPath)}`, { headers: HeadersConfiguration.getHeaders({ contentType: false }), - observe: 'body' + observe: 'body', }); } @Validate() - delete(@RequiredParam() body: unknown, modelPath = this._defaultModelPath, queryParams?: List): Observable { + delete( + @RequiredParam() body: unknown, + modelPath = this._defaultModelPath, + queryParams?: List, + ): Observable { let path = `/${encodeURI(modelPath)}`; if (typeof body === 'string') { @@ -40,7 +44,7 @@ export abstract class GenericService { body: body, params: this._queryParams(queryParams), headers: HeadersConfiguration.getHeaders({ contentType: false }), - observe: 'body' + observe: 'body', }); } @@ -48,12 +52,12 @@ export abstract class GenericService { protected _post( @RequiredParam() body: unknown, modelPath = this._defaultModelPath, - queryParams?: List + queryParams?: List, ): Observable { return this._http.post(`/${encodeURI(modelPath)}`, body, { params: this._queryParams(queryParams), headers: HeadersConfiguration.getHeaders(), - observe: 'body' + observe: 'body', }); } @@ -61,12 +65,12 @@ export abstract class GenericService { protected _put( @RequiredParam() body: unknown, modelPath = this._defaultModelPath, - queryParams?: List + queryParams?: List, ): Observable { return this._http.put(`/${encodeURI(modelPath)}`, body, { params: this._queryParams(queryParams), headers: HeadersConfiguration.getHeaders(), - observe: 'body' + observe: 'body', }); } @@ -74,14 +78,14 @@ export abstract class GenericService { protected _getOne( @RequiredParam() path: List, modelPath = this._defaultModelPath, - queryParams?: List + queryParams?: List, ): Observable { const entityPath = path.map(item => encodeURIComponent(item)).join('/'); return this._http.get(`/${encodeURI(modelPath)}/${entityPath}`, { headers: HeadersConfiguration.getHeaders({ contentType: false }), params: this._queryParams(queryParams), - observe: 'body' + observe: 'body', }); } diff --git a/src/lib/utils/custom-route-reuse.strategy.ts b/src/lib/utils/custom-route-reuse.strategy.ts index 2d51245..43e2da3 100644 --- a/src/lib/utils/custom-route-reuse.strategy.ts +++ b/src/lib/utils/custom-route-reuse.strategy.ts @@ -39,15 +39,13 @@ export class CustomRouteReuseStrategy implements RouteReuseStrategy { // eslint-disable-next-line @typescript-eslint/no-explicit-any const element: any = handle; - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access if (element?.componentRef?.instance?.ngOnDetach) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access this._onDetach(element.componentRef?.instance); } this._storedRoutes[this._getKey(route)] = { handle: element as DetachedRouteHandle, - previousRoute: route + previousRoute: route, }; } @@ -60,9 +58,7 @@ export class CustomRouteReuseStrategy implements RouteReuseStrategy { // eslint-disable-next-line @typescript-eslint/no-explicit-any const element: any = this._storedRoutes[key]?.handle; - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access if (element?.componentRef?.instance?.ngOnAttach) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access this._onAttach(element.componentRef?.instance, this._storedRoutes[key].previousRoute); } @@ -75,7 +71,9 @@ export class CustomRouteReuseStrategy implements RouteReuseStrategy { private _getKey(route: ActivatedRouteSnapshot): string { return route.pathFromRoot - .map((el: ActivatedRouteSnapshot) => (el.routeConfig ? (el.routeConfig.path as string) + JSON.stringify(el.params) : '')) + .map((el: ActivatedRouteSnapshot) => + el.routeConfig ? el.routeConfig.path + JSON.stringify(el.params) : '', + ) .filter(str => str.length > 0) .join(''); }