From c81ad44858e04d923ee889eca1e12de4a01dd0b8 Mon Sep 17 00:00:00 2001 From: Huy Date: Wed, 5 Feb 2025 10:01:05 +0000 Subject: [PATCH] chore(setup): Add and configure prettier (!4) Co-authored-by: Phan Huy Tran Reviewed-on: https://git.simonis.lol/projects/casino/pulls/4 Reviewed-by: Hop In, I Have Puppies AND WiFi --- frontend/.prettierignore | 4 +++ frontend/.prettierrc | 9 ++++++ frontend/bun.lock | 3 ++ frontend/package.json | 5 ++- frontend/src/app/app.component.html | 3 -- frontend/src/app/app.component.ts | 20 ++++-------- frontend/src/app/app.config.ts | 50 +++++++++++++++-------------- frontend/src/app/app.routes.ts | 5 ++- frontend/src/app/auth.guard.ts | 3 +- frontend/src/index.html | 20 ++++++------ frontend/src/main.ts | 8 +---- 11 files changed, 67 insertions(+), 63 deletions(-) create mode 100644 frontend/.prettierignore create mode 100644 frontend/.prettierrc diff --git a/frontend/.prettierignore b/frontend/.prettierignore new file mode 100644 index 0000000..f0c3bb3 --- /dev/null +++ b/frontend/.prettierignore @@ -0,0 +1,4 @@ +dist +coverage +node_modules +.angular diff --git a/frontend/.prettierrc b/frontend/.prettierrc new file mode 100644 index 0000000..837b4f9 --- /dev/null +++ b/frontend/.prettierrc @@ -0,0 +1,9 @@ +{ + "singleQuote": true, + "trailingComma": "es5", + "tabWidth": 2, + "semi": true, + "printWidth": 100, + "bracketSpacing": true, + "endOfLine": "lf" +} diff --git a/frontend/bun.lock b/frontend/bun.lock index 0a612a4..779bef3 100644 --- a/frontend/bun.lock +++ b/frontend/bun.lock @@ -29,6 +29,7 @@ "karma-coverage": "~2.2.0", "karma-jasmine": "~5.1.0", "karma-jasmine-html-reporter": "~2.1.0", + "prettier": "^3.4.2", "typescript": "~5.5.2", }, }, @@ -1344,6 +1345,8 @@ "postcss-value-parser": ["postcss-value-parser@4.2.0", "", {}, "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ=="], + "prettier": ["prettier@3.4.2", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ=="], + "proc-log": ["proc-log@4.2.0", "", {}, "sha512-g8+OnU/L2v+wyiVK+D5fA34J7EH8jZ8DDlvwhRCMxmMj7UCBvxiO1mGeN+36JXIKF4zevU4kRBd8lVgG9vLelA=="], "process-nextick-args": ["process-nextick-args@2.0.1", "", {}, "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag=="], diff --git a/frontend/package.json b/frontend/package.json index f30a86e..9df863d 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -6,7 +6,9 @@ "start": "bunx @angular/cli serve --proxy-config src/proxy.conf.json", "build": "bunx @angular/cli build", "watch": "bunx @angular/cli build --watch --configuration development", - "test": "bunx @angular/cli test" + "test": "bunx @angular/cli test", + "format": "prettier --write \"src/**/*.{ts,html,css,scss}\"", + "format:check": "prettier --check \"src/**/*.{ts,html,css,scss}\"" }, "private": true, "dependencies": { @@ -35,6 +37,7 @@ "karma-coverage": "~2.2.0", "karma-jasmine": "~5.1.0", "karma-jasmine-html-reporter": "~2.1.0", + "prettier": "^3.4.2", "typescript": "~5.5.2" } } diff --git a/frontend/src/app/app.component.html b/frontend/src/app/app.component.html index 1d818d2..0680b43 100644 --- a/frontend/src/app/app.component.html +++ b/frontend/src/app/app.component.html @@ -1,4 +1 @@ - - - diff --git a/frontend/src/app/app.component.ts b/frontend/src/app/app.component.ts index e25c629..95cdffc 100644 --- a/frontend/src/app/app.component.ts +++ b/frontend/src/app/app.component.ts @@ -1,22 +1,16 @@ -import {APP_INITIALIZER, Component} from '@angular/core'; +import { Component } from '@angular/core'; import { CommonModule } from '@angular/common'; import { RouterOutlet } from '@angular/router'; -import {HelloListComponent} from "./hello-list/hello-list.component"; -import {KeycloakAngularModule} from "keycloak-angular"; +import { KeycloakAngularModule } from 'keycloak-angular'; @Component({ selector: 'app-root', standalone: true, - imports: [CommonModule, HelloListComponent, RouterOutlet, KeycloakAngularModule], - providers: [ ], + imports: [CommonModule, RouterOutlet, KeycloakAngularModule], + providers: [], templateUrl: './app.component.html', - styleUrl: './app.component.css' + styleUrl: './app.component.css', }) -export class AppComponent{ - - constructor() { - } - - - +export class AppComponent { + constructor() {} } diff --git a/frontend/src/app/app.config.ts b/frontend/src/app/app.config.ts index 094570f..23e39b3 100644 --- a/frontend/src/app/app.config.ts +++ b/frontend/src/app/app.config.ts @@ -1,9 +1,13 @@ -import {APP_INITIALIZER, ApplicationConfig} from '@angular/core'; +import { APP_INITIALIZER, ApplicationConfig } from '@angular/core'; import { provideRouter } from '@angular/router'; import { routes } from './app.routes'; -import {KeycloakAngularModule, KeycloakBearerInterceptor, KeycloakService} from "keycloak-angular"; -import {HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi} from "@angular/common/http"; +import { + KeycloakAngularModule, + KeycloakBearerInterceptor, + KeycloakService, +} from 'keycloak-angular'; +import { HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; export const initializeKeycloak = (keycloak: KeycloakService) => async () => keycloak.init({ @@ -15,34 +19,32 @@ export const initializeKeycloak = (keycloak: KeycloakService) => async () => loadUserProfileAtStartUp: true, initOptions: { onLoad: 'check-sso', - silentCheckSsoRedirectUri: - window.location.origin + '/silent-check-sso.html', + silentCheckSsoRedirectUri: window.location.origin + '/silent-check-sso.html', checkLoginIframe: false, redirectUri: 'http://localhost:4200', }, }); - function initializeApp(keycloak: KeycloakService): () => Promise { return () => initializeKeycloak(keycloak)(); } export const appConfig: ApplicationConfig = { - providers: [provideRouter(routes), - KeycloakAngularModule, - { - provide: APP_INITIALIZER, - useFactory: initializeApp, - multi: true, - deps: [KeycloakService] - }, - KeycloakService, - provideHttpClient(withInterceptorsFromDi()), - { - provide: HTTP_INTERCEPTORS, - useClass: KeycloakBearerInterceptor, - multi: true - } - ] - }; - + providers: [ + provideRouter(routes), + KeycloakAngularModule, + { + provide: APP_INITIALIZER, + useFactory: initializeApp, + multi: true, + deps: [KeycloakService], + }, + KeycloakService, + provideHttpClient(withInterceptorsFromDi()), + { + provide: HTTP_INTERCEPTORS, + useClass: KeycloakBearerInterceptor, + multi: true, + }, + ], +}; diff --git a/frontend/src/app/app.routes.ts b/frontend/src/app/app.routes.ts index 02cdecf..dc39edb 100644 --- a/frontend/src/app/app.routes.ts +++ b/frontend/src/app/app.routes.ts @@ -1,4 +1,3 @@ -import {Routes} from '@angular/router'; +import { Routes } from '@angular/router'; -export const routes: Routes = [ -]; +export const routes: Routes = []; diff --git a/frontend/src/app/auth.guard.ts b/frontend/src/app/auth.guard.ts index 0f6dfa2..dd78a48 100644 --- a/frontend/src/app/auth.guard.ts +++ b/frontend/src/app/auth.guard.ts @@ -1,7 +1,6 @@ - import { CanActivateFn } from '@angular/router'; import { inject } from '@angular/core'; -import {KeycloakService} from "keycloak-angular"; +import { KeycloakService } from 'keycloak-angular'; export const authGuard: CanActivateFn = async (route, state) => { const keycloakService = inject(KeycloakService); diff --git a/frontend/src/index.html b/frontend/src/index.html index dfd88fd..8d60cc1 100644 --- a/frontend/src/index.html +++ b/frontend/src/index.html @@ -1,13 +1,13 @@ - - - Lf10StarterNew - - - - - - - + + + Lf10StarterNew + + + + + + + diff --git a/frontend/src/main.ts b/frontend/src/main.ts index 5096254..17447a5 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -2,10 +2,4 @@ import { bootstrapApplication } from '@angular/platform-browser'; import { appConfig } from './app/app.config'; import { AppComponent } from './app/app.component'; - - -bootstrapApplication(AppComponent, appConfig) - .catch((err) => console.error(err)); - - - +bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err));