Skip to content

Commit d5435b6

Browse files
committed
refactor: eslint minor syntax cleanups
1 parent 85e8ff2 commit d5435b6

File tree

16 files changed

+165
-204
lines changed

16 files changed

+165
-204
lines changed

Diff for: projects/coreui-angular-chartjs/src/lib/chartjs.component.spec.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@ describe('ChartjsComponent', () => {
1818

1919
const data = {
2020
labels: labels,
21-
datasets: [{
22-
data: [65, 59, 84, 84, 51, 55, 40],
23-
...colors,
24-
fill: { value: 65 }
25-
}]
21+
datasets: [
22+
{
23+
data: [65, 59, 84, 84, 51, 55, 40],
24+
...colors,
25+
fill: { value: 65 }
26+
}
27+
]
2628
};
2729

2830
beforeEach(async () => {
2931
Chart.register(...registerables);
3032

3133
await TestBed.configureTestingModule({
3234
imports: [ChartjsComponent]
33-
})
34-
.compileComponents();
35+
}).compileComponents();
3536
});
3637

3738
beforeEach(() => {
38-
// @ts-ignore
3939
fixture = TestBed.createComponent(ChartjsComponent);
4040
component = fixture.componentInstance;
4141
component.data = undefined;

Diff for: projects/coreui-angular-chartjs/src/lib/chartjs.component.ts

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ let nextId = 0;
3636
exportAs: 'cChart',
3737
standalone: true,
3838
changeDetection: ChangeDetectionStrategy.OnPush
39-
// eslint-disable-next-line @angular-eslint/no-host-metadata-property
4039
// host: { ngSkipHydration: 'true' }
4140
})
4241
export class ChartjsComponent implements AfterViewInit, OnDestroy, OnChanges {

Diff for: projects/coreui-angular/src/lib/collapse/collapse.directive.ts

-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@ import {
2323
} from './collapse.animations';
2424

2525
// todo
26-
// tslint:disable-next-line:no-conflicting-lifecycle
2726
@Directive({
2827
selector: '[cCollapse]',
2928
exportAs: 'cCollapse',
3029
standalone: true
3130
})
3231
export class CollapseDirective implements OnChanges, OnDestroy, DoCheck, AfterViewInit {
33-
3432
/**
3533
* @ignore
3634
*/

Diff for: projects/coreui-angular/src/lib/offcanvas/offcanvas/offcanvas.component.ts

+23-43
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,10 @@ let nextId = 0;
5353
exportAs: 'cOffcanvas',
5454
standalone: true,
5555
imports: [A11yModule],
56-
hostDirectives: [
57-
{ directive: ThemeDirective, inputs: ['dark'] }
58-
],
59-
// eslint-disable-next-line @angular-eslint/no-host-metadata-property
56+
hostDirectives: [{ directive: ThemeDirective, inputs: ['dark'] }],
6057
host: { ngSkipHydration: 'true' }
6158
})
6259
export class OffcanvasComponent implements OnInit, OnDestroy {
63-
6460
#destroyRef = inject(DestroyRef);
6561

6662
constructor(
@@ -196,7 +192,8 @@ export class OffcanvasComponent implements OnInit, OnDestroy {
196192
}
197193
const element: Element = this.document.documentElement;
198194
const responsiveBreakpoint = this.responsive;
199-
const breakpointValue = getComputedStyle(element)?.getPropertyValue(`--cui-breakpoint-${responsiveBreakpoint.trim()}`) ?? false;
195+
const breakpointValue =
196+
getComputedStyle(element)?.getPropertyValue(`--cui-breakpoint-${responsiveBreakpoint.trim()}`) ?? false;
200197
return breakpointValue ? `${parseFloat(breakpointValue.trim()) - 0.02}px` : false;
201198
}
202199

@@ -229,12 +226,7 @@ export class OffcanvasComponent implements OnInit, OnDestroy {
229226

230227
@HostListener('document:keydown', ['$event'])
231228
onKeyDownHandler(event: KeyboardEvent): void {
232-
if (
233-
event.key === 'Escape' &&
234-
this.keyboard &&
235-
this.visible &&
236-
this.backdrop !== 'static'
237-
) {
229+
if (event.key === 'Escape' && this.keyboard && this.visible && this.backdrop !== 'static') {
238230
this.offcanvasService.toggle({ show: false, id: this.id });
239231
}
240232
}
@@ -258,46 +250,36 @@ export class OffcanvasComponent implements OnInit, OnDestroy {
258250
}
259251

260252
private stateToggleSubscribe(): void {
261-
this.offcanvasService.offcanvasState$
262-
.pipe(
263-
takeUntilDestroyed(this.#destroyRef)
264-
)
265-
.subscribe((action) => {
266-
if (this === action.offcanvas || this.id === action.id) {
267-
if ('show' in action) {
268-
this.visible =
269-
action?.show === 'toggle' ? !this.visible : action.show;
270-
}
253+
this.offcanvasService.offcanvasState$.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe((action) => {
254+
if (this === action.offcanvas || this.id === action.id) {
255+
if ('show' in action) {
256+
this.visible = action?.show === 'toggle' ? !this.visible : action.show;
271257
}
272-
});
258+
}
259+
});
273260
}
274261

275262
private backdropClickSubscribe(subscribe: boolean = true): void {
276263
if (subscribe) {
277-
this.#backdropClickSubscription =
278-
this.backdropService.backdropClick$
279-
.pipe(
280-
takeUntilDestroyed(this.#destroyRef)
281-
)
282-
.subscribe((clicked) => {
283-
this.offcanvasService.toggle({ show: !clicked, id: this.id });
284-
});
264+
this.#backdropClickSubscription = this.backdropService.backdropClick$
265+
.pipe(takeUntilDestroyed(this.#destroyRef))
266+
.subscribe((clicked) => {
267+
this.offcanvasService.toggle({ show: !clicked, id: this.id });
268+
});
285269
} else {
286270
this.#backdropClickSubscription?.unsubscribe();
287271
}
288272
}
289273

290274
private setBackdrop(setBackdrop: boolean | 'static'): void {
291-
this.#activeBackdrop = !!setBackdrop ? this.backdropService.setBackdrop('offcanvas')
292-
: this.backdropService.clearBackdrop(this.#activeBackdrop);
293-
setBackdrop === true ? this.backdropClickSubscribe()
294-
: this.backdropClickSubscribe(false);
275+
this.#activeBackdrop = !!setBackdrop
276+
? this.backdropService.setBackdrop('offcanvas')
277+
: this.backdropService.clearBackdrop(this.#activeBackdrop);
278+
setBackdrop === true ? this.backdropClickSubscribe() : this.backdropClickSubscribe(false);
295279
}
296280

297281
private layoutChangeSubscribe(subscribe: boolean = true): void {
298-
299282
if (subscribe) {
300-
301283
if (!this.responsiveBreakpoint) {
302284
return;
303285
}
@@ -308,14 +290,12 @@ export class OffcanvasComponent implements OnInit, OnDestroy {
308290

309291
this.#layoutChangeSubscription = layoutChanges
310292
.pipe(
311-
filter(breakpointState => !breakpointState.matches),
293+
filter((breakpointState) => !breakpointState.matches),
312294
takeUntilDestroyed(this.#destroyRef)
313295
)
314-
.subscribe(
315-
(breakpointState: BreakpointState) => {
316-
this.visible = breakpointState.matches;
317-
}
318-
);
296+
.subscribe((breakpointState: BreakpointState) => {
297+
this.visible = breakpointState.matches;
298+
});
319299
} else {
320300
this.#layoutChangeSubscription?.unsubscribe();
321301
}

Diff for: projects/coreui-angular/src/lib/progress/progress-bar.directive.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { IProgressBar } from './progress.type';
2020
standalone: true
2121
})
2222
export class ProgressBarDirective implements IProgressBar {
23-
2423
constructor() {}
2524

2625
readonly #renderer = inject(Renderer2);
@@ -32,13 +31,15 @@ export class ProgressBarDirective implements IProgressBar {
3231
readonly #width: WritableSignal<number | undefined> = signal(undefined);
3332

3433
readonly percent = computed(() => {
35-
return +((((this.#value() ?? this.#width() ?? 0) - this.#min) / (this.#max() - this.#min)) * 100).toFixed(this.precision);
34+
return +((((this.#value() ?? this.#width() ?? 0) - this.#min) / (this.#max() - this.#min)) * 100).toFixed(
35+
this.precision
36+
);
3637
});
3738

3839
readonly #valuesEffect: EffectRef = effect(() => {
3940
const host: HTMLElement = this.#hostElement.nativeElement;
4041
if (this.#value() === undefined || this.#width()) {
41-
for (let name of ['aria-valuenow', 'aria-valuemax', 'aria-valuemin', 'role']) {
42+
for (const name of ['aria-valuenow', 'aria-valuemax', 'aria-valuemin', 'role']) {
4243
this.#renderer.removeAttribute(host, name);
4344
}
4445
} else {
@@ -118,5 +119,4 @@ export class ProgressBarDirective implements IProgressBar {
118119
* @type string
119120
*/
120121
@Input() role: string = 'progressbar';
121-
122122
}

Diff for: projects/coreui-angular/src/lib/services/local-storage.service.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import { DOCUMENT, isPlatformBrowser } from '@angular/common';
2-
import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
2+
import { inject, Injectable, PLATFORM_ID } from '@angular/core';
33
import { BehaviorSubject } from 'rxjs';
44
import { InMemoryStorageService } from './in-memory-storage.service';
55

66
@Injectable({
77
providedIn: 'root'
88
})
99
export class LocalStorageService {
10+
private platformId = inject(PLATFORM_ID);
11+
private document = inject(DOCUMENT);
1012

11-
constructor(
12-
@Inject(PLATFORM_ID) private platformId: Object,
13-
@Inject(DOCUMENT) private document: Document
14-
) {
13+
constructor() {
1514
this.#localStorage =
1615
isPlatformBrowser(this.platformId) && this.document.defaultView
17-
? this.document.defaultView?.localStorage
18-
: new InMemoryStorageService();
16+
? this.document.defaultView?.localStorage
17+
: new InMemoryStorageService();
1918
}
2019

2120
#localStorage: Storage;

Diff for: projects/coreui-angular/src/lib/shared/html-attr.directive.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { Directive, ElementRef, Input, OnInit, Renderer2 } from '@angular/core';
66
standalone: true
77
})
88
export class HtmlAttributesDirective implements OnInit {
9-
109
@Input() cHtmlAttr?: { [key: string]: any };
1110

1211
constructor(
@@ -17,7 +16,7 @@ export class HtmlAttributesDirective implements OnInit {
1716
ngOnInit(): void {
1817
const attribs = this.cHtmlAttr;
1918
for (const attr in attribs) {
20-
if (attr === 'style' && typeof (attribs[attr]) === 'object') {
19+
if (attr === 'style' && typeof attribs[attr] === 'object') {
2120
this.setStyle(attribs[attr]);
2221
} else if (attr === 'class') {
2322
this.addClass(attribs[attr]);
@@ -27,7 +26,7 @@ export class HtmlAttributesDirective implements OnInit {
2726
}
2827
}
2928

30-
private setStyle(styles: { [x: string]: any; }): void {
29+
private setStyle(styles: { [x: string]: any }): void {
3130
for (const style in styles) {
3231
if (style) {
3332
this.renderer.setStyle(this.el.nativeElement, style, styles[style]);
@@ -36,15 +35,17 @@ export class HtmlAttributesDirective implements OnInit {
3635
}
3736

3837
private addClass(classes: string | string[]): void {
39-
const classArray = (Array.isArray(classes) ? classes : classes.split(' '));
40-
classArray.filter((element) => element.length > 0).forEach(element => {
41-
this.renderer.addClass(this.el.nativeElement, element);
42-
});
38+
const classArray = Array.isArray(classes) ? classes : classes.split(' ');
39+
classArray
40+
.filter((element) => element.length > 0)
41+
.forEach((element) => {
42+
this.renderer.addClass(this.el.nativeElement, element);
43+
});
4344
}
4445

4546
private setAttrib(key: string, value: string | null): void {
46-
value !== null ?
47-
this.renderer.setAttribute(this.el.nativeElement, key, value) :
48-
this.renderer.removeAttribute(this.el.nativeElement, key);
47+
value !== null
48+
? this.renderer.setAttribute(this.el.nativeElement, key, value)
49+
: this.renderer.removeAttribute(this.el.nativeElement, key);
4950
}
5051
}

Diff for: projects/coreui-angular/src/lib/sidebar/sidebar-nav/sidebar-nav-link.component.ts

+13-20
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ import { SidebarNavIconPipe } from './sidebar-nav-icon.pipe';
2626
export class SidebarNavLinkContentComponent {
2727
@Input() item?: INavData;
2828

29-
constructor(
30-
public helper: SidebarNavHelper
31-
) { }
29+
constructor(public helper: SidebarNavHelper) {}
3230
}
3331

3432
@Component({
@@ -49,8 +47,6 @@ export class SidebarNavLinkContentComponent {
4947
]
5048
})
5149
export class SidebarNavLinkComponent implements OnInit, OnDestroy {
52-
53-
// tslint:disable-next-line:variable-name
5450
protected _item: INavData = {};
5551

5652
@Input()
@@ -64,18 +60,13 @@ export class SidebarNavLinkComponent implements OnInit, OnDestroy {
6460

6561
@Output() linkClick = new EventEmitter();
6662

67-
// @ts-ignore
68-
public linkType: string;
69-
// @ts-ignore
70-
public href: string;
71-
// @ts-ignore
72-
public linkActive: boolean;
73-
// @ts-ignore
74-
private url: string;
63+
public linkType!: string;
64+
public href!: string;
65+
public linkActive!: boolean;
66+
private url!: string;
7567

7668
private navigationEndObservable: Observable<NavigationEnd>;
77-
// @ts-ignore
78-
private navSubscription: Subscription;
69+
private navSubscription!: Subscription;
7970

8071
constructor(
8172
public router: Router
@@ -84,19 +75,21 @@ export class SidebarNavLinkComponent implements OnInit, OnDestroy {
8475
// private sidebarService: SidebarService
8576
) {
8677
this.navigationEndObservable = router.events.pipe(
87-
filter(event => {
78+
filter((event) => {
8879
return event instanceof NavigationEnd;
8980
})
9081
) as Observable<NavigationEnd>;
9182
}
9283

9384
ngOnInit(): void {
94-
// @ts-ignore
95-
this.url = typeof this.item.url === 'string' ? this.item.url : this.router.serializeUrl(this.router.createUrlTree(this.item.url));
85+
this.url =
86+
typeof this.item.url === 'string'
87+
? this.item.url
88+
: this.router.serializeUrl(this.router.createUrlTree(this.item.url as any[]));
9689
this.linkType = this.getLinkType();
97-
this.href = this.isDisabled() ? '' : (this.item.href || this.url);
90+
this.href = this.isDisabled() ? '' : this.item.href || this.url;
9891
this.linkActive = this.router.url.split(/[?#(;]/)[0] === this.href.split(/[?#(;]/)[0];
99-
this.navSubscription = this.navigationEndObservable.subscribe(event => {
92+
this.navSubscription = this.navigationEndObservable.subscribe((event) => {
10093
const itemUrlArray = this.href.split(/[?#(;]/)[0].split('/');
10194
const urlArray = event.urlAfterRedirects.split(/[?#(;]/)[0].split('/');
10295
this.linkActive = itemUrlArray.every((value, index) => value === urlArray[index]);

0 commit comments

Comments
 (0)