From 1afafe0e28239da365d9f1e663763b210b9a9b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Thu, 26 Aug 2021 20:45:15 +0300 Subject: [PATCH] Eslint curly --- .eslintrc.json | 5 +---- .../circle-button/circle-button.component.ts | 4 +++- src/lib/filtering/filter-utils.ts | 16 +++++++++++---- src/lib/filtering/filter.service.ts | 20 ++++++++++++++----- .../popup-filter/popup-filter.component.ts | 8 ++++++-- src/lib/help-mode/help-mode.service.ts | 4 +++- src/lib/listing/entities.service.ts | 8 ++++++-- .../listing/tables/sync-width.directive.ts | 14 +++++++------ src/lib/search/search.service.ts | 4 +++- src/lib/services/error-message.service.ts | 11 +++++----- src/lib/services/toaster.service.ts | 7 +++++-- src/lib/sorting/models/sorting-order.type.ts | 4 +++- src/lib/sorting/sorting.service.ts | 4 +++- .../utils/decorators/required.decorator.ts | 4 +++- 14 files changed, 77 insertions(+), 36 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index f4c2934..ab8195e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -11,10 +11,7 @@ "eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:@typescript-eslint/recommended-requiring-type-checking", - "plugin:@angular-eslint/recommended--extra", - "airbnb-typescript/base", - "prettier", - "plugin:prettier/recommended" + "plugin:@angular-eslint/recommended--extra" ], "parserOptions": { "project": ["libs/common-ui/tsconfig.*?.json"] diff --git a/src/lib/buttons/circle-button/circle-button.component.ts b/src/lib/buttons/circle-button/circle-button.component.ts index fd5d00e..3d57336 100644 --- a/src/lib/buttons/circle-button/circle-button.component.ts +++ b/src/lib/buttons/circle-button/circle-button.component.ts @@ -35,7 +35,9 @@ export class CircleButtonComponent implements OnInit { } performAction($event: MouseEvent): void { - if (this.disabled) return; + if (this.disabled) { + return; + } if (this.removeTooltip) { this._matTooltip.hide(); diff --git a/src/lib/filtering/filter-utils.ts b/src/lib/filtering/filter-utils.ts index 239cc19..1226de9 100644 --- a/src/lib/filtering/filter-utils.ts +++ b/src/lib/filtering/filter-utils.ts @@ -4,14 +4,18 @@ import { FilterGroup } from './models/filter-group.model'; import { Filter } from './models/filter.model'; function copySettings(oldFilters: NestedFilter[], newFilters: NestedFilter[]) { - if (!oldFilters || !newFilters) return; + if (!oldFilters || !newFilters) { + return; + } oldFilters.forEach(filter => { const newFilter = newFilters.find(f => f.key === filter.key); if (newFilter) { newFilter.checked = filter.checked; newFilter.indeterminate = filter.indeterminate; - if (filter.children && newFilter.children) copySettings(filter.children, newFilter.children); + if (filter.children && newFilter.children) { + copySettings(filter.children, newFilter.children); + } } }); } @@ -49,7 +53,9 @@ export function checkFilter( ): boolean { const hasChecked = filters.find(f => f.checked); - if (!hasChecked) return true; + if (!hasChecked) { + return true; + } let filterMatched = matchAll; filters.forEach(filter => { @@ -75,7 +81,9 @@ export function getFilteredEntities(entities: T[], filters: FilterGroup[]): T filters.forEach(filter => { add = add && checkFilter(entity, filter.filters, filter.checker, filter.checkerArgs, filter.matchAll); }); - if (add) filteredEntities.push(entity); + if (add) { + filteredEntities.push(entity); + } }); return filteredEntities; } diff --git a/src/lib/filtering/filter.service.ts b/src/lib/filtering/filter.service.ts index d6b014c..77ab66b 100644 --- a/src/lib/filtering/filter.service.ts +++ b/src/lib/filtering/filter.service.ts @@ -40,20 +40,30 @@ export class FilterService { toggleFilter(filterGroupSlug: string, key: string): void { const filters = this.filterGroups.find(group => group.slug === filterGroupSlug)?.filters; - if (!filters) return console.error(`Cannot find filter group "${filterGroupSlug}"`); + if (!filters) { + return console.error(`Cannot find filter group "${filterGroupSlug}"`); + } let found = filters.find(f => f.key === key); - if (!found) [found] = filters.map(f => f.children?.find(ff => ff.key === key)); - if (!found) return console.error(`Cannot find filter with key "${key}" in group "${filterGroupSlug}"`); + if (!found) { + [found] = filters.map(f => f.children?.find(ff => ff.key === key)); + } + if (!found) { + return console.error(`Cannot find filter with key "${key}" in group "${filterGroupSlug}"`); + } - found.checked = !found.checked; + if (found) { + found.checked = !found.checked; + } this.refresh(); } addFilterGroup(value: FilterGroup): void { const oldFilters = this.getGroup(value.slug)?.filters; - if (!oldFilters) return this._filterGroups$.next([...this.filterGroups, value]); + if (!oldFilters) { + return this._filterGroups$.next([...this.filterGroups, value]); + } const newGroup = { ...value, filters: processFilters(oldFilters, value.filters) }; this._filterGroups$.next([...this.filterGroups.filter(f => f.slug !== newGroup.slug), newGroup]); diff --git a/src/lib/filtering/popup-filter/popup-filter.component.ts b/src/lib/filtering/popup-filter/popup-filter.component.ts index 8b490dc..98a6cf6 100644 --- a/src/lib/filtering/popup-filter/popup-filter.component.ts +++ b/src/lib/filtering/popup-filter/popup-filter.component.ts @@ -73,7 +73,9 @@ export class PopupFilterComponent implements OnInit { handleCheckedValue(parent); } else { // eslint-disable-next-line no-param-reassign - if (nestedFilter.indeterminate) nestedFilter.checked = false; + if (nestedFilter.indeterminate) { + nestedFilter.checked = false; + } // eslint-disable-next-line no-param-reassign nestedFilter.indeterminate = false; // eslint-disable-next-line no-return-assign,no-param-reassign @@ -89,7 +91,9 @@ export class PopupFilterComponent implements OnInit { deactivateFilters(): void { this._setFilters(this.primaryFiltersSlug); - if (this.secondaryFiltersSlug) this._setFilters(this.secondaryFiltersSlug); + if (this.secondaryFiltersSlug) { + this._setFilters(this.secondaryFiltersSlug); + } } toggleFilterExpanded($event: MouseEvent, nestedFilter: NestedFilter): void { diff --git a/src/lib/help-mode/help-mode.service.ts b/src/lib/help-mode/help-mode.service.ts index 4ab95f4..7258a6c 100644 --- a/src/lib/help-mode/help-mode.service.ts +++ b/src/lib/help-mode/help-mode.service.ts @@ -70,7 +70,9 @@ export class HelpModeService { } highlightHelperElements(): void { - if (!this.isHelpModeActive) return; + if (!this.isHelpModeActive) { + return; + } Object.values(this._elements).forEach(({ helperElement }) => { this._renderer.addClass(helperElement, 'help-highlight'); diff --git a/src/lib/listing/entities.service.ts b/src/lib/listing/entities.service.ts index e6dfe12..c73f34b 100644 --- a/src/lib/listing/entities.service.ts +++ b/src/lib/listing/entities.service.ts @@ -110,13 +110,17 @@ export class EntitiesService { } selectAll(): void { - if (this._allSelected) return this.setSelected([]); + if (this._allSelected) { + return this.setSelected([]); + } this.setSelected(this._displayed); } select(entity: T): void { const currentEntityIdx = this.selected.indexOf(entity); - if (currentEntityIdx === -1) return this.setSelected([...this.selected, entity]); + if (currentEntityIdx === -1) { + return this.setSelected([...this.selected, entity]); + } this.setSelected(this.selected.filter((el, idx) => idx !== currentEntityIdx)); } diff --git a/src/lib/listing/tables/sync-width.directive.ts b/src/lib/listing/tables/sync-width.directive.ts index e624a9b..c7cde8c 100644 --- a/src/lib/listing/tables/sync-width.directive.ts +++ b/src/lib/listing/tables/sync-width.directive.ts @@ -17,6 +17,11 @@ export class SyncWidthDirective implements OnDestroy { clearInterval(this._interval); } + @HostListener('window:resize') + onResize(): void { + this._matchWidth(); + } + private _matchWidth() { const headerItems = (this._elementRef.nativeElement as HTMLElement).children; const tableRows = (this._elementRef.nativeElement as HTMLElement).parentElement?.parentElement?.getElementsByClassName( @@ -30,7 +35,9 @@ export class SyncWidthDirective implements OnDestroy { (this._elementRef.nativeElement as HTMLElement).setAttribute('synced', 'true'); const { tableRow, length } = this._sampleRow(tableRows); - if (!tableRow) return; + if (!tableRow) { + return; + } const hasExtraColumns = headerItems.length !== length ? 1 : 0; @@ -50,11 +57,6 @@ export class SyncWidthDirective implements OnDestroy { } } - @HostListener('window:resize') - onResize(): void { - this._matchWidth(); - } - private _sampleRow(tableRows: HTMLCollectionOf): { tableRow?: Element; length: number; diff --git a/src/lib/search/search.service.ts b/src/lib/search/search.service.ts index 2ef1dbf..9efdf19 100644 --- a/src/lib/search/search.service.ts +++ b/src/lib/search/search.service.ts @@ -17,7 +17,9 @@ export class SearchService { } searchIn(entities: T[]): T[] { - if (!this._searchKey) return entities; + if (!this._searchKey) { + return entities; + } const searchValue = this.searchValue.toLowerCase(); return entities.filter(entity => this._searchField(entity).includes(searchValue)); diff --git a/src/lib/services/error-message.service.ts b/src/lib/services/error-message.service.ts index a1a5d5a..f13674f 100644 --- a/src/lib/services/error-message.service.ts +++ b/src/lib/services/error-message.service.ts @@ -8,12 +8,13 @@ import { HttpErrorResponse } from '@angular/common/http'; export class ErrorMessageService { constructor(private readonly _translateService: TranslateService) {} - private _parseErrorResponse(err: HttpErrorResponse): string { - // 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]}` : ''; - } - getMessage(error: HttpErrorResponse, defaultMessage: string): string { return (this._translateService.instant(defaultMessage) as string) + this._parseErrorResponse(error); } + + 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/toaster.service.ts b/src/lib/services/toaster.service.ts index 0d19ee6..5562b1b 100644 --- a/src/lib/services/toaster.service.ts +++ b/src/lib/services/toaster.service.ts @@ -47,8 +47,11 @@ export class Toaster { error(message: string, options?: Partial): ActiveToast { let resultedMsg; - if (options?.error) resultedMsg = this._errorMessageService.getMessage(options.error, message); - else resultedMsg = this._translateService.instant(message, options?.params) as string; + if (options?.error) { + resultedMsg = this._errorMessageService.getMessage(options.error, message); + } else { + resultedMsg = this._translateService.instant(message, options?.params) as string; + } return this._toastr.error(resultedMsg, options?.title, options); } diff --git a/src/lib/sorting/models/sorting-order.type.ts b/src/lib/sorting/models/sorting-order.type.ts index 8869403..8ab85f8 100644 --- a/src/lib/sorting/models/sorting-order.type.ts +++ b/src/lib/sorting/models/sorting-order.type.ts @@ -4,7 +4,9 @@ export const SortingOrders = { asc: 'asc', desc: 'desc', inverseOf: (order?: 'asc' | 'desc') => { - if (order === undefined) return 'asc'; + if (order === undefined) { + return 'asc'; + } return order === 'asc' ? 'desc' : 'asc'; } } as const; diff --git a/src/lib/sorting/sorting.service.ts b/src/lib/sorting/sorting.service.ts index d3a8af3..e2dd389 100644 --- a/src/lib/sorting/sorting.service.ts +++ b/src/lib/sorting/sorting.service.ts @@ -15,7 +15,9 @@ export class SortingService { } static sort(values: T[], order?: SortingOrder, column?: KeysOf): T[] { - if (!values || values.length <= 1 || !order) return values; + if (!values || values.length <= 1 || !order) { + return values; + } if (!column) { /** sort 1D array */ diff --git a/src/lib/utils/decorators/required.decorator.ts b/src/lib/utils/decorators/required.decorator.ts index ab043da..276dfc0 100644 --- a/src/lib/utils/decorators/required.decorator.ts +++ b/src/lib/utils/decorators/required.decorator.ts @@ -4,7 +4,9 @@ export function Required(condition: Condition = () => true): PropertyDecor return function _required(target: unknown, propertyKey: PropertyKey) { Object.defineProperty(target, propertyKey, { get() { - if (condition(this)) throw new Error(`Attribute ${String(propertyKey)} is required`); + if (condition(this)) { + throw new Error(`Attribute ${String(propertyKey)} is required`); + } }, set(value: unknown) { Object.defineProperty(this, propertyKey, {