Skip to content

Commit 33f8265

Browse files
committed
style: fix the lint error due to eslint v9
1 parent d4e7e9e commit 33f8265

File tree

8 files changed

+496
-353
lines changed

8 files changed

+496
-353
lines changed
Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,54 @@
1-
import { chain, Rule, Tree, SchematicContext } from '@angular-devkit/schematics';
2-
import { updateWorkspace } from '@schematics/angular/utility/workspace';
3-
import { Schema } from '../schema';
4-
import { getProjectFromWorkspace, getProjectTargetOptions } from '../../utils/project';
5-
1+
import {
2+
chain,
3+
Rule,
4+
Tree,
5+
SchematicContext,
6+
} from "@angular-devkit/schematics";
7+
import { updateWorkspace } from "@schematics/angular/utility/workspace";
8+
import { Schema } from "../schema";
9+
import {
10+
getProjectFromWorkspace,
11+
getProjectTargetOptions,
12+
} from "../../utils/project";
613

714
export function addThemeToAppStyles(options: Schema): Rule {
8-
const themePath = './node_modules/angular-toaster/toaster.css';
15+
const themePath = "./node_modules/angular-toaster/toaster.css";
916

10-
17+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1118
return (_host: Tree, _context: SchematicContext) => {
1219
return chain([
13-
addThemeStyleToTarget(options.project, 'build', themePath),
14-
addThemeStyleToTarget(options.project, 'test', themePath),
20+
addThemeStyleToTarget(options.project, "build", themePath),
21+
addThemeStyleToTarget(options.project, "test", themePath),
1522
]);
16-
}
23+
};
1724
}
1825

19-
function addThemeStyleToTarget(projectName: string, targetName: 'test' | 'build', assetPath: string): Rule {
20-
return updateWorkspace(workspace => {
26+
function addThemeStyleToTarget(
27+
projectName: string,
28+
targetName: "test" | "build",
29+
assetPath: string
30+
): Rule {
31+
return updateWorkspace((workspace) => {
2132
// TODO: Types have separate declarations of a private property '_validateNam
22-
const project = getProjectFromWorkspace(workspace as any, projectName);
33+
const project = getProjectFromWorkspace(workspace, projectName);
2334

24-
// Do not update the builder options in case the target does not use the default CLI builder.
35+
// Do not update the builder options in case the target does not use the default CLI builder.
2536
// if (!validateDefaultTargetBuilder(project, targetName, logger)) {
2637
// return
2738
// }
2839

2940
const targetOptions = getProjectTargetOptions(project, targetName);
30-
const styles = targetOptions!['styles'] as (string | { input: string })[];
41+
const styles = targetOptions!["styles"] as (string | { input: string })[];
3142

32-
const existingStyles = styles.map(s => (typeof s === 'string' ? s : s.input));
43+
const existingStyles = styles.map((s) =>
44+
typeof s === "string" ? s : s.input
45+
);
3346

3447
for (const [, stylePath] of existingStyles.entries()) {
35-
if (stylePath === assetPath)
36-
return;
48+
if (stylePath === assetPath) return;
3749
}
3850

3951
styles.push(assetPath);
4052
});
41-
}
53+
}
54+

packages/angular-toaster/src/angular-toaster-config.ts

Lines changed: 77 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
21
import { InjectionToken } from "@angular/core";
32

4-
export type ToastType = 'success' | 'info' | 'warning' | 'wait' | 'error';
3+
export type ToastType = "success" | "info" | "warning" | "wait" | "error";
54
export type OnActionCallback = (_toast: Toast) => void;
6-
export type ProgressBarDirection = 'decreasing' | 'increasing';
5+
export type ProgressBarDirection = "decreasing" | "increasing";
76

87
export enum BodyOutputType {
9-
Default, TrustedHtml, Component
8+
Default,
9+
TrustedHtml,
10+
Component,
1011
}
1112

1213
export interface IClearWrapper {
1314
toastId?: string;
1415
toastContainerId?: number;
1516
}
1617

17-
1818
export interface Toast {
1919
type: ToastType;
2020
title?: string;
21+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2122
body?: any;
2223
toastId?: string;
2324
toastContainerId?: number;
@@ -28,35 +29,36 @@ export interface Toast {
2829
bodyOutputType?: BodyOutputType;
2930
showCloseButton?: boolean;
3031
closeHtml?: string;
32+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3133
data?: any;
3234
tapToDismiss?: boolean;
3335
progressBar?: boolean;
34-
progressBarDirection?: ProgressBarDirection
36+
progressBarDirection?: ProgressBarDirection;
3537
}
3638

37-
export const DefaultTypeClasses : Partial<Record<ToastType, string>> = {
38-
error: 'angular-toast-error',
39-
info: 'angular-toast-info',
40-
wait: 'angular-toast-wait',
41-
success: 'angular-toast-success',
42-
warning: 'angular-toast-warning'
39+
export const DefaultTypeClasses: Partial<Record<ToastType, string>> = {
40+
error: "angular-toast-error",
41+
info: "angular-toast-info",
42+
wait: "angular-toast-wait",
43+
success: "angular-toast-success",
44+
warning: "angular-toast-warning",
4345
};
4446

45-
export const DefaultIconClasses : Partial<Record<ToastType, string>> = {
46-
error: 'icon-error',
47-
info: 'icon-info',
48-
wait: 'icon-wait',
49-
success: 'icon-success',
50-
warning: 'icon-warning'
47+
export const DefaultIconClasses: Partial<Record<ToastType, string>> = {
48+
error: "icon-error",
49+
info: "icon-info",
50+
wait: "icon-wait",
51+
success: "icon-success",
52+
warning: "icon-warning",
5153
};
5254

5355
export interface IToasterConfig {
54-
limit?: number|null;
56+
limit?: number | null;
5557
tapToDismiss?: boolean;
56-
showCloseButton?: boolean|Partial<Record<ToastType, boolean>>;
58+
showCloseButton?: boolean | Partial<Record<ToastType, boolean>>;
5759
closeHtml?: string;
5860
newestOnTop?: boolean;
59-
timeout?: number|Partial<Record<ToastType, number>>;
61+
timeout?: number | Partial<Record<ToastType, number>>;
6062
typeClasses?: Partial<Record<ToastType, string>>;
6163
iconClasses?: Partial<Record<ToastType, string>>;
6264
bodyOutputType?: BodyOutputType;
@@ -72,39 +74,40 @@ export interface IToasterConfig {
7274
animation?: string;
7375
preventDuplicates?: boolean;
7476
mouseoverTimerStop?: boolean;
75-
toastContainerId?: number|null;
77+
toastContainerId?: number | null;
7678
}
7779

7880
export const defaultToasterConfig: IToasterConfig = {
7981
limit: null,
8082
tapToDismiss: true,
8183
showCloseButton: false,
82-
closeHtml: '<span>&times;</span>',
84+
closeHtml: "<span>&times;</span>",
8385
newestOnTop: true,
8486
timeout: 5000,
8587
typeClasses: DefaultTypeClasses,
8688
iconClasses: DefaultIconClasses,
8789
bodyOutputType: BodyOutputType.Default,
88-
bodyTemplate: 'toasterBodyTmpl.html',
89-
defaultToastType: 'info',
90-
positionClass: 'angular-toast-top-right',
91-
titleClass: 'angular-toast-title',
92-
messageClass: 'angular-toast-message',
93-
animation: '',
90+
bodyTemplate: "toasterBodyTmpl.html",
91+
defaultToastType: "info",
92+
positionClass: "angular-toast-top-right",
93+
titleClass: "angular-toast-title",
94+
messageClass: "angular-toast-message",
95+
animation: "",
9496
preventDuplicates: false,
9597
mouseoverTimerStop: false,
96-
toastContainerId: null
97-
}
98+
toastContainerId: null,
99+
};
98100

99-
export const ToasterConfigInjectionToken: InjectionToken<IToasterConfig> = new InjectionToken<IToasterConfig>('ToasterConfig');
101+
export const ToasterConfigInjectionToken: InjectionToken<IToasterConfig> =
102+
new InjectionToken<IToasterConfig>("ToasterConfig");
100103

101104
export class ToasterConfig implements IToasterConfig {
102-
limit?: number|null;
105+
limit?: number | null;
103106
tapToDismiss: boolean;
104-
showCloseButton: boolean|Partial<Record<ToastType, boolean>>;
107+
showCloseButton: boolean | Partial<Record<ToastType, boolean>>;
105108
closeHtml: string;
106109
newestOnTop: boolean;
107-
timeout: number|Partial<Record<ToastType, number>>;
110+
timeout: number | Partial<Record<ToastType, number>>;
108111
typeClasses: Partial<Record<ToastType, string>>;
109112
iconClasses: Partial<Record<ToastType, string>>;
110113
bodyOutputType: BodyOutputType;
@@ -120,28 +123,46 @@ export class ToasterConfig implements IToasterConfig {
120123
animation: string;
121124
preventDuplicates: boolean;
122125
mouseoverTimerStop: boolean;
123-
toastContainerId?: number|null;
126+
toastContainerId?: number | null;
124127

125128
constructor(configOverrides?: IToasterConfig) {
126-
configOverrides = configOverrides || {};
127-
this.limit = configOverrides.limit || null;
128-
this.tapToDismiss = configOverrides.tapToDismiss != null ? configOverrides.tapToDismiss : true;
129-
this.showCloseButton = configOverrides.showCloseButton != null ? configOverrides.showCloseButton : false;
130-
this.closeHtml = configOverrides.closeHtml || '<span>&times;</span>';
131-
this.newestOnTop = configOverrides.newestOnTop != null ? configOverrides.newestOnTop : true;
132-
this.timeout = configOverrides.timeout != null ? configOverrides.timeout : 5000;
133-
this.typeClasses = configOverrides.typeClasses || DefaultTypeClasses;
134-
this.iconClasses = configOverrides.iconClasses || DefaultIconClasses;
135-
this.bodyOutputType = configOverrides.bodyOutputType || BodyOutputType.Default;
136-
this.bodyTemplate = configOverrides.bodyTemplate || 'toasterBodyTmpl.html';
137-
this.defaultToastType = configOverrides.defaultToastType || 'info';
138-
this.positionClass = configOverrides.positionClass || 'angular-toast-top-right';
139-
this.titleClass = configOverrides.titleClass || 'angular-toast-title';
140-
this.messageClass = configOverrides.messageClass || 'angular-toast-message';
141-
this.animation = configOverrides.animation || '';
142-
this.preventDuplicates = configOverrides.preventDuplicates != null ? configOverrides.preventDuplicates : false;
143-
this.mouseoverTimerStop = configOverrides.mouseoverTimerStop != null ? configOverrides.mouseoverTimerStop : false;
144-
this.toastContainerId = configOverrides.toastContainerId != null ? configOverrides.toastContainerId : null;
129+
configOverrides = configOverrides || {};
130+
this.limit = configOverrides.limit || null;
131+
this.tapToDismiss =
132+
configOverrides.tapToDismiss != null
133+
? configOverrides.tapToDismiss
134+
: true;
135+
this.showCloseButton =
136+
configOverrides.showCloseButton != null
137+
? configOverrides.showCloseButton
138+
: false;
139+
this.closeHtml = configOverrides.closeHtml || "<span>&times;</span>";
140+
this.newestOnTop =
141+
configOverrides.newestOnTop != null ? configOverrides.newestOnTop : true;
142+
this.timeout =
143+
configOverrides.timeout != null ? configOverrides.timeout : 5000;
144+
this.typeClasses = configOverrides.typeClasses || DefaultTypeClasses;
145+
this.iconClasses = configOverrides.iconClasses || DefaultIconClasses;
146+
this.bodyOutputType =
147+
configOverrides.bodyOutputType || BodyOutputType.Default;
148+
this.bodyTemplate = configOverrides.bodyTemplate || "toasterBodyTmpl.html";
149+
this.defaultToastType = configOverrides.defaultToastType || "info";
150+
this.positionClass =
151+
configOverrides.positionClass || "angular-toast-top-right";
152+
this.titleClass = configOverrides.titleClass || "angular-toast-title";
153+
this.messageClass = configOverrides.messageClass || "angular-toast-message";
154+
this.animation = configOverrides.animation || "";
155+
this.preventDuplicates =
156+
configOverrides.preventDuplicates != null
157+
? configOverrides.preventDuplicates
158+
: false;
159+
this.mouseoverTimerStop =
160+
configOverrides.mouseoverTimerStop != null
161+
? configOverrides.mouseoverTimerStop
162+
: false;
163+
this.toastContainerId =
164+
configOverrides.toastContainerId != null
165+
? configOverrides.toastContainerId
166+
: null;
145167
}
146168
}
147-
Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
<div [ngClass]="buildPositionClass()">
22
@for (toast of toasts; track $index) {
3-
<div toastComp class="angular-toast"
4-
[toast]="toast"
5-
[toasterconfig]="toasterconfig"
6-
[@toastState]="toasterconfig.animation"
7-
[titleClass]="toasterconfig.titleClass!"
8-
[messageClass]="toasterconfig.messageClass!"
9-
[ngClass]="buildToastCompClasses(toast)"
10-
(click)="click(toast)"
11-
(clickEvent)="childClick($event)"
12-
(removeToastEvent)="removeToast($event)"
13-
>
14-
</div>
3+
<div
4+
toastComp
5+
class="angular-toast"
6+
aria-hidden="true"
7+
tabIndex="0"
8+
[toast]="toast"
9+
[toasterconfig]="toasterconfig"
10+
[@toastState]="toasterconfig.animation"
11+
[titleClass]="toasterconfig.titleClass!"
12+
[messageClass]="toasterconfig.messageClass!"
13+
[ngClass]="buildToastCompClasses(toast)"
14+
(click)="click(toast)"
15+
(keypress)="keypress(toast)"
16+
(clickEvent)="childClick($event)"
17+
(removeToastEvent)="removeToast($event)"
18+
></div>
1519
}
1620
</div>

packages/angular-toaster/src/angular-toaster-container.component.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable @angular-eslint/component-selector */
1+
/* eslint-disable @typescript-eslint/prefer-for-of, @typescript-eslint/no-explicit-any, @angular-eslint/component-selector */
22
import { ComponentFixture, TestBed } from "@angular/core/testing";
33
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
44

@@ -67,7 +67,7 @@ export class TestDynamicComponentModule {}
6767
@Component({
6868
selector: "bound-dynamic-component",
6969
template:
70-
'<div>{{someValue}} loaded via component<button (click)="clickHandler()" id="click"></button></div>',
70+
'<div>{{someValue}} loaded via component<button (click)="clickHandler()" id="click">button</button></div>',
7171
// eslint-disable-next-line @angular-eslint/prefer-standalone
7272
standalone: false,
7373
})
@@ -263,7 +263,7 @@ describe("ToasterContainerComponent with sync ToasterService", () => {
263263
it("addToast should use defaultTypeClass if type is empty string", () => {
264264
toasterContainer.ngOnInit();
265265

266-
toasterService.pop(("" as ExtendedToastType), "", "");
266+
toasterService.pop("" as ExtendedToastType, "", "");
267267

268268
expect(toasterContainer.toasterconfig.defaultToastType).toBe("info");
269269
expect(toasterContainer.toasts.length).toBe(1);

0 commit comments

Comments
 (0)