From 2efd3f4e035168473ab6cc3500a7d76efaf4e0ca Mon Sep 17 00:00:00 2001 From: eric-gade Date: Wed, 24 Jul 2024 14:24:56 -0400 Subject: [PATCH] Formatting and disabling linting on these files --- .eslintrc.js | 5 ++++- tests/translations/gettextExtraction.js | 18 +++++++-------- tests/translations/main.js | 18 +++++---------- .../translations/tests/twig-t-filter.spec.js | 5 +++-- tests/translations/translationExtraction.js | 22 +++++++------------ 5 files changed, 29 insertions(+), 39 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 44070261b..e43884175 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,6 +1,9 @@ module.exports = { extends: ["airbnb-base", "prettier"], - ignorePatterns: ["uswds*.js"], + ignorePatterns: [ + "tests/translations/**/*.js", + "uswds*.js" + ], rules: { // For imports in the browser, file extensions are always required. "import/extensions": ["error", "always"], diff --git a/tests/translations/gettextExtraction.js b/tests/translations/gettextExtraction.js index a375db409..f0ec514d9 100644 --- a/tests/translations/gettextExtraction.js +++ b/tests/translations/gettextExtraction.js @@ -12,24 +12,22 @@ const MSG_STR_RX = /msgstr\s+\"(.*)\"/m; * Here a 'block' is any series of contiguous * lines of text that are not just an empty string/newline. */ -const parseGettextBlocks = (str) => { +const parseGettextBlocks = (str) => // We ignore the first block, which is just // the gettext header information - return str.split("\n\n").slice(1); -}; + str.split("\n\n").slice(1) +; const parseGettextSource = (str) => { const results = []; const blocks = parseGettextBlocks(str); blocks.forEach((block) => { - const comments = block.split("\n").filter((line) => { - return line.startsWith("#"); - }); - let msgidString, - msgstrString, - msgid, - msgstr = null; + const comments = block.split("\n").filter((line) => line.startsWith("#")); + let msgidString; + let msgstrString; + let msgid; + let msgstr = null; const msgidMatch = block.match(MSG_ID_RX); if (msgidMatch) { diff --git a/tests/translations/main.js b/tests/translations/main.js index 01f9ae4ee..d11f1ef12 100644 --- a/tests/translations/main.js +++ b/tests/translations/main.js @@ -41,7 +41,7 @@ const translationPaths = config.translations.include const templateLookup = getFileMatchInfo(templatePaths, phpPaths); const translationLookup = getTranslationMatchInfo(translationPaths); const languages = Object.keys(translationLookup); -let errorsSummary = []; +const errorsSummary = []; languages.forEach((langCode) => { console.log(`Checking translation integrity for: ${langCode}`); @@ -52,7 +52,7 @@ languages.forEach((langCode) => { const translationTerms = Object.keys(translations); const templateTerms = Object.keys(templateLookup); - let fileNames = new Set(); + const fileNames = new Set(); templateTerms.forEach((key) => { templateLookup[key].forEach((phrase) => { fileNames.add(phrase.filename); @@ -60,20 +60,16 @@ languages.forEach((langCode) => { }); console.log("Checking for missing translations"); - const missing = templateTerms.filter((key) => { - return !translationTerms.includes(key); - }); + const missing = templateTerms.filter((key) => !translationTerms.includes(key)); if (missing.length) { const errString = `Missing [${missing.length}] translations in the ${langCode} translations file`; errorsSummary.push(errString); - console.error(errString + ":"); + console.error(`${errString }:`); missing.forEach((key) => { const entryList = templateLookup[key]; if (entryList) { - const fileLocations = entryList.map((entry) => { - return `${entry.filename}:${entry.lineNumber}`; - }); + const fileLocations = entryList.map((entry) => `${entry.filename}:${entry.lineNumber}`); const serialized = JSON.stringify(entryList, null, 2); console.error(`${fileLocations.join("\n")}\n${serialized}`); } @@ -82,9 +78,7 @@ languages.forEach((langCode) => { } console.log("Checking for stale translations"); - const stale = translationTerms.filter((key) => { - return !templateTerms.includes(key); - }); + const stale = translationTerms.filter((key) => !templateTerms.includes(key)); if (stale.length) { console.warn( diff --git a/tests/translations/tests/twig-t-filter.spec.js b/tests/translations/tests/twig-t-filter.spec.js index 01ce2fea2..c5a6420ed 100644 --- a/tests/translations/tests/twig-t-filter.spec.js +++ b/tests/translations/tests/twig-t-filter.spec.js @@ -1,7 +1,8 @@ -const { matchTranslationFilters } = require("../translationExtraction.js"); const fs = require("fs"); const path = require("path"); -let assert, expect, should; +const { matchTranslationFilters } = require("../translationExtraction.js"); + +let assert; let expect; let should; import("chai").then((module) => { assert = module.assert; expect = module.expect; diff --git a/tests/translations/translationExtraction.js b/tests/translations/translationExtraction.js index f5c6a4522..18d4136b6 100644 --- a/tests/translations/translationExtraction.js +++ b/tests/translations/translationExtraction.js @@ -41,9 +41,9 @@ const matchTranslationFilters = (source) => { return result.sort((a, b) => { if (a.index < b.index) { return -1; - } else { + } return 0; - } + }); }; @@ -59,15 +59,13 @@ const extractPHPTranslations = (filePath) => { const matches = source.matchAll(PHP_T_FUNCTION_RX); if (matches) { result = result.concat( - Array.from(matches, (match) => { - return { + Array.from(matches, (match) => ({ filename: path.basename(filePath), matchedString: match[0], extracted: match[1], extractedArgs: match[3] | null, lineNumber: getLineNumberForPosition(source, match.index), - }; - }), + })), ); } @@ -85,31 +83,27 @@ const extractTemplateTranslations = (filePath) => { const functionMatches = source.matchAll(TWIG_T_FUNCTION_RX); if (functionMatches) { result = result.concat( - Array.from(functionMatches, (match) => { - return { + Array.from(functionMatches, (match) => ({ filename: path.basename(filePath), matchedString: match[0], extracted: match[1], extractedArgs: match[3] | null, lineNumber: getLineNumberForPosition(source, match.index), index: match.index, - }; - }), + })), ); } const filterMatches = matchTranslationFilters(source); if (filterMatches.length) { result = result.concat( - Array.from(filterMatches, (match) => { - return { + Array.from(filterMatches, (match) => ({ filename: path.basename(filePath), matchedString: match[0], extracted: match[1], extractedArgs: match[3] || null, lineNumber: getLineNumberForPosition(source, match.index), index: match.index, - }; - }), + })), ); }