Skip to content

Commit

Permalink
Formatting and disabling linting on these files
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-gade committed Jul 24, 2024
1 parent ecf40e6 commit 2efd3f4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 39 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -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"],
Expand Down
18 changes: 8 additions & 10 deletions tests/translations/gettextExtraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 6 additions & 12 deletions tests/translations/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -52,28 +52,24 @@ 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);
});
});

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}`);
}
Expand All @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions tests/translations/tests/twig-t-filter.spec.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
22 changes: 8 additions & 14 deletions tests/translations/translationExtraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ const matchTranslationFilters = (source) => {
return result.sort((a, b) => {
if (a.index < b.index) {
return -1;
} else {
}
return 0;
}

});
};

Expand All @@ -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),
};
}),
})),
);
}

Expand All @@ -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,
};
}),
})),
);
}

Expand Down

0 comments on commit 2efd3f4

Please sign in to comment.