From 231c46712941714c8a90ed06ce4afc34b7b9358c Mon Sep 17 00:00:00 2001 From: Raj Jaiswal Date: Sun, 28 Nov 2021 14:13:10 +0530 Subject: [PATCH 1/2] Setting up Prettier --- .eslintrc.json | 6 +++-- .prettierignore | 1 + .prettierrc.json | 9 +++++++ package-lock.json | 66 ++++++++++++++++++++++++++++++++++++++++++++++- package.json | 3 +++ 5 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 .prettierignore create mode 100644 .prettierrc.json diff --git a/.eslintrc.json b/.eslintrc.json index 84a5f30..1108078 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -57,10 +57,12 @@ "plugin:@angular-eslint/recommended", "plugin:@angular-eslint/template/process-inline-templates", "airbnb-base", - "airbnb-typescript/base" + "airbnb-typescript/base", + "plugin:prettier/recommended" ], "plugins": [ - "@typescript-eslint" + "@typescript-eslint", + "prettier" ], "rules": { "@angular-eslint/directive-selector": [ diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +node_modules diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..387d69f --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,9 @@ +{ + "arrowParens": "avoid", + "endOfLine": "auto", + "printWidth": 180, + "semi": true, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "all" +} diff --git a/package-lock.json b/package-lock.json index 8fdd66b..2c54dad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3200,6 +3200,16 @@ "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", "dev": true }, + "bindings": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", + "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "dev": true, + "optional": true, + "requires": { + "file-uri-to-path": "1.0.0" + } + }, "bl": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", @@ -5341,6 +5351,12 @@ "eslint-config-airbnb-base": "^15.0.0" } }, + "eslint-config-prettier": { + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.3.0.tgz", + "integrity": "sha512-BgZuLUSeKzvlL/VUjx/Yb787VQ26RU3gGjA3iiFvdsp/2bMfVIWUVP7tjxtjS0e+HP409cPlPvNkQloz8C91ew==", + "dev": true + }, "eslint-import-resolver-node": { "version": "0.3.6", "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.6.tgz", @@ -5495,6 +5511,15 @@ "integrity": "sha512-q8j8KnLH/4uwmPELFZvEyfEcuCuGxXScJaRdqHjOjz064GcfX6aoFbzy5VohZ5QYk2+WvoqMoqDSb9nRLf89GQ==", "dev": true }, + "eslint-plugin-prettier": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-4.0.0.tgz", + "integrity": "sha512-98MqmCJ7vJodoQK359bqQWaxOE0CS8paAz/GgjaZLyex4TTk3g9HugoO89EqWCrFiOqn9EVvcoo7gZzONCWVwQ==", + "dev": true, + "requires": { + "prettier-linter-helpers": "^1.0.0" + } + }, "eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -5871,6 +5896,12 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, + "fast-diff": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz", + "integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==", + "dev": true + }, "fast-glob": { "version": "3.2.7", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.7.tgz", @@ -5943,6 +5974,13 @@ "flat-cache": "^3.0.4" } }, + "file-uri-to-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", + "dev": true, + "optional": true + }, "filelist": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.2.tgz", @@ -8471,6 +8509,13 @@ "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==", "dev": true }, + "nan": { + "version": "2.15.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.15.0.tgz", + "integrity": "sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ==", + "dev": true, + "optional": true + }, "nanoid": { "version": "3.1.30", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.30.tgz", @@ -10797,6 +10842,21 @@ "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true }, + "prettier": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.5.0.tgz", + "integrity": "sha512-FM/zAKgWTxj40rH03VxzIPdXmj39SwSjwG0heUcNFwI+EMZJnY93yAiKXM3dObIKAM5TA88werc8T/EwhB45eg==", + "dev": true + }, + "prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "requires": { + "fast-diff": "^1.1.2" + } + }, "pretty-bytes": { "version": "5.6.0", "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.6.0.tgz", @@ -13127,7 +13187,11 @@ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz", "integrity": "sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==", "dev": true, - "optional": true + "optional": true, + "requires": { + "bindings": "^1.5.0", + "nan": "^2.12.1" + } }, "glob-parent": { "version": "3.1.0", diff --git a/package.json b/package.json index 51b3a6d..8aea495 100644 --- a/package.json +++ b/package.json @@ -42,14 +42,17 @@ "eslint": "^7.32.0", "eslint-config-airbnb-base": "^15.0.0", "eslint-config-airbnb-typescript": "^16.0.0", + "eslint-config-prettier": "^8.3.0", "eslint-plugin-import": "^2.25.3", "eslint-plugin-jasmine": "^4.1.3", + "eslint-plugin-prettier": "^4.0.0", "jasmine-core": "~3.8.0", "karma": "~6.3.0", "karma-chrome-launcher": "~3.1.0", "karma-coverage": "~2.0.3", "karma-jasmine": "~4.0.0", "karma-jasmine-html-reporter": "~1.7.0", + "prettier": "^2.5.0", "typescript": "~4.3.5" } } From 815bb13f02c3a6b279bcaf9ba9bd232a1cd13794 Mon Sep 17 00:00:00 2001 From: Raj Jaiswal Date: Sun, 28 Nov 2021 14:16:16 +0530 Subject: [PATCH 2/2] Prettier: lint fixes. --- src/app/app-routing.module.ts | 2 +- src/app/app.component.spec.ts | 10 +++------- src/app/app.module.ts | 11 +++-------- src/main.ts | 5 +++-- src/test.ts | 17 +++++++---------- 5 files changed, 17 insertions(+), 28 deletions(-) diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 8d6d7b0..f3daf25 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -7,4 +7,4 @@ const routes: Routes = []; imports: [RouterModule.forRoot(routes)], exports: [RouterModule], }) -export class AppRoutingModule { } +export class AppRoutingModule {} diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index fb13fd4..5e44b70 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -5,12 +5,8 @@ import { AppComponent } from './app.component'; describe('AppComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [ - RouterTestingModule, - ], - declarations: [ - AppComponent, - ], + imports: [RouterTestingModule], + declarations: [AppComponent], }).compileComponents(); }); @@ -21,7 +17,7 @@ describe('AppComponent', () => { expect(app).toBeTruthy(); }); - it('should have as title \'eslint-prettier-husky-lintstaged\'', () => { + it("should have as title 'eslint-prettier-husky-lintstaged'", () => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.componentInstance; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index cd11b70..68937b4 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -5,14 +5,9 @@ import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; @NgModule({ - declarations: [ - AppComponent, - ], - imports: [ - BrowserModule, - AppRoutingModule, - ], + declarations: [AppComponent], + imports: [BrowserModule, AppRoutingModule], providers: [], bootstrap: [AppComponent], }) -export class AppModule { } +export class AppModule {} diff --git a/src/main.ts b/src/main.ts index 8816bd1..074f5be 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,5 +9,6 @@ if (environment.production) { enableProdMode(); } -platformBrowserDynamic().bootstrapModule(AppModule) - .catch((err) => throwError(err)); +platformBrowserDynamic() + .bootstrapModule(AppModule) + .catch(err => throwError(err)); diff --git a/src/test.ts b/src/test.ts index 821b040..b1deba9 100644 --- a/src/test.ts +++ b/src/test.ts @@ -2,14 +2,15 @@ import 'zone.js/testing'; import { getTestBed } from '@angular/core/testing'; -import { - BrowserDynamicTestingModule, - platformBrowserDynamicTesting, -} from '@angular/platform-browser-dynamic/testing'; +import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; declare const require: { /* eslint-disable no-unused-vars */ - context(path: string, deep?: boolean, filter?: RegExp): { + context( + path: string, + deep?: boolean, + filter?: RegExp, + ): { keys(): string[]; (id: string): T; }; @@ -17,11 +18,7 @@ declare const require: { }; // First, initialize the Angular testing environment. -getTestBed().initTestEnvironment( - BrowserDynamicTestingModule, - platformBrowserDynamicTesting(), - { teardown: { destroyAfterEach: true } }, -); +getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), { teardown: { destroyAfterEach: true } }); // Then we find all the tests. const context = require.context('./', true, /\.spec\.ts$/);