From 2266b98896e9eab668b827fd5aaad6de4d7486fa Mon Sep 17 00:00:00 2001 From: VijayKesharwani <122533719+VijayKesharwani@users.noreply.github.com> Date: Fri, 27 Oct 2023 14:35:53 +0530 Subject: [PATCH] Update check-telco-specific-terms.js --- lint_function/check-telco-specific-terms.js | 32 +++++++++++++-------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/lint_function/check-telco-specific-terms.js b/lint_function/check-telco-specific-terms.js index 286b0ad8ba..d9886050dd 100644 --- a/lint_function/check-telco-specific-terms.js +++ b/lint_function/check-telco-specific-terms.js @@ -1,8 +1,17 @@ export default async function (input) { const errors = []; const suggestions = []; - let mobileNetworkFound = false; - let msisdnFound = false; + const replacements = [ + { original: 'mobile network', recommended: 'network' }, + { original: 'MSISDN', recommended: 'phone number' } + ]; + + const termFlags = {}; // Store flags for each replacement term + + // Initialize flags to false for all replacement terms + replacements.forEach(replacement => { + termFlags[replacement.original] = false; + }); // Iterate over properties of the input object for (const path in input) { @@ -10,21 +19,20 @@ export default async function (input) { // Check if the value is a string if (typeof value === 'string') { - if (value.includes('mobile network') && !mobileNetworkFound) { - errors.push({ original: 'mobile network', recommended: 'network' }); - suggestions.push(`Consider replacing 'mobile network' with 'network'.`); - mobileNetworkFound = true; - } + for (const replacement of replacements) { + const original = replacement.original; - if (value.includes('MSISDN') && !msisdnFound) { - errors.push({ original: 'MSISDN', recommended: 'phone number' }); - suggestions.push(`Consider replacing 'MSISDN' with 'phone number'.`); - msisdnFound = true; + // Check if the term is not flagged and exists in the value + if (!termFlags[original] && value.includes(original)) { + errors.push(replacement); + suggestions.push(`Consider replacing '${original}' with '${replacement.recommended}'.`); + termFlags[original] = true; // Set the flag to true + } } } } - // Check if any word from 'replacements' is in the suggestions + // Check if any words from 'replacements' are in the suggestions if (errors.length > 0) { console.log('Hint: Telco-specific terminology found in input: ' + suggestions.join(', ')); }