fix: run prettier on all file to avoid prettier issue inside PR

This commit is contained in:
thomas
2024-01-07 21:41:36 +01:00
parent 3bc793f6b3
commit c8b7c5d4a6
195 changed files with 575 additions and 452 deletions

View File

@@ -2,7 +2,7 @@ import { names } from '@nx/devkit';
export function normalizeDirectory(
appName: string,
directoryName: string
directoryName: string,
): string {
return directoryName
? `${names(directoryName).fileName}/${names(appName).fileName}`
@@ -11,7 +11,7 @@ export function normalizeDirectory(
export function normalizeProjectName(
appName: string,
directoryName: string
directoryName: string,
): string {
return normalizeDirectory(appName, directoryName).replace(/\//g, '-');
}

View File

@@ -1,5 +1,5 @@
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { Tree, readProjectConfiguration } from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { customLibraryGenerator } from './generator';
import { CustomLibraryGeneratorSchema } from './schema';

View File

@@ -9,7 +9,7 @@ import { CustomLibraryGeneratorSchema } from './schema';
export async function customLibraryGenerator(
tree: Tree,
options: CustomLibraryGeneratorSchema
options: CustomLibraryGeneratorSchema,
) {
const projectRoot = `libs/${options.name}`;
addProjectConfiguration(tree, options.name, {

View File

@@ -9,7 +9,7 @@ import { FeatureComponentGeneratorSchema } from './schema';
export async function featureComponentGenerator(
tree: Tree,
options: FeatureComponentGeneratorSchema
options: FeatureComponentGeneratorSchema,
) {
const projectRoot = `libs/${options.name}`;
addProjectConfiguration(tree, options.name, {

View File

@@ -27,7 +27,7 @@ export class BtnHelmetDirective {
this.renderer.setAttribute(
this.element.nativeElement,
'data-state',
this.state()
this.state(),
);
});
}

View File

@@ -11,14 +11,14 @@ import { RouterModule } from '@angular/router';
path: '',
loadChildren: () =>
import('./dashboard/dashboard.component').then(
(m) => m.DashboardModule
(m) => m.DashboardModule,
),
},
{
path: 'create-user',
loadChildren: () =>
import('./create-user/create-user.component').then(
(m) => m.CreateUserModule
(m) => m.CreateUserModule,
),
},
]),

View File

@@ -3,13 +3,15 @@ import { RouterModule } from '@angular/router';
@Component({
selector: 'lib-create-user',
template: `Create User Form
template: `
Create User Form
<button
routerLink=".."
class="border bg-gray-700 rounded-lg p-2 text-white ml-5">
class="ml-5 rounded-lg border bg-gray-700 p-2 text-white">
Back
</button> `,
</button>
`,
})
export class CreateUserComponent {}

View File

@@ -3,13 +3,15 @@ import { RouterModule } from '@angular/router';
@Component({
selector: 'lib-dashboard',
template: `Dashboard
template: `
Dashboard
<button
routerLink="create-user"
class="border bg-gray-700 rounded-lg p-2 text-white ml-10">
class="ml-10 rounded-lg border bg-gray-700 p-2 text-white">
Create User
</button> `,
</button>
`,
})
export class DashboardComponent {}

View File

@@ -10,14 +10,14 @@ import { Observable, map } from 'rxjs';
export class IsAuthorizedGuard implements CanActivate {
constructor(
private authorizationService: AuthorizationService,
private router: Router
private router: Router,
) {}
canActivate(): Observable<boolean | UrlTree> {
return this.authorizationService.isAuthorized$.pipe(
map((isAuthorized) =>
isAuthorized ? true : this.router.createUrlTree(['forbidden'])
)
isAuthorized ? true : this.router.createUrlTree(['forbidden']),
),
);
}
}

View File

@@ -2,6 +2,8 @@ import { Component } from '@angular/core';
@Component({
selector: 'lib-home',
template: `Forbidden component`,
template: `
Forbidden component
`,
})
export class ForbiddenComponent {}

View File

@@ -4,9 +4,10 @@ import { Component, Inject } from '@angular/core';
@Component({
selector: 'lib-home',
template: `Home component
template: `
Home component
<section class="flex gap-5 items-center">
<section class="flex items-center gap-5">
Authorization :
<button class="border p-2 " (click)="authorizeService.authorize()">
Authorize
@@ -17,11 +18,12 @@ import { Component, Inject } from '@angular/core';
(isAuthorized: {{ authorizeService.isAuthorized$ | async }})
</section>
<section>LoadedToken {{ token }}</section> `,
<section>LoadedToken {{ token }}</section>
`,
})
export class HomeComponent {
constructor(
public authorizeService: AuthorizationService,
@Inject(TOKEN) public token: string
@Inject(TOKEN) public token: string,
) {}
}

View File

@@ -7,7 +7,7 @@ export const appRoutes: Route[] = [
path: 'home',
loadChildren: () =>
import('@angular-challenges/module-to-standalone/home').then(
(m) => m.ModuleToStandaloneHomeModule
(m) => m.ModuleToStandaloneHomeModule,
),
},
{
@@ -15,14 +15,14 @@ export const appRoutes: Route[] = [
canActivate: [IsAuthorizedGuard],
loadChildren: () =>
import('@angular-challenges/module-to-standalone/admin/feature').then(
(m) => m.AdminFeatureModule
(m) => m.AdminFeatureModule,
),
},
{
path: 'user',
loadChildren: () =>
import('@angular-challenges/module-to-standalone/user/shell').then(
(m) => m.UserShellModule
(m) => m.UserShellModule,
),
},
@@ -30,7 +30,7 @@ export const appRoutes: Route[] = [
path: 'forbidden',
loadChildren: () =>
import('@angular-challenges/module-to-standalone/forbidden').then(
(m) => m.ForbiddenModule
(m) => m.ForbiddenModule,
),
},
];

View File

@@ -11,14 +11,14 @@ import { RouterModule } from '@angular/router';
path: '',
loadChildren: () =>
import('./dashboard/dashboard.component').then(
(m) => m.ContactDashboardModule
(m) => m.ContactDashboardModule,
),
},
{
path: 'create-contact',
loadChildren: () =>
import('./create-contact/create-contact.component').then(
(m) => m.CreateContactModule
(m) => m.CreateContactModule,
),
},
]),

View File

@@ -3,13 +3,15 @@ import { RouterModule } from '@angular/router';
@Component({
selector: 'lib-create-contact',
template: `Create Contact Form
template: `
Create Contact Form
<button
routerLink=".."
class="border bg-gray-700 rounded-lg p-2 text-white ml-5">
class="ml-5 rounded-lg border bg-gray-700 p-2 text-white">
Back
</button> `,
</button>
`,
})
export class CreateContactComponent {}

View File

@@ -3,13 +3,15 @@ import { RouterModule } from '@angular/router';
@Component({
selector: 'lib-contact-dashboard',
template: `Contact Dashboard
template: `
Contact Dashboard
<button
routerLink="create-contact"
class="border bg-gray-700 rounded-lg p-2 text-white ml-10">
class="ml-10 rounded-lg border bg-gray-700 p-2 text-white">
Create contact
</button> `,
</button>
`,
})
export class ContactDashboardComponent {}

View File

@@ -2,6 +2,8 @@ import { Component } from '@angular/core';
@Component({
selector: 'lib-user-home',
template: `User Home component`,
template: `
User Home component
`,
})
export class UserHomeComponent {}

View File

@@ -5,15 +5,15 @@ import { Component, Inject } from '@angular/core';
selector: 'lib-user-shell',
template: `
-- User Panel --
<div class="flex gap-2 items-center">
<div class="flex items-center gap-2">
<button
routerLink="home"
class="border px-4 py-2 border-blue-400 rounded-md">
class="rounded-md border border-blue-400 px-4 py-2">
Home
</button>
<button
routerLink="contact"
class="border px-4 py-2 border-blue-400 rounded-md">
class="rounded-md border border-blue-400 px-4 py-2">
Contact
</button>
More buttons ...

View File

@@ -11,14 +11,14 @@ export const userShellRoutes: Route[] = [
path: 'home',
loadChildren: () =>
import('@angular-challenges/module-to-standalone/user/home').then(
(m) => m.UserHomeModule
(m) => m.UserHomeModule,
),
},
{
path: 'contact',
loadChildren: () =>
import('@angular-challenges/module-to-standalone/user/contact').then(
(m) => m.ContactFeatureModule
(m) => m.ContactFeatureModule,
),
},
],

View File

@@ -16,19 +16,19 @@ export class FakeDBService extends ComponentStore<{
readonly teachers$ = this.select((state) => state.teachers);
readonly randomTeacher$ = this.select(
this.teachers$,
(teachers) => teachers[randNumber({ max: teachers.length - 1 })]
(teachers) => teachers[randNumber({ max: teachers.length - 1 })],
);
readonly students$ = this.select((state) => state.students);
readonly randomStudents$ = this.select(
this.students$,
(students) => students[randNumber({ max: students.length - 1 })]
(students) => students[randNumber({ max: students.length - 1 })],
);
readonly schools$ = this.select((state) => state.schools);
readonly randomSchool$ = this.select(
this.schools$,
(schools) => schools[randNumber({ max: schools.length - 1 })]
(schools) => schools[randNumber({ max: schools.length - 1 })],
);
constructor() {

View File

@@ -5,7 +5,7 @@ import { BehaviorSubject } from 'rxjs';
@Injectable({ providedIn: 'root' })
export class PushService {
private notificationSubject = new BehaviorSubject<Push | undefined>(
undefined
undefined,
);
notification$ = this.notificationSubject.asObservable();

View File

@@ -6,7 +6,10 @@ import { Directive, DoCheck, ElementRef, NgZone } from '@angular/core';
standalone: true,
})
export class CDFlashingDirective implements DoCheck {
constructor(private elementRef: ElementRef, private zone: NgZone) {}
constructor(
private elementRef: ElementRef,
private zone: NgZone,
) {}
ngDoCheck(): void {
this.cdRan();

View File

@@ -175,8 +175,7 @@ export class CallStateError {
export class CallStateErrorHandler implements ErrorHandler<CallStateError> {
toError = (error: unknown): CallStateError => {
if (error instanceof CallStateError) return error;
if (error instanceof Error)
return new CallStateError(error.name, error.message);
if (error instanceof Error) return new CallStateError(error.name, error.message);
return new CallStateError(UNKNOWN_ERROR_CAUSE, UNKNOWN_ERROR_MESSAGE);
};

View File

@@ -29,7 +29,7 @@ export class CallStateComponentStore<
| (U & CallStateComponentState)
| CallStateComponentState = U extends void
? CallStateComponentState
: U & CallStateComponentState
: U & CallStateComponentState,
> extends ComponentStore<T> {
private error = inject(ERROR_TOKEN);
private flickerTime = inject(FLICKER_TIME);
@@ -39,23 +39,23 @@ export class CallStateComponentStore<
}
readonly isLoading$: Observable<boolean> = this.select(
(state) => state.callState === 'LOADING'
(state) => state.callState === 'LOADING',
);
readonly isLoadingWithFlicker$: Observable<boolean> = this.select(
(state) => state.callState === 'LOADING'
(state) => state.callState === 'LOADING',
).pipe(
switchMap((loading) => nonFlickerLoader(of(loading), this.flickerTime))
switchMap((loading) => nonFlickerLoader(of(loading), this.flickerTime)),
);
readonly isLoaded$: Observable<boolean> = this.select(
(state) => state.callState === 'LOADED'
(state) => state.callState === 'LOADED',
).pipe(switchMap((loaded) => of(loaded)));
readonly callState$ = this.select((state) => state.callState);
readonly error$: Observable<string | undefined> = this.select((state) =>
this.error.getErrorMessage(getErrorCallState(state.callState))
this.error.getErrorMessage(getErrorCallState(state.callState)),
);
readonly updateCallState = this.updater(
@@ -64,7 +64,7 @@ export class CallStateComponentStore<
...(state as object),
callState: callState ?? 'LOADED',
} as T;
}
},
);
readonly startLoading = this.updater(
@@ -74,7 +74,7 @@ export class CallStateComponentStore<
...patchedState,
callState: 'LOADING',
} as T;
}
},
);
readonly stopLoading = this.updater(
@@ -84,12 +84,12 @@ export class CallStateComponentStore<
...patchedState,
callState: 'LOADED',
} as T;
}
},
);
protected handleError(
error: unknown,
patchedState: Partial<U> = {}
patchedState: Partial<U> = {},
): CallStateError {
const err = this.error.toError(error);
this.patchState({

View File

@@ -36,7 +36,7 @@ export interface ErrorState {
export type CallState = LoadingState | ErrorState;
export const getErrorCallState = (
callState: CallState
callState: CallState,
): CustomError | undefined => {
if (isErrorState(callState)) {
return callState.error;

View File

@@ -19,7 +19,7 @@ export const ERROR_TOKEN = new InjectionToken<ErrorHandler<any>>('error', {
});
export const provideErrorHandler = <T extends ErrorHandler<any>>(
errorHandlerClass: Type<T>
errorHandlerClass: Type<T>,
): ClassProvider => ({ provide: ERROR_TOKEN, useClass: errorHandlerClass });
export const FLICKER_TIME = new InjectionToken<number>('flicker', {

View File

@@ -5,16 +5,16 @@ import { combineLatest, map, mapTo, Observable, startWith, timer } from 'rxjs';
*/
export const nonFlickerLoader = (
data$: Observable<boolean>,
duration = 300
duration = 300,
): Observable<boolean> => {
const isTrueWhileDuration$ = timer(duration).pipe(
mapTo(false),
startWith(true)
startWith(true),
);
return combineLatest([data$, isTrueWhileDuration$]).pipe(
map(([data, isTrueWhileDuration]) =>
isTrueWhileDuration ? isTrueWhileDuration : data
)
isTrueWhileDuration ? isTrueWhileDuration : data,
),
);
};

View File

@@ -22,7 +22,7 @@ function describeDestroyService() {
if (!destroy$) {
throw new Error(
'It seems that you forgot to provide DestroyService. Add "provideDestroyService()" to your declarable\'s providers.'
'It seems that you forgot to provide DestroyService. Add "provideDestroyService()" to your declarable\'s providers.',
);
}

View File

@@ -18,13 +18,13 @@ export class FakeBackendService {
getUsers = (active: keyof User, dir: SortDirection, pageIndex: number) =>
timer(0, 1000).pipe(
take(1),
map(() => this.sortByKey(this.users, active, sort[dir]))
map(() => this.sortByKey(this.users, active, sort[dir])),
);
private sortByKey(
arr: User[],
key: keyof User,
direction: SortDirectionIndex
direction: SortDirectionIndex,
): User[] {
return arr.sort((a, b) => {
const valueA = a[key];