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