refactor: class-methods-use-this
This commit is contained in:
parent
a42add7131
commit
af57cb5d71
12 changed files with 48 additions and 45 deletions
|
@ -5,6 +5,25 @@ import { LokiLabels } from 'loki-logger-ts';
|
||||||
export class MikroOrmLogger extends DefaultLogger {
|
export class MikroOrmLogger extends DefaultLogger {
|
||||||
private logger: Logger = getLogger();
|
private logger: Logger = getLogger();
|
||||||
|
|
||||||
|
static createMessage(namespace: LoggerNamespace, messageArg: string, context?: LogContext): unknown {
|
||||||
|
const labels: LokiLabels = {
|
||||||
|
service: 'ORM',
|
||||||
|
};
|
||||||
|
|
||||||
|
let message: string;
|
||||||
|
if (context?.label) {
|
||||||
|
message = `[${namespace}] (${context.label}) ${messageArg}`;
|
||||||
|
} else {
|
||||||
|
message = `[${namespace}] ${messageArg}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
message: message,
|
||||||
|
labels: labels,
|
||||||
|
context: context,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
log(namespace: LoggerNamespace, message: string, context?: LogContext): void {
|
log(namespace: LoggerNamespace, message: string, context?: LogContext): void {
|
||||||
if (!this.isEnabled(namespace, context)) {
|
if (!this.isEnabled(namespace, context)) {
|
||||||
return;
|
return;
|
||||||
|
@ -12,28 +31,28 @@ export class MikroOrmLogger extends DefaultLogger {
|
||||||
|
|
||||||
switch (namespace) {
|
switch (namespace) {
|
||||||
case 'query':
|
case 'query':
|
||||||
this.logger.debug(this.createMessage(namespace, message, context));
|
this.logger.debug(MikroOrmLogger.createMessage(namespace, message, context));
|
||||||
break;
|
break;
|
||||||
case 'query-params':
|
case 'query-params':
|
||||||
// TODO Which log level should this be?
|
// TODO Which log level should this be?
|
||||||
this.logger.info(this.createMessage(namespace, message, context));
|
this.logger.info(MikroOrmLogger.createMessage(namespace, message, context));
|
||||||
break;
|
break;
|
||||||
case 'schema':
|
case 'schema':
|
||||||
this.logger.info(this.createMessage(namespace, message, context));
|
this.logger.info(MikroOrmLogger.createMessage(namespace, message, context));
|
||||||
break;
|
break;
|
||||||
case 'discovery':
|
case 'discovery':
|
||||||
this.logger.debug(this.createMessage(namespace, message, context));
|
this.logger.debug(MikroOrmLogger.createMessage(namespace, message, context));
|
||||||
break;
|
break;
|
||||||
case 'info':
|
case 'info':
|
||||||
this.logger.info(this.createMessage(namespace, message, context));
|
this.logger.info(MikroOrmLogger.createMessage(namespace, message, context));
|
||||||
break;
|
break;
|
||||||
case 'deprecated':
|
case 'deprecated':
|
||||||
this.logger.warn(this.createMessage(namespace, message, context));
|
this.logger.warn(MikroOrmLogger.createMessage(namespace, message, context));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
switch (context?.level) {
|
switch (context?.level) {
|
||||||
case 'info':
|
case 'info':
|
||||||
this.logger.info(this.createMessage(namespace, message, context));
|
this.logger.info(MikroOrmLogger.createMessage(namespace, message, context));
|
||||||
break;
|
break;
|
||||||
case 'warning':
|
case 'warning':
|
||||||
this.logger.warn(message);
|
this.logger.warn(message);
|
||||||
|
@ -47,23 +66,4 @@ export class MikroOrmLogger extends DefaultLogger {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private createMessage(namespace: LoggerNamespace, messageArg: string, context?: LogContext): unknown {
|
|
||||||
const labels: LokiLabels = {
|
|
||||||
service: 'ORM',
|
|
||||||
};
|
|
||||||
|
|
||||||
let message: string;
|
|
||||||
if (context?.label) {
|
|
||||||
message = `[${namespace}] (${context?.label}) ${messageArg}`;
|
|
||||||
} else {
|
|
||||||
message = `[${namespace}] ${messageArg}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
message: message,
|
|
||||||
labels: labels,
|
|
||||||
context: context,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ class AudioProcessor extends StringProcessor {
|
||||||
super(DwengoContentType.AUDIO_MPEG);
|
super(DwengoContentType.AUDIO_MPEG);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected renderFn(audioUrl: string): string {
|
override renderFn(audioUrl: string): string {
|
||||||
return DOMPurify.sanitize(`<audio controls>
|
return DOMPurify.sanitize(`<audio controls>
|
||||||
<source src="${audioUrl}" type=${type}>
|
<source src="${audioUrl}" type=${type}>
|
||||||
Your browser does not support the audio element.
|
Your browser does not support the audio element.
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { Category } from 'gift-pegjs';
|
||||||
import { ProcessingError } from '../../processing-error.js';
|
import { ProcessingError } from '../../processing-error.js';
|
||||||
|
|
||||||
export class CategoryQuestionRenderer extends GIFTQuestionRenderer<Category> {
|
export class CategoryQuestionRenderer extends GIFTQuestionRenderer<Category> {
|
||||||
render(_question: Category, _questionNumber: number): string {
|
override render(_question: Category, _questionNumber: number): string {
|
||||||
throw new ProcessingError("The question type 'Category' is not supported yet!");
|
throw new ProcessingError("The question type 'Category' is not supported yet!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { Description } from 'gift-pegjs';
|
||||||
import { ProcessingError } from '../../processing-error.js';
|
import { ProcessingError } from '../../processing-error.js';
|
||||||
|
|
||||||
export class DescriptionQuestionRenderer extends GIFTQuestionRenderer<Description> {
|
export class DescriptionQuestionRenderer extends GIFTQuestionRenderer<Description> {
|
||||||
render(_question: Description, _questionNumber: number): string {
|
override render(_question: Description, _questionNumber: number): string {
|
||||||
throw new ProcessingError("The question type 'Description' is not supported yet!");
|
throw new ProcessingError("The question type 'Description' is not supported yet!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { GIFTQuestionRenderer } from './gift-question-renderer.js';
|
||||||
import { Essay } from 'gift-pegjs';
|
import { Essay } from 'gift-pegjs';
|
||||||
|
|
||||||
export class EssayQuestionRenderer extends GIFTQuestionRenderer<Essay> {
|
export class EssayQuestionRenderer extends GIFTQuestionRenderer<Essay> {
|
||||||
render(question: Essay, questionNumber: number): string {
|
override render(question: Essay, questionNumber: number): string {
|
||||||
let renderedHtml = '';
|
let renderedHtml = '';
|
||||||
if (question.title) {
|
if (question.title) {
|
||||||
renderedHtml += `<h2 class='gift-title' id='gift-q${questionNumber}-title'>${question.title}</h2>\n`;
|
renderedHtml += `<h2 class='gift-title' id='gift-q${questionNumber}-title'>${question.title}</h2>\n`;
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { Matching } from 'gift-pegjs';
|
||||||
import { ProcessingError } from '../../processing-error.js';
|
import { ProcessingError } from '../../processing-error.js';
|
||||||
|
|
||||||
export class MatchingQuestionRenderer extends GIFTQuestionRenderer<Matching> {
|
export class MatchingQuestionRenderer extends GIFTQuestionRenderer<Matching> {
|
||||||
render(_question: Matching, _questionNumber: number): string {
|
override render(_question: Matching, _questionNumber: number): string {
|
||||||
throw new ProcessingError("The question type 'Matching' is not supported yet!");
|
throw new ProcessingError("The question type 'Matching' is not supported yet!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { GIFTQuestionRenderer } from './gift-question-renderer.js';
|
||||||
import { MultipleChoice } from 'gift-pegjs';
|
import { MultipleChoice } from 'gift-pegjs';
|
||||||
|
|
||||||
export class MultipleChoiceQuestionRenderer extends GIFTQuestionRenderer<MultipleChoice> {
|
export class MultipleChoiceQuestionRenderer extends GIFTQuestionRenderer<MultipleChoice> {
|
||||||
render(question: MultipleChoice, questionNumber: number): string {
|
override render(question: MultipleChoice, questionNumber: number): string {
|
||||||
let renderedHtml = '';
|
let renderedHtml = '';
|
||||||
if (question.title) {
|
if (question.title) {
|
||||||
renderedHtml += `<h2 class='gift-title' id='gift-q${questionNumber}-title'>${question.title}</h2>\n`;
|
renderedHtml += `<h2 class='gift-title' id='gift-q${questionNumber}-title'>${question.title}</h2>\n`;
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { Numerical } from 'gift-pegjs';
|
||||||
import { ProcessingError } from '../../processing-error.js';
|
import { ProcessingError } from '../../processing-error.js';
|
||||||
|
|
||||||
export class NumericalQuestionRenderer extends GIFTQuestionRenderer<Numerical> {
|
export class NumericalQuestionRenderer extends GIFTQuestionRenderer<Numerical> {
|
||||||
render(_question: Numerical, _questionNumber: number): string {
|
override render(_question: Numerical, _questionNumber: number): string {
|
||||||
throw new ProcessingError("The question type 'Numerical' is not supported yet!");
|
throw new ProcessingError("The question type 'Numerical' is not supported yet!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { ShortAnswer } from 'gift-pegjs';
|
||||||
import { ProcessingError } from '../../processing-error.js';
|
import { ProcessingError } from '../../processing-error.js';
|
||||||
|
|
||||||
export class ShortQuestionRenderer extends GIFTQuestionRenderer<ShortAnswer> {
|
export class ShortQuestionRenderer extends GIFTQuestionRenderer<ShortAnswer> {
|
||||||
render(_question: ShortAnswer, _questionNumber: number): string {
|
override render(_question: ShortAnswer, _questionNumber: number): string {
|
||||||
throw new ProcessingError("The question type 'ShortAnswer' is not supported yet!");
|
throw new ProcessingError("The question type 'ShortAnswer' is not supported yet!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { TrueFalse } from 'gift-pegjs';
|
||||||
import { ProcessingError } from '../../processing-error.js';
|
import { ProcessingError } from '../../processing-error.js';
|
||||||
|
|
||||||
export class TrueFalseQuestionRenderer extends GIFTQuestionRenderer<TrueFalse> {
|
export class TrueFalseQuestionRenderer extends GIFTQuestionRenderer<TrueFalse> {
|
||||||
render(_question: TrueFalse, _questionNumber: number): string {
|
override render(_question: TrueFalse, _questionNumber: number): string {
|
||||||
throw new ProcessingError("The question type 'TrueFalse' is not supported yet!");
|
throw new ProcessingError("The question type 'TrueFalse' is not supported yet!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,11 +15,20 @@ class MarkdownProcessor extends StringProcessor {
|
||||||
super(DwengoContentType.TEXT_MARKDOWN);
|
super(DwengoContentType.TEXT_MARKDOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static replaceLinks(html: string): string {
|
||||||
|
const proc = new InlineImageProcessor();
|
||||||
|
html = html.replace(
|
||||||
|
/<img.*?src="(.*?)".*?(alt="(.*?)")?.*?(title="(.*?)")?.*?>/g,
|
||||||
|
(_match: string, src: string, _alt: string, _altText: string, _title: string, _titleText: string) => proc.render(src)
|
||||||
|
);
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
override renderFn(mdText: string): string {
|
override renderFn(mdText: string): string {
|
||||||
try {
|
try {
|
||||||
marked.use({ renderer: dwengoMarkedRenderer });
|
marked.use({ renderer: dwengoMarkedRenderer });
|
||||||
const html = marked(mdText, { async: false });
|
const html = marked(mdText, { async: false });
|
||||||
return this.replaceLinks(html); // Replace html image links path
|
return MarkdownProcessor.replaceLinks(html); // Replace html image links path
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
if (e instanceof YAMLException) {
|
if (e instanceof YAMLException) {
|
||||||
throw new ProcessingError(e.message);
|
throw new ProcessingError(e.message);
|
||||||
|
@ -28,15 +37,6 @@ class MarkdownProcessor extends StringProcessor {
|
||||||
throw new ProcessingError('Unknown error while processing markdown: ' + e);
|
throw new ProcessingError('Unknown error while processing markdown: ' + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
replaceLinks(html: string): string {
|
|
||||||
const proc = new InlineImageProcessor();
|
|
||||||
html = html.replace(
|
|
||||||
/<img.*?src="(.*?)".*?(alt="(.*?)")?.*?(title="(.*?)")?.*?>/g,
|
|
||||||
(_match: string, src: string, _alt: string, _altText: string, _title: string, _titleText: string) => proc.render(src)
|
|
||||||
);
|
|
||||||
return html;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export { MarkdownProcessor };
|
export { MarkdownProcessor };
|
||||||
|
|
|
@ -35,6 +35,9 @@ export default [
|
||||||
'@typescript-eslint/array-type': 'warn',
|
'@typescript-eslint/array-type': 'warn',
|
||||||
'@typescript-eslint/await-thenable': 'error',
|
'@typescript-eslint/await-thenable': 'error',
|
||||||
|
|
||||||
|
'class-methods-use-this': 'off',
|
||||||
|
'@typescript-eslint/class-methods-use-this': [ 'error', { ignoreOverrideMethods: true } ],
|
||||||
|
|
||||||
'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',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue