diff --git a/.eslintrc.json b/.eslintrc.json index 45679be4..08e7586d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -18,9 +18,9 @@ "createDefaultProgram": true }, "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended", "plugin:@angular-eslint/recommended", - "plugin:@angular-eslint/ng-cli-compat", - "plugin:@angular-eslint/ng-cli-compat--formatting-add-on", "plugin:@angular-eslint/template/process-inline-templates" ], "rules": { @@ -81,7 +81,19 @@ "format": null } ], - "no-underscore-dangle": "off" + "@typescript-eslint/no-explicit-any": "off", + "no-underscore-dangle": "off", + "arrow-spacing": "error", + "comma-spacing": "error", + "indent": ["error", 2], + "key-spacing": "error", + "keyword-spacing": "error", + "object-curly-spacing": ["error", "always"], + "object-shorthand": "error", + "spaced-comment": "error", + "space-before-blocks": "error", + "space-infix-ops": "error", + "semi": "error" } }, { diff --git a/client/app/about/about.component.spec.ts b/client/app/about/about.component.spec.ts index b3d30e2e..bca06c9c 100644 --- a/client/app/about/about.component.spec.ts +++ b/client/app/about/about.component.spec.ts @@ -11,7 +11,7 @@ describe('Component: About', () => { TestBed.configureTestingModule({ declarations: [ AboutComponent ] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/client/app/about/about.component.ts b/client/app/about/about.component.ts index bc100bd0..e036785f 100644 --- a/client/app/about/about.component.ts +++ b/client/app/about/about.component.ts @@ -7,6 +7,4 @@ import { Component } from '@angular/core'; }) export class AboutComponent { - constructor() { } - } diff --git a/client/app/account/account.component.spec.ts b/client/app/account/account.component.spec.ts index 674a3eba..a3e62465 100644 --- a/client/app/account/account.component.spec.ts +++ b/client/app/account/account.component.spec.ts @@ -37,7 +37,7 @@ describe('Component: Account', () => { ], schemas: [NO_ERRORS_SCHEMA] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/client/app/account/account.component.ts b/client/app/account/account.component.ts index d3817602..381801d6 100644 --- a/client/app/account/account.component.ts +++ b/client/app/account/account.component.ts @@ -31,7 +31,7 @@ export class AccountComponent implements OnInit { save(user: User): void { this.userService.editUser(user).subscribe({ - next: res => { + next: () => { this.toast.setMessage('Account settings saved!', 'success'); this.auth.currentUser = user; this.auth.isAdmin = user.role === 'admin'; diff --git a/client/app/add-cat-form/add-cat-form.component.spec.ts b/client/app/add-cat-form/add-cat-form.component.spec.ts index bbf2e78b..50b42b51 100644 --- a/client/app/add-cat-form/add-cat-form.component.spec.ts +++ b/client/app/add-cat-form/add-cat-form.component.spec.ts @@ -21,7 +21,7 @@ describe('Component: AddCatForm', () => { { provide: CatService, useClass: CatServiceMock } ] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/client/app/admin/admin.component.spec.ts b/client/app/admin/admin.component.spec.ts index 36f94f83..90f9b093 100644 --- a/client/app/admin/admin.component.spec.ts +++ b/client/app/admin/admin.component.spec.ts @@ -36,7 +36,7 @@ describe('Component: Admin', () => { ], schemas: [NO_ERRORS_SCHEMA] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/client/app/admin/admin.component.ts b/client/app/admin/admin.component.ts index 3ff86525..7a687bd7 100644 --- a/client/app/admin/admin.component.ts +++ b/client/app/admin/admin.component.ts @@ -33,7 +33,7 @@ export class AdminComponent implements OnInit { deleteUser(user: User): void { if (window.confirm('Are you sure you want to delete ' + user.username + '?')) { this.userService.deleteUser(user).subscribe({ - next: data => this.toast.setMessage('User deleted successfully.', 'success'), + next: () => this.toast.setMessage('User deleted successfully.', 'success'), error: error => console.log(error), complete: () => this.getUsers() }); diff --git a/client/app/cats/cats.component.spec.ts b/client/app/cats/cats.component.spec.ts index 34d5a8d2..a63fd1ad 100644 --- a/client/app/cats/cats.component.spec.ts +++ b/client/app/cats/cats.component.spec.ts @@ -33,7 +33,7 @@ describe('Component: Cats', () => { ], schemas: [CUSTOM_ELEMENTS_SCHEMA] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/client/app/login/login.component.spec.ts b/client/app/login/login.component.spec.ts index d346f585..4b3c63af 100644 --- a/client/app/login/login.component.spec.ts +++ b/client/app/login/login.component.spec.ts @@ -26,7 +26,7 @@ describe('Component: Login', () => { ], schemas: [NO_ERRORS_SCHEMA] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/client/app/logout/logout.component.spec.ts b/client/app/logout/logout.component.spec.ts index e9631ef5..98784514 100644 --- a/client/app/logout/logout.component.spec.ts +++ b/client/app/logout/logout.component.spec.ts @@ -20,7 +20,7 @@ describe('Component: Logout', () => { declarations: [ LogoutComponent ], providers: [ { provide: AuthService, useClass: AuthServiceMock } ], }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/client/app/not-found/not-found.component.spec.ts b/client/app/not-found/not-found.component.spec.ts index 32f75d7b..fa10f270 100644 --- a/client/app/not-found/not-found.component.spec.ts +++ b/client/app/not-found/not-found.component.spec.ts @@ -11,7 +11,7 @@ describe('Component: NotFound', () => { TestBed.configureTestingModule({ declarations: [ NotFoundComponent ] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/client/app/not-found/not-found.component.ts b/client/app/not-found/not-found.component.ts index e80fe1d0..ee45a0aa 100644 --- a/client/app/not-found/not-found.component.ts +++ b/client/app/not-found/not-found.component.ts @@ -6,6 +6,4 @@ import { Component } from '@angular/core'; }) export class NotFoundComponent { - constructor() { } - } diff --git a/client/app/register/register.component.spec.ts b/client/app/register/register.component.spec.ts index 40d0186d..4cc72322 100644 --- a/client/app/register/register.component.spec.ts +++ b/client/app/register/register.component.spec.ts @@ -26,7 +26,7 @@ describe('Component: Register', () => { ], schemas: [NO_ERRORS_SCHEMA] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/client/app/register/register.component.ts b/client/app/register/register.component.ts index df53aaa2..0e9386cc 100644 --- a/client/app/register/register.component.ts +++ b/client/app/register/register.component.ts @@ -58,11 +58,11 @@ export class RegisterComponent { register(): void { this.userService.register(this.registerForm.value).subscribe({ - next: res => { + next: () => { this.toast.setMessage('You successfully registered!', 'success'); this.router.navigate(['/login']); }, - error: error => this.toast.setMessage('Email already exists', 'danger') + error: () => this.toast.setMessage('Email already exists', 'danger') }); } } diff --git a/client/app/services/auth.service.ts b/client/app/services/auth.service.ts index 355fbd8b..5230d092 100644 --- a/client/app/services/auth.service.ts +++ b/client/app/services/auth.service.ts @@ -25,7 +25,7 @@ export class AuthService { } } - login(emailAndPassword: object): void { + login(emailAndPassword: { email: string; password: string }): void { this.userService.login(emailAndPassword).subscribe({ next: res => { localStorage.setItem('token', res.token); @@ -34,7 +34,7 @@ export class AuthService { this.loggedIn = true; this.router.navigate(['/']); }, - error: error => this.toast.setMessage('Invalid email or password!', 'danger') + error: () => this.toast.setMessage('Invalid email or password!', 'danger') }); } diff --git a/client/app/services/cat.service.ts b/client/app/services/cat.service.ts index 0c4cfb6a..e5a6b598 100644 --- a/client/app/services/cat.service.ts +++ b/client/app/services/cat.service.ts @@ -25,11 +25,11 @@ export class CatService { return this.http.get(`/api/cat/${cat._id}`); } - editCat(cat: Cat): Observable { + editCat(cat: Cat): Observable { return this.http.put(`/api/cat/${cat._id}`, cat, { responseType: 'text' }); } - deleteCat(cat: Cat): Observable { + deleteCat(cat: Cat): Observable { return this.http.delete(`/api/cat/${cat._id}`, { responseType: 'text' }); } diff --git a/client/app/services/user.service.ts b/client/app/services/user.service.ts index 58f6259c..19b409a3 100644 --- a/client/app/services/user.service.ts +++ b/client/app/services/user.service.ts @@ -13,7 +13,7 @@ export class UserService { return this.http.post('/api/user', user); } - login(credentials: object): Observable { + login(credentials: { email: string; password: string }): Observable { return this.http.post('/api/login', credentials); } diff --git a/client/app/shared/loading/loading.component.spec.ts b/client/app/shared/loading/loading.component.spec.ts index b1551e7b..5583afda 100644 --- a/client/app/shared/loading/loading.component.spec.ts +++ b/client/app/shared/loading/loading.component.spec.ts @@ -13,7 +13,7 @@ describe('Component: Loading', () => { declarations: [ LoadingComponent ], schemas: [NO_ERRORS_SCHEMA] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/client/app/shared/toast/toast.component.spec.ts b/client/app/shared/toast/toast.component.spec.ts index 08c49533..815dc505 100644 --- a/client/app/shared/toast/toast.component.spec.ts +++ b/client/app/shared/toast/toast.component.spec.ts @@ -13,7 +13,7 @@ describe('Component: Toast', () => { declarations: [ ToastComponent ], schemas: [NO_ERRORS_SCHEMA] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/server/app.ts b/server/app.ts index dbc5c9d0..5459803d 100644 --- a/server/app.ts +++ b/server/app.ts @@ -18,7 +18,7 @@ if (process.env.NODE_ENV !== 'test') { setRoutes(app); -const main = async (): Promise => { +const main = async (): Promise => { try { await connectToMongo(); app.get('/*', (req, res) => { diff --git a/server/models/user.ts b/server/models/user.ts index ea1f3451..aa8c3bf3 100644 --- a/server/models/user.ts +++ b/server/models/user.ts @@ -1,5 +1,5 @@ import { compare, genSalt, hash } from 'bcryptjs'; -import { model, Schema} from 'mongoose'; +import { model, Schema } from 'mongoose'; interface IUser { username: string; @@ -19,6 +19,7 @@ const userSchema = new Schema({ // Before saving the user, hash the password userSchema.pre('save', function(next): void { + // eslint-disable-next-line @typescript-eslint/no-this-alias const user = this; if (!user.isModified('password')) { return next(); } genSalt(10, (err, salt) => { @@ -40,7 +41,7 @@ userSchema.methods.comparePassword = function(candidatePassword: string, callbac // Omit the password when returning a user userSchema.set('toJSON', { - transform: (doc, ret, options) => { + transform: (doc, ret) => { delete ret.password; return ret; }