From 0eb07088ee3e324a10f90b1b384dc372a0d717a5 Mon Sep 17 00:00:00 2001 From: Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com> Date: Wed, 11 Dec 2024 21:50:55 -0600 Subject: [PATCH] More code formatting error detection tweaks --- src/components/formatting-error-detection.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/formatting-error-detection.ts b/src/components/formatting-error-detection.ts index 9cf2411..c5b447e 100644 --- a/src/components/formatting-error-detection.ts +++ b/src/components/formatting-error-detection.ts @@ -60,6 +60,11 @@ export default class FormattingErrorDetection extends BotComponent { new dismark.TextRule(), ]); + static has_enough_special_characters_to_likely_be_code(content: string) { + const count = (content.match(/[()[\];{}]/g) ?? []).length; + return count / content.length >= 0.05 && count >= 6; + } + static has_likely_format_errors(content: string) { // early return if (content.search(/['"`]{2}/) === -1) { @@ -95,12 +100,12 @@ export default class FormattingErrorDetection extends BotComponent { case "code_block": if (node.language !== null) { has_properly_formatted_code_blocks = true; - } else if ((node.content.match(/[()[\];*+.]/g) ?? []).length / node.content.length >= 0.05) { + } else if (this.has_enough_special_characters_to_likely_be_code(node.content)) { has_likely_format_mistakes = true; } break; case "failed_code_block": - if ((node.content.match(/[()[\];*+.]/g) ?? []).length / node.content.length >= 0.05) { + if (this.has_enough_special_characters_to_likely_be_code(node.content)) { has_likely_format_mistakes = true; } break;