mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05:00
ESLint: Enable @typescript-eslint/return-await rule
This ensures stack traces are helpful at the cost of a slightly lower performance (one more tick in the event loop). Fixes #838 Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
2ba824d9e2
commit
9485597e6f
8 changed files with 26 additions and 20 deletions
|
@ -27,5 +27,7 @@ module.exports = {
|
|||
{ argsIgnorePattern: '^_+$' },
|
||||
],
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
'no-return-await': 'off',
|
||||
'@typescript-eslint/return-await': ['error', 'always'],
|
||||
},
|
||||
};
|
||||
|
|
|
@ -44,12 +44,16 @@ export class TokensController {
|
|||
@Body('validUntil') validUntil: TimestampMillis,
|
||||
): Promise<AuthTokenWithSecretDto> {
|
||||
// ToDo: Get real userName
|
||||
return this.authService.createTokenForUser('hardcoded', label, validUntil);
|
||||
return await this.authService.createTokenForUser(
|
||||
'hardcoded',
|
||||
label,
|
||||
validUntil,
|
||||
);
|
||||
}
|
||||
|
||||
@Delete('/:keyId')
|
||||
@HttpCode(204)
|
||||
async deleteToken(@Param('keyId') keyId: string) {
|
||||
return this.authService.removeToken(keyId);
|
||||
return await this.authService.removeToken(keyId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ export class MeController {
|
|||
@Get('history')
|
||||
async getUserHistory(@Request() req): Promise<HistoryEntryDto[]> {
|
||||
const foundEntries = await this.historyService.getEntriesByUser(req.user);
|
||||
return Promise.all(
|
||||
return await Promise.all(
|
||||
foundEntries.map(
|
||||
async (entry) => await this.historyService.toHistoryEntryDto(entry),
|
||||
),
|
||||
|
@ -69,7 +69,7 @@ export class MeController {
|
|||
): Promise<HistoryEntryDto> {
|
||||
// ToDo: Check if user is allowed to pin this history entry
|
||||
try {
|
||||
return this.historyService.toHistoryEntryDto(
|
||||
return await this.historyService.toHistoryEntryDto(
|
||||
await this.historyService.updateHistoryEntry(
|
||||
note,
|
||||
req.user,
|
||||
|
@ -103,7 +103,7 @@ export class MeController {
|
|||
@Get('notes')
|
||||
async getMyNotes(@Request() req): Promise<NoteMetadataDto[]> {
|
||||
const notes = await this.notesService.getUserNotes(req.user);
|
||||
return Promise.all(
|
||||
return await Promise.all(
|
||||
notes.map((note) => this.notesService.toNoteMetadataDto(note)),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ export class NotesController {
|
|||
throw new UnauthorizedException('Creating note denied!');
|
||||
}
|
||||
this.logger.debug('Got raw markdown:\n' + text);
|
||||
return this.noteService.toNoteDto(
|
||||
return await this.noteService.toNoteDto(
|
||||
await this.noteService.createNote(text, undefined, req.user),
|
||||
);
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ export class NotesController {
|
|||
throw new UnauthorizedException('Reading note denied!');
|
||||
}
|
||||
await this.historyService.createOrUpdateHistoryEntry(note, req.user);
|
||||
return this.noteService.toNoteDto(note);
|
||||
return await this.noteService.toNoteDto(note);
|
||||
}
|
||||
|
||||
@UseGuards(TokenAuthGuard)
|
||||
|
@ -106,7 +106,7 @@ export class NotesController {
|
|||
}
|
||||
this.logger.debug('Got raw markdown:\n' + text, 'createNamedNote');
|
||||
try {
|
||||
return this.noteService.toNoteDto(
|
||||
return await this.noteService.toNoteDto(
|
||||
await this.noteService.createNote(text, noteAlias, req.user),
|
||||
);
|
||||
} catch (e) {
|
||||
|
@ -153,7 +153,7 @@ export class NotesController {
|
|||
throw new UnauthorizedException('Updating note denied!');
|
||||
}
|
||||
this.logger.debug('Got raw markdown:\n' + text, 'updateNote');
|
||||
return this.noteService.toNoteDto(
|
||||
return await this.noteService.toNoteDto(
|
||||
await this.noteService.updateNote(note, text),
|
||||
);
|
||||
} catch (e) {
|
||||
|
@ -196,7 +196,7 @@ export class NotesController {
|
|||
if (!this.permissionsService.mayRead(req.user, note)) {
|
||||
throw new UnauthorizedException('Reading note denied!');
|
||||
}
|
||||
return this.noteService.toNoteMetadataDto(note);
|
||||
return await this.noteService.toNoteMetadataDto(note);
|
||||
} catch (e) {
|
||||
if (e instanceof NotInDBError) {
|
||||
throw new NotFoundException(e.message);
|
||||
|
@ -220,7 +220,7 @@ export class NotesController {
|
|||
if (!this.permissionsService.isOwner(req.user, note)) {
|
||||
throw new UnauthorizedException('Updating note denied!');
|
||||
}
|
||||
return this.noteService.toNotePermissionsDto(
|
||||
return await this.noteService.toNotePermissionsDto(
|
||||
await this.noteService.updateNotePermissions(note, updateDto),
|
||||
);
|
||||
} catch (e) {
|
||||
|
@ -243,7 +243,7 @@ export class NotesController {
|
|||
throw new UnauthorizedException('Reading note denied!');
|
||||
}
|
||||
const revisions = await this.revisionsService.getAllRevisions(note);
|
||||
return Promise.all(
|
||||
return await Promise.all(
|
||||
revisions.map((revision) =>
|
||||
this.revisionsService.toRevisionMetadataDto(revision),
|
||||
),
|
||||
|
|
|
@ -49,17 +49,17 @@ export class AuthService {
|
|||
}
|
||||
const accessToken = await this.getAuthTokenAndValidate(keyId, secret);
|
||||
await this.setLastUsedToken(keyId);
|
||||
return this.usersService.getUserByUsername(accessToken.user.userName);
|
||||
return await this.usersService.getUserByUsername(accessToken.user.userName);
|
||||
}
|
||||
|
||||
async hashPassword(cleartext: string): Promise<string> {
|
||||
// hash the password with bcrypt and 2^12 iterations
|
||||
// this was decided on the basis of https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#bcrypt
|
||||
return hash(cleartext, 12);
|
||||
return await hash(cleartext, 12);
|
||||
}
|
||||
|
||||
async checkPassword(cleartext: string, password: string): Promise<boolean> {
|
||||
return compare(cleartext, password);
|
||||
return await compare(cleartext, password);
|
||||
}
|
||||
|
||||
async randomString(length: number): Promise<Buffer> {
|
||||
|
@ -209,13 +209,13 @@ export class AuthService {
|
|||
// Delete all non valid tokens every sunday on 3:00 AM
|
||||
@Cron('0 0 3 * * 0')
|
||||
async handleCron() {
|
||||
return this.removeInvalidTokens();
|
||||
return await this.removeInvalidTokens();
|
||||
}
|
||||
|
||||
// Delete all non valid tokens 5 sec after startup
|
||||
@Timeout(5000)
|
||||
async handleTimeout() {
|
||||
return this.removeInvalidTokens();
|
||||
return await this.removeInvalidTokens();
|
||||
}
|
||||
|
||||
async removeInvalidTokens() {
|
||||
|
|
|
@ -79,7 +79,7 @@ export class HistoryService {
|
|||
);
|
||||
}
|
||||
entry.pinStatus = updateDto.pinStatus;
|
||||
return this.historyEntryRepository.save(entry);
|
||||
return await this.historyEntryRepository.save(entry);
|
||||
}
|
||||
|
||||
async deleteHistoryEntry(noteIdOrAlias: string, user: User): Promise<void> {
|
||||
|
|
|
@ -46,7 +46,7 @@ export class FilesystemBackend implements MediaBackend {
|
|||
async deleteFile(fileName: string, _: BackendData): Promise<void> {
|
||||
const filePath = this.getFilePath(fileName);
|
||||
try {
|
||||
return fs.unlink(filePath);
|
||||
return await fs.unlink(filePath);
|
||||
} catch (e) {
|
||||
this.logger.error(e.message, e.stack, 'deleteFile');
|
||||
throw new MediaBackendError(`Could not delete '${filePath}'`);
|
||||
|
|
|
@ -202,7 +202,7 @@ export class NotesService {
|
|||
//TODO: Calculate patch
|
||||
revisions.push(Revision.create(noteContent, noteContent));
|
||||
note.revisions = Promise.resolve(revisions);
|
||||
return this.noteRepository.save(note);
|
||||
return await this.noteRepository.save(note);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue