mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-23 02:06:29 -05:00
Enforce explicit function return types
This re-enables the `@typescript-eslint/explicit-module-boundary-types` check and also enables the `@typescript-eslint/explicit-function-return-type` check. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
73db821649
commit
9fcc3c6cee
15 changed files with 59 additions and 42 deletions
|
@ -25,7 +25,7 @@ module.exports = {
|
|||
'warn',
|
||||
{ argsIgnorePattern: '^_+$' },
|
||||
],
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
'@typescript-eslint/explicit-function-return-type': 'warn',
|
||||
'no-return-await': 'off',
|
||||
'@typescript-eslint/return-await': ['error', 'always'],
|
||||
'@typescript-eslint/naming-convention': [
|
||||
|
|
|
@ -53,7 +53,7 @@ export class TokensController {
|
|||
|
||||
@Delete('/:keyId')
|
||||
@HttpCode(204)
|
||||
async deleteToken(@Param('keyId') keyId: string) {
|
||||
async deleteToken(@Param('keyId') keyId: string): Promise<void> {
|
||||
return await this.authService.removeToken(keyId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,7 +86,10 @@ export class MeController {
|
|||
@UseGuards(TokenAuthGuard)
|
||||
@Delete('history/:note')
|
||||
@HttpCode(204)
|
||||
deleteHistoryEntry(@Req() req: Request, @Param('note') note: string) {
|
||||
deleteHistoryEntry(
|
||||
@Req() req: Request,
|
||||
@Param('note') note: string,
|
||||
): Promise<void> {
|
||||
// ToDo: Check if user is allowed to delete note
|
||||
try {
|
||||
return this.historyService.deleteHistoryEntry(note, req.user);
|
||||
|
|
|
@ -25,7 +25,7 @@ export class MonitoringController {
|
|||
|
||||
@UseGuards(TokenAuthGuard)
|
||||
@Get('prometheus')
|
||||
getPrometheusStatus() {
|
||||
getPrometheusStatus(): string {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ export const MarkdownBody = createParamDecorator(
|
|||
}
|
||||
},
|
||||
[
|
||||
(target, key) => {
|
||||
(target, key): void => {
|
||||
ApiConsumes('text/markdown')(
|
||||
target,
|
||||
key,
|
||||
|
|
|
@ -123,7 +123,7 @@ export class AuthService {
|
|||
return this.toAuthTokenWithSecretDto(createdToken, `${keyId}.${secret}`);
|
||||
}
|
||||
|
||||
async setLastUsedToken(keyId: string) {
|
||||
async setLastUsedToken(keyId: string): Promise<void> {
|
||||
const accessToken = await this.authTokenRepository.findOne({
|
||||
where: { keyId: keyId },
|
||||
});
|
||||
|
@ -166,7 +166,7 @@ export class AuthService {
|
|||
return user.authTokens;
|
||||
}
|
||||
|
||||
async removeToken(keyId: string) {
|
||||
async removeToken(keyId: string): Promise<void> {
|
||||
const token = await this.authTokenRepository.findOne({
|
||||
where: { keyId: keyId },
|
||||
});
|
||||
|
@ -213,17 +213,17 @@ export class AuthService {
|
|||
|
||||
// Delete all non valid tokens every sunday on 3:00 AM
|
||||
@Cron('0 0 3 * * 0')
|
||||
async handleCron() {
|
||||
async handleCron(): Promise<void> {
|
||||
return await this.removeInvalidTokens();
|
||||
}
|
||||
|
||||
// Delete all non valid tokens 5 sec after startup
|
||||
@Timeout(5000)
|
||||
async handleTimeout() {
|
||||
async handleTimeout(): Promise<void> {
|
||||
return await this.removeInvalidTokens();
|
||||
}
|
||||
|
||||
async removeInvalidTokens() {
|
||||
async removeInvalidTokens(): Promise<void> {
|
||||
const currentTime = new Date().getTime();
|
||||
const tokens: AuthToken[] = await this.authTokenRepository.find();
|
||||
let removedTokens = 0;
|
||||
|
|
|
@ -14,7 +14,7 @@ export class MockAuthGuard {
|
|||
private user: User;
|
||||
constructor(private usersService: UsersService) {}
|
||||
|
||||
async canActivate(context: ExecutionContext) {
|
||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||
const req: Request = context.switchToHttp().getRequest();
|
||||
if (!this.user) {
|
||||
// this assures that we can create the user 'hardcoded', if we need them before any calls are made or
|
||||
|
|
|
@ -4,7 +4,10 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
export const toArrayConfig = (configValue: string, separator = ',') => {
|
||||
export const toArrayConfig: (
|
||||
configValue: string,
|
||||
separator?: string,
|
||||
) => string[] = (configValue: string, separator = ',') => {
|
||||
if (!configValue) {
|
||||
return [];
|
||||
}
|
||||
|
|
|
@ -18,11 +18,11 @@ export class ConsoleLoggerService {
|
|||
this.classContext = context;
|
||||
}
|
||||
|
||||
setContext(context: string) {
|
||||
setContext(context: string): void {
|
||||
this.classContext = context;
|
||||
}
|
||||
|
||||
error(message: unknown, trace = '', functionContext?: string) {
|
||||
error(message: unknown, trace = '', functionContext?: string): void {
|
||||
this.printMessage(
|
||||
message,
|
||||
clc.red,
|
||||
|
@ -32,7 +32,7 @@ export class ConsoleLoggerService {
|
|||
this.printStackTrace(trace);
|
||||
}
|
||||
|
||||
log(message: unknown, functionContext?: string) {
|
||||
log(message: unknown, functionContext?: string): void {
|
||||
this.printMessage(
|
||||
message,
|
||||
clc.green,
|
||||
|
@ -41,7 +41,7 @@ export class ConsoleLoggerService {
|
|||
);
|
||||
}
|
||||
|
||||
warn(message: unknown, functionContext?: string) {
|
||||
warn(message: unknown, functionContext?: string): void {
|
||||
this.printMessage(
|
||||
message,
|
||||
clc.yellow,
|
||||
|
@ -50,7 +50,7 @@ export class ConsoleLoggerService {
|
|||
);
|
||||
}
|
||||
|
||||
debug(message: unknown, functionContext?: string) {
|
||||
debug(message: unknown, functionContext?: string): void {
|
||||
this.printMessage(
|
||||
message,
|
||||
clc.magentaBright,
|
||||
|
@ -59,7 +59,7 @@ export class ConsoleLoggerService {
|
|||
);
|
||||
}
|
||||
|
||||
verbose(message: unknown, functionContext?: string) {
|
||||
verbose(message: unknown, functionContext?: string): void {
|
||||
this.printMessage(
|
||||
message,
|
||||
clc.cyanBright,
|
||||
|
@ -68,7 +68,7 @@ export class ConsoleLoggerService {
|
|||
);
|
||||
}
|
||||
|
||||
private makeContextString(functionContext: string) {
|
||||
private makeContextString(functionContext: string): string {
|
||||
let context = this.classContext;
|
||||
if (functionContext) {
|
||||
context += '.' + functionContext + '()';
|
||||
|
@ -81,7 +81,7 @@ export class ConsoleLoggerService {
|
|||
color: (message: string) => string,
|
||||
context = '',
|
||||
isTimeDiffEnabled?: boolean,
|
||||
) {
|
||||
): void {
|
||||
const output = isObject(message)
|
||||
? `${color('Object:')}\n${JSON.stringify(message, null, 2)}\n`
|
||||
: color(message as string);
|
||||
|
@ -117,7 +117,7 @@ export class ConsoleLoggerService {
|
|||
return result;
|
||||
}
|
||||
|
||||
private printStackTrace(trace: string) {
|
||||
private printStackTrace(trace: string): void {
|
||||
if (!trace) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import { NestConsoleLoggerService } from './logger/nest-console-logger.service';
|
|||
import { setupPrivateApiDocs, setupPublicApiDocs } from './utils/swagger';
|
||||
import { BackendType } from './media/backends/backend-type.enum';
|
||||
|
||||
async function bootstrap() {
|
||||
async function bootstrap(): Promise<void> {
|
||||
const app = await NestFactory.create<NestExpressApplication>(AppModule);
|
||||
const logger = await app.resolve(NestConsoleLoggerService);
|
||||
logger.log('Switching logger', 'AppBootstrap');
|
||||
|
|
|
@ -63,7 +63,7 @@ export class FilesystemBackend implements MediaBackend {
|
|||
return join(this.uploadDirectory, fileName);
|
||||
}
|
||||
|
||||
private async ensureDirectory() {
|
||||
private async ensureDirectory(): Promise<void> {
|
||||
try {
|
||||
await fs.access(this.uploadDirectory);
|
||||
} catch (e) {
|
||||
|
|
|
@ -16,7 +16,13 @@ let versionCache: null | {
|
|||
preRelease?: string;
|
||||
commit?: string;
|
||||
} = null;
|
||||
async function getServerVersionFromPackageJson() {
|
||||
async function getServerVersionFromPackageJson(): Promise<{
|
||||
major: number;
|
||||
minor: number;
|
||||
patch: number;
|
||||
preRelease?: string;
|
||||
commit?: string;
|
||||
}> {
|
||||
if (versionCache === null) {
|
||||
const rawFileContent: string = await fs.readFile(
|
||||
joinPath(__dirname, '../../package.json'),
|
||||
|
|
|
@ -11,23 +11,23 @@
|
|||
@typescript-eslint/require-await */
|
||||
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { LoggerModule } from '../logger/logger.module';
|
||||
import { GuestPermission, PermissionsService } from './permissions.service';
|
||||
import { User } from '../users/user.entity';
|
||||
import { Note } from '../notes/note.entity';
|
||||
import { UsersModule } from '../users/users.module';
|
||||
import { NotesModule } from '../notes/notes.module';
|
||||
import { PermissionsModule } from './permissions.module';
|
||||
import { getRepositoryToken } from '@nestjs/typeorm';
|
||||
import { AuthToken } from '../auth/auth-token.entity';
|
||||
import { Group } from '../groups/group.entity';
|
||||
import { LoggerModule } from '../logger/logger.module';
|
||||
import { AuthorColor } from '../notes/author-color.entity';
|
||||
import { Note } from '../notes/note.entity';
|
||||
import { NotesModule } from '../notes/notes.module';
|
||||
import { Tag } from '../notes/tag.entity';
|
||||
import { Authorship } from '../revisions/authorship.entity';
|
||||
import { Revision } from '../revisions/revision.entity';
|
||||
import { Identity } from '../users/identity.entity';
|
||||
import { User } from '../users/user.entity';
|
||||
import { UsersModule } from '../users/users.module';
|
||||
import { NoteGroupPermission } from './note-group-permission.entity';
|
||||
import { NoteUserPermission } from './note-user-permission.entity';
|
||||
import { Identity } from '../users/identity.entity';
|
||||
import { AuthToken } from '../auth/auth-token.entity';
|
||||
import { Authorship } from '../revisions/authorship.entity';
|
||||
import { AuthorColor } from '../notes/author-color.entity';
|
||||
import { Revision } from '../revisions/revision.entity';
|
||||
import { Tag } from '../notes/tag.entity';
|
||||
import { Group } from '../groups/group.entity';
|
||||
import { PermissionsModule } from './permissions.module';
|
||||
import { GuestPermission, PermissionsService } from './permissions.service';
|
||||
|
||||
describe('PermissionsService', () => {
|
||||
let permissionsService: PermissionsService;
|
||||
|
@ -154,6 +154,7 @@ describe('PermissionsService', () => {
|
|||
noteEverybodyWrite,
|
||||
];
|
||||
}
|
||||
|
||||
const notes = createNoteUserPermissionNotes();
|
||||
|
||||
describe('mayRead works with', () => {
|
||||
|
@ -342,6 +343,7 @@ describe('PermissionsService', () => {
|
|||
[user2groupWrite, user2groupRead, null], // group4: don't allow user1 to read or write via group
|
||||
];
|
||||
}
|
||||
|
||||
/*
|
||||
* creates the matrix multiplication of group0 to group4 of createAllNoteGroupPermissions
|
||||
*/
|
||||
|
@ -414,7 +416,10 @@ describe('PermissionsService', () => {
|
|||
): NoteGroupPermission[][] {
|
||||
const results = [];
|
||||
|
||||
function permute(arr: NoteGroupPermission[], memo: NoteGroupPermission[]) {
|
||||
function permute(
|
||||
arr: NoteGroupPermission[],
|
||||
memo: NoteGroupPermission[],
|
||||
): NoteGroupPermission[][] {
|
||||
let cur;
|
||||
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
|
|
|
@ -26,7 +26,7 @@ export class UsersService {
|
|||
return this.userRepository.save(user);
|
||||
}
|
||||
|
||||
async deleteUser(userName: string) {
|
||||
async deleteUser(userName: string): Promise<void> {
|
||||
// TODO: Handle owned notes and edits
|
||||
const user = await this.userRepository.findOne({
|
||||
where: { userName: userName },
|
||||
|
|
|
@ -9,7 +9,7 @@ import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
|||
import { PrivateApiModule } from '../api/private/private-api.module';
|
||||
import { PublicApiModule } from '../api/public/public-api.module';
|
||||
|
||||
export function setupPublicApiDocs(app: INestApplication) {
|
||||
export function setupPublicApiDocs(app: INestApplication): void {
|
||||
const publicApiOptions = new DocumentBuilder()
|
||||
.setTitle('HedgeDoc Public API')
|
||||
// TODO: Use real version
|
||||
|
@ -25,7 +25,7 @@ export function setupPublicApiDocs(app: INestApplication) {
|
|||
SwaggerModule.setup('apidoc', app, publicApi);
|
||||
}
|
||||
|
||||
export function setupPrivateApiDocs(app: INestApplication) {
|
||||
export function setupPrivateApiDocs(app: INestApplication): void {
|
||||
const privateApiOptions = new DocumentBuilder()
|
||||
.setTitle('HedgeDoc Private API')
|
||||
// TODO: Use real version
|
||||
|
|
Loading…
Reference in a new issue