From 421f3b58d70b4476d17578edbe582b4e78d1ec3b Mon Sep 17 00:00:00 2001 From: VijayKesharwani <122533719+VijayKesharwani@users.noreply.github.com> Date: Thu, 19 Oct 2023 15:28:34 +0530 Subject: [PATCH] updating to look nice output --- lint_function/check-spelling-code.js | 49 +++++++++++----------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/lint_function/check-spelling-code.js b/lint_function/check-spelling-code.js index b81517c245..2ebeeb9b3a 100644 --- a/lint_function/check-spelling-code.js +++ b/lint_function/check-spelling-code.js @@ -11,34 +11,23 @@ function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } export default async function (input) { - return new Promise((resolve, reject) => { - dictionary ((err, dict) => { - if (err) { - reject(err); - return; - } - var spell = nspell(dict) - var no_special_characters= input.replace(/[^\w\s]/gi, '') - const words = no_special_characters.split(separatorsRegex); - var errors= words - .filter((word) => !exceptions.includes(word)) - .filter((word) => !spell.correct(word)) - .filter((word) => !word == '') - .filter((word) => !includesNumber(word)); - - if (errors.length > 0) { - // Concatenate all spelling mistakes into a single string - const mistakesString = errors.join(', '); - // Print the mistakes - console.log("There was a spelling mistake: " + mistakesString); - resolve([{ - message: `Spelling mistakes found: ${mistakesString}`, - }]); - } else { - resolve([{ - message: "No spelling mistakes found!", - }]); - } - }) - }) + dictionary ((err, dict) => { + if (err) { + throw err; + } + var spell = nspell(dict) + var no_special_characters= input.replace(/[^\w\s]/gi, '') + const words = no_special_characters.split(separatorsRegex); + var errors= words + .filter((word) => !exceptions.includes(word)) + .filter((word) => !spell.correct(word)) + .filter((word) => !word == '') + .filter((word) => !includesNumber(word)); + + if ((errors.length > 0) && (mistakes[mistakes.length-1] != errors[errors.length-1])) { + mistakes.push(errors); + errors = []; + console.log("There was a spelling mistake: " + mistakes); + } + }) };