refactor: Cleanup

This commit is contained in:
Tibo De Peuter 2025-03-23 14:02:11 +01:00
parent 4bf82b09fa
commit 413220c54f
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
9 changed files with 53 additions and 34 deletions

View file

@ -8,14 +8,4 @@ export default [
globals: globals.node, globals: globals.node,
}, },
}, },
{
files: ['tests/**/*.ts'],
languageOptions: {
globals: globals.node,
},
rules: {
'no-console': 'off',
},
},
]; ];

View file

@ -11,7 +11,7 @@
"format": "prettier --write src/", "format": "prettier --write src/",
"format-check": "prettier --check src/", "format-check": "prettier --check src/",
"lint": "eslint . --fix", "lint": "eslint . --fix",
"test:unit": "vitest" "test:unit": "vitest --run"
}, },
"dependencies": { "dependencies": {
"@mikro-orm/core": "6.4.9", "@mikro-orm/core": "6.4.9",

View file

@ -2,7 +2,7 @@ import { Request, Response } from 'express';
import { createAssignment, getAllAssignments, getAssignment, getAssignmentsSubmissions } from '../services/assignments.js'; import { createAssignment, getAllAssignments, getAssignment, getAssignmentsSubmissions } from '../services/assignments.js';
import { AssignmentDTO } from '../interfaces/assignment.js'; import { AssignmentDTO } from '../interfaces/assignment.js';
// Typescript is annoy with with parameter forwarding from class.ts // Typescript is annoying with parameter forwarding from class.ts
interface AssignmentParams { interface AssignmentParams {
classid: string; classid: string;
id: string; id: string;

View file

@ -80,7 +80,7 @@ export async function getGroupSubmissionsHandler(req: Request, res: Response): P
return; return;
} }
const groupId = Number(req.params.groupid!); // Can't be undefined const groupId = Number(req.params.groupid); // Can't be undefined
if (isNaN(groupId)) { if (isNaN(groupId)) {
res.status(400).json({ error: 'Group id must be a number' }); res.status(400).json({ error: 'Group id must be a number' });

View file

@ -3,18 +3,16 @@ import { themes } from '../data/themes.js';
import { loadTranslations } from '../util/translation-helper.js'; import { loadTranslations } from '../util/translation-helper.js';
interface Translations { interface Translations {
curricula_page: { curricula_page: Record<string, { title: string; description?: string }>;
[key: string]: { title: string; description?: string };
};
} }
export function getThemes(req: Request, res: Response): void { export function getThemes(req: Request, res: Response): void {
const language = (req.query.language as string)?.toLowerCase() || 'nl'; const language = (req.query.language as string).toLowerCase() || 'nl';
const translations = loadTranslations<Translations>(language); const translations = loadTranslations<Translations>(language);
const themeList = themes.map((theme) => ({ const themeList = themes.map((theme) => ({
key: theme.title, key: theme.title,
title: translations.curricula_page[theme.title]?.title || theme.title, title: translations.curricula_page[theme.title].title || theme.title,
description: translations.curricula_page[theme.title]?.description, description: translations.curricula_page[theme.title].description,
image: `https://dwengo.org/images/curricula/logo_${theme.title}.png`, image: `https://dwengo.org/images/curricula/logo_${theme.title}.png`,
})); }));

View file

@ -25,7 +25,7 @@ async function getLearningObjectsForNodes(nodes: LearningPathNode[]): Promise<Ma
version: node.version, version: node.version,
language: node.language, language: node.language,
}) })
.then((learningObject) => ([node, learningObject] as [LearningPathNode, FilteredLearningObject | null])) .then((learningObject) => [node, learningObject] as [LearningPathNode, FilteredLearningObject | null])
) )
) )
); );

View file

@ -10,7 +10,7 @@ import { Language } from '../../../src/entities/content/language.js';
function expectToHaveFoundPrecisely(expected: LearningPath, result: LearningPath[]): void { function expectToHaveFoundPrecisely(expected: LearningPath, result: LearningPath[]): void {
expect(result).toHaveProperty('length'); expect(result).toHaveProperty('length');
expect(result.length).toBe(1); expect(result.length).toBe(1);
expectToBeCorrectEntity({ entity: result[0]! }, { entity: expected }); expectToBeCorrectEntity({ entity: result[0] }, { entity: expected });
} }
function expectToHaveFoundNothing(result: LearningPath[]): void { function expectToHaveFoundNothing(result: LearningPath[]): void {

View file

@ -46,8 +46,6 @@ async function initPersonalizationTestData(): Promise<{
await learningObjectRepo.save(learningContent.extraExerciseObject); await learningObjectRepo.save(learningContent.extraExerciseObject);
await learningPathRepo.save(learningContent.learningPath); await learningPathRepo.save(learningContent.learningPath);
console.log(await getSubmissionRepository().findAll({}));
const studentA = studentRepo.create({ const studentA = studentRepo.create({
username: 'student_a', username: 'student_a',
firstName: 'Aron', firstName: 'Aron',

View file

@ -32,12 +32,23 @@ export default [
reportUnusedInlineConfigs: 'error', reportUnusedInlineConfigs: 'error',
}, },
rules: { rules: {
// All @typescript-eslint configuration options are listed.
// If the rules are commented, they are configured by the inherited configurations.
'@typescript-eslint/adjacent-overload-signatures': 'warn',
'@typescript-eslint/array-type': 'warn', '@typescript-eslint/array-type': 'warn',
'@typescript-eslint/await-thenable': 'error', '@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/ban-ts-comment': [
'error',
{ minimumDescriptionLength: 10 },
],
'@typescript-eslint/ban-tslint-comment': 'error',
'camelcase': 'off',
'@typescript-eslint/class-literal-property-style': 'warn',
'class-methods-use-this': 'off', 'class-methods-use-this': 'off',
'@typescript-eslint/class-methods-use-this': [ 'error', { ignoreOverrideMethods: true } ], '@typescript-eslint/class-methods-use-this': [ 'error', { ignoreOverrideMethods: true } ],
'@typescript-eslint/consistent-generic-constructors': 'warn',
'@typescript-eslint/consistent-indexed-object-style': 'error',
'consistent-return': 'off', 'consistent-return': 'off',
'@typescript-eslint/consistent-return': 'off', '@typescript-eslint/consistent-return': 'off',
'@typescript-eslint/consistent-type-assertions': 'error', '@typescript-eslint/consistent-type-assertions': 'error',
@ -46,9 +57,13 @@ export default [
'@typescript-eslint/consistent-type-imports': 'off', '@typescript-eslint/consistent-type-imports': 'off',
'default-param-last': 'off', 'default-param-last': 'off',
'@typescript-eslint/default-param-last': 'error', '@typescript-eslint/default-param-last': 'error',
'dot-notation': 'off',
'@typescript-eslint/dot-notation': 'warn',
'@typescript-eslint/explicit-function-return-type': 'warn', '@typescript-eslint/explicit-function-return-type': 'warn',
'@typescript-eslint/explicit-member-accessibility': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'warn',
'init-declarations': 'off',
'@typescript-eslint/init-declarations': 'off',
'max-params': 'off', 'max-params': 'off',
'@typescript-eslint/max-params': ['error', { 'max': 6 }], '@typescript-eslint/max-params': ['error', { 'max': 6 }],
'@typescript-eslint/member-ordering': 'warn', '@typescript-eslint/member-ordering': 'warn',
@ -76,22 +91,41 @@ export default [
'no-array-constructor': 'off', 'no-array-constructor': 'off',
'@typescript-eslint/no-array-constructor': 'error', '@typescript-eslint/no-array-constructor': 'error',
'@typescript-eslint/no-array-delete': 'error', '@typescript-eslint/no-array-delete': 'error',
'@typescript-eslint/no-base-to-string': 'off',
'@typescript-eslint/no-confusing-non-null-assertion': 'error',
'@typescript-eslint/no-confusing-void-expression': 'error',
'@typescript-eslint/no-deprecated': 'error',
'no-dupe-class-members': 'off', 'no-dupe-class-members': 'off',
'@typescript-eslint/no-dupe-class-members': 'off', '@typescript-eslint/no-dupe-class-members': 'off',
'@typescript-eslint/no-duplicate-enum-values': 'error', '@typescript-eslint/no-duplicate-enum-values': 'error',
'no-duplicate-imports': 'off', 'no-duplicate-imports': 'off',
'@typescript-eslint/no-duplicate-type-constituents': 'off', '@typescript-eslint/no-duplicate-type-constituents': 'off',
'@typescript-eslint/no-dynamic-delete': 'error',
// 'no-empty-function': 'off', 'no-empty-function': 'off',
'@typescript-eslint/no-empty-function': 'error', '@typescript-eslint/no-empty-function': 'error',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-empty-object-type': 'error',
'@typescript-eslint/no-explicit-any': 'warn', // Once in production, this should be an error.
'@typescript-eslint/no-extra-non-null-assertion': 'error',
'@typescript-eslint/no-extraneous-class': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-for-in-array': 'error', '@typescript-eslint/no-for-in-array': 'error',
'no-implied-eval': 'off',
'@typescript-eslint/no-implied-eval': 'error',
'@typescript-eslint/no-import-type-side-effects': 'error',
'@typescript-eslint/no-inferrable-types': 'warn', '@typescript-eslint/no-inferrable-types': 'warn',
'no-invalid-this': 'off',
'@typescript-eslint/no-invalid-this': 'off',
'@typescript-eslint/no-invalid-void-type': 'error',
'no-loop-func': 'off', 'no-loop-func': 'off',
'@typescript-eslint/no-loop-func': 'error', '@typescript-eslint/no-loop-func': 'error',
'no-loss-of-precision': 'off',
'@typescript-eslint/no-loss-of-precision': 'off',
'no-magic-numbers': 'off',
'@typescript-eslint/no-magic-numbers': 'off',
'no-redeclare': 'off',
'@typescript-eslint/no-redeclare': 'off',
'@typescript-eslint/no-type-alias': 'off', '@typescript-eslint/no-type-alias': 'off',
@ -149,7 +183,6 @@ export default [
curly: 'error', curly: 'error',
'default-case': 'error', 'default-case': 'error',
'default-case-last': 'error', 'default-case-last': 'error',
'dot-notation': 'warn',
eqeqeq: 'error', eqeqeq: 'error',
'func-names': 'warn', 'func-names': 'warn',
'func-style': ['warn', 'declaration'], 'func-style': ['warn', 'declaration'],