Skip to content

Commit

Permalink
Fix eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideViolante committed May 5, 2023
1 parent 2db78ec commit 192d1f3
Show file tree
Hide file tree
Showing 22 changed files with 39 additions and 30 deletions.
18 changes: 15 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion client/app/about/about.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Component: About', () => {
TestBed.configureTestingModule({
declarations: [ AboutComponent ]
})
.compileComponents();
.compileComponents();
}));

beforeEach(() => {
Expand Down
2 changes: 0 additions & 2 deletions client/app/about/about.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ import { Component } from '@angular/core';
})
export class AboutComponent {

constructor() { }

}
2 changes: 1 addition & 1 deletion client/app/account/account.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Component: Account', () => {
],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents();
.compileComponents();
}));

beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion client/app/account/account.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion client/app/add-cat-form/add-cat-form.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Component: AddCatForm', () => {
{ provide: CatService, useClass: CatServiceMock }
]
})
.compileComponents();
.compileComponents();
}));

beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion client/app/admin/admin.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Component: Admin', () => {
],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents();
.compileComponents();
}));

beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion client/app/admin/admin.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
});
Expand Down
2 changes: 1 addition & 1 deletion client/app/cats/cats.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('Component: Cats', () => {
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
.compileComponents();
.compileComponents();
}));

beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion client/app/login/login.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('Component: Login', () => {
],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents();
.compileComponents();
}));

beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion client/app/logout/logout.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Component: Logout', () => {
declarations: [ LogoutComponent ],
providers: [ { provide: AuthService, useClass: AuthServiceMock } ],
})
.compileComponents();
.compileComponents();
}));

beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion client/app/not-found/not-found.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Component: NotFound', () => {
TestBed.configureTestingModule({
declarations: [ NotFoundComponent ]
})
.compileComponents();
.compileComponents();
}));

beforeEach(() => {
Expand Down
2 changes: 0 additions & 2 deletions client/app/not-found/not-found.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ import { Component } from '@angular/core';
})
export class NotFoundComponent {

constructor() { }

}
2 changes: 1 addition & 1 deletion client/app/register/register.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('Component: Register', () => {
],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents();
.compileComponents();
}));

beforeEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions client/app/register/register.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
});
}
}
4 changes: 2 additions & 2 deletions client/app/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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')
});
}

Expand Down
4 changes: 2 additions & 2 deletions client/app/services/cat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export class CatService {
return this.http.get<Cat>(`/api/cat/${cat._id}`);
}

editCat(cat: Cat): Observable<any> {
editCat(cat: Cat): Observable<string> {
return this.http.put(`/api/cat/${cat._id}`, cat, { responseType: 'text' });
}

deleteCat(cat: Cat): Observable<any> {
deleteCat(cat: Cat): Observable<string> {
return this.http.delete(`/api/cat/${cat._id}`, { responseType: 'text' });
}

Expand Down
2 changes: 1 addition & 1 deletion client/app/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class UserService {
return this.http.post<User>('/api/user', user);
}

login(credentials: object): Observable<any> {
login(credentials: { email: string; password: string }): Observable<any> {
return this.http.post('/api/login', credentials);
}

Expand Down
2 changes: 1 addition & 1 deletion client/app/shared/loading/loading.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Component: Loading', () => {
declarations: [ LoadingComponent ],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents();
.compileComponents();
}));

beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion client/app/shared/toast/toast.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Component: Toast', () => {
declarations: [ ToastComponent ],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents();
.compileComponents();
}));

beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if (process.env.NODE_ENV !== 'test') {

setRoutes(app);

const main = async (): Promise<any> => {
const main = async (): Promise<void> => {
try {
await connectToMongo();
app.get('/*', (req, res) => {
Expand Down
5 changes: 3 additions & 2 deletions server/models/user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { compare, genSalt, hash } from 'bcryptjs';
import { model, Schema} from 'mongoose';
import { model, Schema } from 'mongoose';

interface IUser {
username: string;
Expand All @@ -19,6 +19,7 @@ const userSchema = new Schema<IUser>({

// Before saving the user, hash the password
userSchema.pre<IUser>('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) => {
Expand All @@ -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;
}
Expand Down

0 comments on commit 192d1f3

Please sign in to comment.