diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c07b0e..b9e4ac0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,7 @@ name: Tests jobs: test: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest name: Node ${{ matrix.node }} strategy: matrix: @@ -23,7 +23,7 @@ jobs: - run: npm test test-targets: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest name: ${{ matrix.targets.name }} strategy: matrix: diff --git a/bin/applyBabelJob.js b/bin/applyBabelJob.js index e170914..65f2ecd 100755 --- a/bin/applyBabelJob.js +++ b/bin/applyBabelJob.js @@ -13,7 +13,7 @@ const urlTools = require('urltools'); const commandLineOptions = require('optimist') .usage( - '$0 --i18n [--locales [,...]] [--defaultlocale ] --babeldir= --root ...' + '$0 --i18n [--locales [,...]] [--defaultlocale ] --babeldir= --root ...', ) .options('defaultlocale', { describe: @@ -33,8 +33,8 @@ const localeIds = commandLineOptions.locales && _.flatten( _.flatten([commandLineOptions.locales]).map((localeId) => - localeId.split(',') - ) + localeId.split(','), + ), ).map(i18nTools.normalizeLocaleId); const initialAssetUrls = commandLineOptions._.map(urlTools.fsFilePathToFileUrl); @@ -44,13 +44,13 @@ let i18nUrl; if (commandLineOptions.defaultlocale) { defaultLocaleId = i18nTools.normalizeLocaleId( - commandLineOptions.defaultlocale + commandLineOptions.defaultlocale, ); if (localeIds && localeIds.indexOf(defaultLocaleId) === -1) { throw new Error( `The default locale id (${defaultLocaleId}) is not among the locales listed with the --locales switch (${localeIds.join( - ', ' - )})` + ', ', + )})`, ); } } else if (localeIds) { @@ -108,7 +108,7 @@ if (commandLineOptions.i18n) { const occurrencesByKey = i18nTools.findOccurrences( assetGraph, - assetGraph.findAssets({ type: 'Html', isInitial: true }) + assetGraph.findAssets({ type: 'Html', isInitial: true }), ); let i18nAssetForAllKeys; @@ -124,7 +124,7 @@ if (commandLineOptions.i18n) { assetGraph.addAsset(i18nAssetForAllKeys); assetGraph.emit( 'info', - `--i18n ${commandLineOptions.i18n} not found, creating it` + `--i18n ${commandLineOptions.i18n} not found, creating it`, ); } else if (!i18nAssetForAllKeys.isLoaded) { i18nAssetForAllKeys.parseTree = {}; @@ -143,14 +143,14 @@ if (commandLineOptions.i18n) { const babelBody = fs.readFileSync( path.resolve(commandLineOptions.babeldir, fileName), - 'utf-8' + 'utf-8', ); isSeenByLocaleId[localeId] = true; if (localeIds && localeIds.indexOf(localeId) === -1) { console.warn( - `Skipping ${fileName} because ${localeId} was not mentioned in --locales` + `Skipping ${fileName} because ${localeId} was not mentioned in --locales`, ); return; } @@ -192,7 +192,7 @@ if (commandLineOptions.i18n) { throw new Error( `Error: Expected ${JSON.stringify(cursor)}['${ path[0] - }'] to be undefined or an array while processing line ${lineNumber} of ${fileName}:\n${line}` + }'] to be undefined or an array while processing line ${lineNumber} of ${fileName}:\n${line}`, ); } } else { @@ -206,7 +206,7 @@ if (commandLineOptions.i18n) { throw new Error( `Error: Expected ${JSON.stringify(cursor)}['${ path[0] - }'] to be undefined or an object while processing line ${lineNumber} of ${fileName}:\n${line}` + }'] to be undefined or an object while processing line ${lineNumber} of ${fileName}:\n${line}`, ); } } @@ -214,7 +214,7 @@ if (commandLineOptions.i18n) { } if (path[0] in cursor) { throw new Error( - `Error: Found double declaration of key in line ${lineNumber} of ${fileName}:\n${line}` + `Error: Found double declaration of key in line ${lineNumber} of ${fileName}:\n${line}`, ); } cursor[path[0]] = value; @@ -222,14 +222,14 @@ if (commandLineOptions.i18n) { console.warn( `Couldn't parse line ${ lineNumber + 1 - } of the ${localeId} file: ${line}` + } of the ${localeId} file: ${line}`, ); } } }); } else { console.warn( - `Skipping file whose basename does not look like a locale id: ${fileName}` + `Skipping file whose basename does not look like a locale id: ${fileName}`, ); } } @@ -238,7 +238,7 @@ if (commandLineOptions.i18n) { localeIds.forEach((localeId) => { if (!isSeenByLocaleId[localeId]) { console.warn( - `${localeId}.txt was not found although --locales ${localeId} was specified` + `${localeId}.txt was not found although --locales ${localeId} was specified`, ); } }); @@ -266,7 +266,7 @@ if (commandLineOptions.i18n) { keys.every( (key) => ['zero', 'one', 'two', 'few', 'many', 'other'].indexOf(key) !== - -1 + -1, ) ) { keys = []; @@ -279,7 +279,7 @@ if (commandLineOptions.i18n) { `${key}: Discarding plural forms not used in ${localeId}:`, obj, '=>', - coalescedObj + coalescedObj, ); } obj = coalescedObj; @@ -336,8 +336,8 @@ if (commandLineOptions.i18n) { _.merge( Array.isArray(newTranslation) ? [] : {}, existingTranslation, - newTranslation - ) + newTranslation, + ), ); } else if ( typeof existingTranslation === 'undefined' || @@ -404,7 +404,7 @@ if (commandLineOptions.i18n) { if ( !_.isEqual( occurrence.defaultValue, - allKeysInDefaultLocale[occurrence.key] + allKeysInDefaultLocale[occurrence.key], ) ) { if (occurrence.type === 'TR' || occurrence.type === 'TRPAT') { @@ -413,9 +413,9 @@ if (commandLineOptions.i18n) { const replaceRegExp = new RegExp( `(TR(?:PAT)?\\((['"])${key.replace( /[.[\]*+?{}()^$]/g, - '\\$&' + '\\$&', )}\\2\\s*,\\s*)(?:[^)'"]*|"[^"]*"|'[^']*')*?\\)`, - 'g' + 'g', ); replacedTextByAssetId[asset.id] = ( @@ -425,8 +425,8 @@ if (commandLineOptions.i18n) { ).replace( replaceRegExp, `$1${util.inspect( - translationsByKeyAndLocaleId[key][defaultLocaleId] - )})` + translationsByKeyAndLocaleId[key][defaultLocaleId], + )})`, ); } } @@ -446,7 +446,7 @@ if (commandLineOptions.i18n) { $0 .replace(/</g, '<') .replace(/>/g, '>') - .replace(/&/g, '&') + .replace(/&/g, '&'), ); } asset._rawSrc = replacedText.toString('utf-8'); diff --git a/bin/checkLanguageKeys.js b/bin/checkLanguageKeys.js index a293f61..f0cff29 100755 --- a/bin/checkLanguageKeys.js +++ b/bin/checkLanguageKeys.js @@ -56,8 +56,8 @@ const localeIds = commandLineOptions.locales && _.flatten( _.flatten([commandLineOptions.locales]).map((localeId) => - localeId.split(',') - ) + localeId.split(','), + ), ).map(i18nTools.normalizeLocaleId); const defaultLocaleId = @@ -68,43 +68,43 @@ const ignoreMessageTypes = commandLineOptions.ignore && _.flatten( _.flatten([commandLineOptions.ignore]).map((ignoreMessageType) => - ignoreMessageType.split(',') - ) + ignoreMessageType.split(','), + ), ); const warnMessageTypes = commandLineOptions.warn && _.flatten( _.flatten([commandLineOptions.warn]).map((warnMessageType) => - warnMessageType.split(',') - ) + warnMessageType.split(','), + ), ); const includeAttributeNames = commandLineOptions.includeattribute && _.flatten( _.flatten([commandLineOptions.includeattribute]).map((attributeName) => - attributeName.split(',') - ) + attributeName.split(','), + ), ); const excludeAttributeNames = commandLineOptions.excludeattribute && _.flatten( _.flatten([commandLineOptions.excludeattribute]).map((attributeName) => - attributeName.split(',') - ) + attributeName.split(','), + ), ); let inputUrls; if (commandLineOptions._.length > 0) { inputUrls = commandLineOptions._.map((urlOrFsPath) => - urlTools.urlOrFsPathToUrl(urlOrFsPath, false) + urlTools.urlOrFsPathToUrl(urlOrFsPath, false), ); if (!rootUrl) { rootUrl = urlTools.findCommonUrlPrefix( - inputUrls.filter((inputUrl) => /^file:/.test(inputUrl)) + inputUrls.filter((inputUrl) => /^file:/.test(inputUrl)), ); if (rootUrl) { console.warn(`Guessing --root from input files: ${rootUrl}`); @@ -115,7 +115,7 @@ if (commandLineOptions._.length > 0) { console.warn(`No input files specified, defaulting to ${inputUrls[0]}`); } else { throw new Error( - "No input files and no --root specified (or it isn't file:), cannot proceed" + "No input files and no --root specified (or it isn't file:), cannot proceed", ); } diff --git a/bin/makeBabelJob.js b/bin/makeBabelJob.js index 1f31fbc..45010cb 100755 --- a/bin/makeBabelJob.js +++ b/bin/makeBabelJob.js @@ -11,7 +11,7 @@ const pluralsCldr = require('plurals-cldr'); const commandLineOptions = require('optimist') .usage( - '$0 --i18n [--all] [--defaultlocale ] --babeldir= --root --locales ,... ...' + '$0 --i18n [--all] [--defaultlocale ] --babeldir= --root --locales ,... ...', ) .boolean('all') .demand(['root', 'locales', 'babeldir', 'i18n']).argv; @@ -20,8 +20,8 @@ const localeIds = commandLineOptions.locales && _.flatten( _.flatten([commandLineOptions.locales]).map((localeId) => - localeId.split(',') - ) + localeId.split(','), + ), ).map(i18nTools.normalizeLocaleId); const initialAssetUrls = commandLineOptions._.map(urlTools.fsFilePathToFileUrl); @@ -30,13 +30,13 @@ let i18nUrl; if (commandLineOptions.defaultlocale) { defaultLocaleId = i18nTools.normalizeLocaleId( - commandLineOptions.defaultlocale + commandLineOptions.defaultlocale, ); if (localeIds && localeIds.indexOf(defaultLocaleId) === -1) { throw new Error( `The default locale id (${defaultLocaleId}) is not among the locales listed with the --locales switch (${localeIds.join( - ', ' - )})` + ', ', + )})`, ); } } else if (localeIds) { @@ -61,7 +61,7 @@ function coalescePluralsToLocale(value, localeId, pluralFormsToInclude) { keys.length > 0 && keys.every( (key) => - ['zero', 'one', 'two', 'few', 'many', 'other'].indexOf(key) !== -1 + ['zero', 'one', 'two', 'few', 'many', 'other'].indexOf(key) !== -1, ) ) { keys = []; @@ -96,7 +96,7 @@ function valueContainsPlurals(obj) { keys.length > 0 && keys.every( (key) => - ['zero', 'one', 'two', 'few', 'many', 'other'].indexOf(key) !== -1 + ['zero', 'one', 'two', 'few', 'many', 'other'].indexOf(key) !== -1, ) ) { return true; @@ -139,8 +139,8 @@ function getLeavesFrom(obj, otherObject) { item, Array.isArray(otherObject) ? nullIfNullOrUndefined(otherObject[i]) - : null - ) + : null, + ), ); } else if (typeof obj === 'object' && obj !== null) { const resultObj = {}; @@ -149,7 +149,7 @@ function getLeavesFrom(obj, otherObject) { obj[propertyName], otherObject && typeof otherObject === 'object' ? nullIfNullOrUndefined(otherObject[propertyName]) - : null + : null, ); }); return resultObj; @@ -188,7 +188,7 @@ const pluralFormsInTheDefaultLocale = pluralsCldr.forms(defaultLocaleId); const relevantPluralFormsNotInTheDefaultLocale = _.difference( _.union(...localeIds.map((localeId) => pluralsCldr.forms(localeId))), - pluralFormsInTheDefaultLocale + pluralFormsInTheDefaultLocale, ); (async () => { @@ -240,7 +240,7 @@ const relevantPluralFormsNotInTheDefaultLocale = _.difference( assetGraph.addAsset(i18nAssetForAllKeys); assetGraph.emit( 'info', - `--i18n ${commandLineOptions.i18n} not found, creating it` + `--i18n ${commandLineOptions.i18n} not found, creating it`, ); } else if (!i18nAssetForAllKeys.isLoaded) { i18nAssetForAllKeys.parseTree = {}; @@ -285,7 +285,7 @@ const relevantPluralFormsNotInTheDefaultLocale = _.difference( isTranslatedByFlattenedKeyByLocaleId[localeId] || {}; const flattenedAndCoalesced = flattenKey( key, - coalescePluralsToLocale(value, localeId) + coalescePluralsToLocale(value, localeId), ); Object.keys(flattenedAndCoalesced).forEach((flattenedKey) => { @@ -306,7 +306,7 @@ const relevantPluralFormsNotInTheDefaultLocale = _.difference( alreadyTranslatedByFlattenedKey[flattenedKey] = localeIds.every( (localeId) => !isRelevantInLocaleByFlattenedKeyByLocaleId[localeId][flattenedKey] || - isTranslatedByFlattenedKeyByLocaleId[localeId][flattenedKey] + isTranslatedByFlattenedKeyByLocaleId[localeId][flattenedKey], ); }); @@ -370,15 +370,15 @@ const relevantPluralFormsNotInTheDefaultLocale = _.difference( if (typeof defaultValueInTheOccurrence !== 'undefined') { defaultValueInTheOccurrence = coalescePluralsToLocale( defaultValueInTheOccurrence, - localeId + localeId, ); defaultValueInTheOccurrenceByFlattenedKey = flattenKey( key, - defaultValueInTheOccurrence + defaultValueInTheOccurrence, ); flattenedKeysThatMustBePresent = _.union( Object.keys(defaultValueInTheOccurrenceByFlattenedKey), - flattenedKeysThatMustBePresent + flattenedKeysThatMustBePresent, ); } @@ -426,9 +426,9 @@ const relevantPluralFormsNotInTheDefaultLocale = _.difference( coalescePluralsToLocale( defaultValueInTheOccurrence, localeId, - pluralForm - ) - ) + pluralForm, + ), + ), ); const existingTranslationByFlattenedKey = @@ -451,7 +451,7 @@ const relevantPluralFormsNotInTheDefaultLocale = _.difference( localeIds.sort(); (flattenedKeysByJoinedLocaleIds[localeIds.join(',')] = flattenedKeysByJoinedLocaleIds[localeIds.join(',')] || []).push( - flattenedKey + flattenedKey, ); }); @@ -471,7 +471,7 @@ const relevantPluralFormsNotInTheDefaultLocale = _.difference( } to cover all plural forms:\n${flattenedKeys .map((flattenedKey) => `# ${flattenedKey}=\n`) .join('')}`; - } + }, ); } @@ -497,12 +497,12 @@ const relevantPluralFormsNotInTheDefaultLocale = _.difference( } else { if (omitExistingValues) { newValue = nullOutLeaves( - coalescePluralsToLocale(value, localeId) + coalescePluralsToLocale(value, localeId), ); } else { newValue = getLeavesFrom( coalescePluralsToLocale(defaultValue, localeId), - value + value, ); } i18nAssetForKey.parseTree[key][localeId] = newValue; @@ -512,7 +512,7 @@ const relevantPluralFormsNotInTheDefaultLocale = _.difference( const existingValue = i18nAssetForKey.parseTree[key][localeId]; newValue = nullOutLeaves( coalescePluralsToLocale(existingValue, localeId), - true + true, ); i18nAssetForKey.parseTree[key][localeId] = newValue; i18nAssetForKey.markDirty(); @@ -521,14 +521,14 @@ const relevantPluralFormsNotInTheDefaultLocale = _.difference( }); const targetBabelFileName = path.resolve( commandLineOptions.babeldir, - `${localeId}.txt` + `${localeId}.txt`, ); if (babelSrc.length) { console.warn(`Writing ${targetBabelFileName}`); fs.writeFileSync(targetBabelFileName, babelSrc, 'utf-8'); } else { console.warn( - `No existing keys for ${localeId}, not writing ${targetBabelFileName}` + `No existing keys for ${localeId}, not writing ${targetBabelFileName}`, ); } }); diff --git a/i18n.js b/i18n.js index b8d75a3..13ab244 100644 --- a/i18n.js +++ b/i18n.js @@ -26,7 +26,7 @@ function createTr(localeData) { valueString = JSON.stringify(pattern); } catch (e) {} throw new Error( - 'i18nTools.tokenizePattern: Value must be a string: ' + valueString + 'i18nTools.tokenizePattern: Value must be a string: ' + valueString, ); } const tokens = []; @@ -93,7 +93,7 @@ function createTr(localeData) { // Use window.TRHTML instead of TRHTML to prevent the recursive call from being recognized as a relation: node.firstChild.nodeValue = window.TR.HTML(node.firstChild.nodeValue); } - } + }, ); return div.innerHTML; }; @@ -123,7 +123,7 @@ module.exports = { function (str, matchedLocale) { load.metadata.locale = matchedLocale; return '.i18n'; - } + }, ); return fetch({ address: load.metadata.newAddress, metadata: {} }); }, @@ -137,7 +137,7 @@ module.exports = { createTr.toString() + ')(' + JSON.stringify( - gatherKeysForLocale(JSON.parse(load.source), load.metadata.locale) + gatherKeysForLocale(JSON.parse(load.source), load.metadata.locale), ) + ');' ); @@ -147,7 +147,7 @@ module.exports = { instantiate: function (load) { if (!this.builder) { return createTr( - gatherKeysForLocale(JSON.parse(load.source), load.metadata.locale) + gatherKeysForLocale(JSON.parse(load.source), load.metadata.locale), ); } }, diff --git a/lib/createI18nTagReplacer.js b/lib/createI18nTagReplacer.js index eab10d1..6e0f322 100644 --- a/lib/createI18nTagReplacer.js +++ b/lib/createI18nTagReplacer.js @@ -45,7 +45,7 @@ module.exports = function createI18nTagReplacer(options) { } } else { nodeToInsert = node.ownerDocument.createTextNode( - '[!{' + token.value + '}!]' + '[!{' + token.value + '}!]', ); } } diff --git a/lib/eachI18nTagInHtmlDocument.js b/lib/eachI18nTagInHtmlDocument.js index dc4ee84..a1d97e1 100644 --- a/lib/eachI18nTagInHtmlDocument.js +++ b/lib/eachI18nTagInHtmlDocument.js @@ -1,7 +1,7 @@ module.exports = function eachI18nTagInHtmlDocument( document, lambda, - nestedTemplateLambda + nestedTemplateLambda, ) { const ELEMENT_NODE = 1; const TEXT_NODE = 3; @@ -26,7 +26,7 @@ module.exports = function eachI18nTagInHtmlDocument( 'i18nTools.eachI18nTagInHtmlDocument: Error evaluating data-i18n attribute: ' + i18nStr + '\n' + - e.stack + e.stack, ); } } else { diff --git a/lib/i18nTools.js b/lib/i18nTools.js index cec4558..5cbafd4 100644 --- a/lib/i18nTools.js +++ b/lib/i18nTools.js @@ -99,7 +99,7 @@ function extractKeyAndDefaultValueFromCallNode(callNode) { 'Invalid ' + escodegen.generate(callNode.callee) + ' syntax: ' + - escodegen.generate(callNode) + escodegen.generate(callNode), ); } else { const keyNameAst = argumentAsts.length > 0 && foldConstant(argumentAsts[0]); @@ -117,14 +117,14 @@ function extractKeyAndDefaultValueFromCallNode(callNode) { if (defaultValueAst) { try { keyAndDefaultValue.defaultValue = esanimate.objectify( - foldConstant(defaultValueAst) + foldConstant(defaultValueAst), ); } catch (e) { console.warn( 'i18nTools.eachTrInAst: Invalid ' + escodegen.generate(callNode.callee) + ' default value syntax: ' + - escodegen.generate(callNode) + escodegen.generate(callNode), ); } } @@ -134,7 +134,7 @@ function extractKeyAndDefaultValueFromCallNode(callNode) { 'i18nTools.eachTrInAst: Invalid ' + escodegen.generate(callNode.callee) + ' key name syntax: ' + - escodegen.generate(callNode) + escodegen.generate(callNode), ); } } @@ -161,7 +161,7 @@ i18nTools.eachTrInAst = function (ast, lambda) { type: 'callTR.PAT', node, parentNode, - }) + }), ) === false ) { return this.break(); @@ -180,7 +180,7 @@ i18nTools.eachTrInAst = function (ast, lambda) { type: 'TR', node, parentNode, - }) + }), ) === false ) { return this.break(); @@ -202,7 +202,7 @@ i18nTools.eachTrInAst = function (ast, lambda) { type: 'TR.PAT', node, parentNode, - }) + }), ) === false ) { return this.break(); @@ -282,14 +282,14 @@ i18nTools.createTrReplacer = function (options) { // Replace TR.PAT('keyName')(placeHolderValue, ...) with a string concatenation: if (valueAst.type !== 'Literal' || typeof valueAst.value !== 'string') { console.warn( - 'trReplacer: Invalid TR.PAT syntax: ' + escodegen.generate(node) + 'trReplacer: Invalid TR.PAT syntax: ' + escodegen.generate(node), ); return; } replaceDescendantNode( parentNode, node, - i18nTools.patternToAst(valueAst.value, node.arguments) + i18nTools.patternToAst(valueAst.value, node.arguments), ); } else if (type === 'TR') { replaceDescendantNode(parentNode, node, valueAst); @@ -377,7 +377,7 @@ i18nTools.findOccurrences = function (assetGraph, initialAssets) { (trOccurrencesByKey[occurrence.key] = trOccurrencesByKey[occurrence.key] || []).push(occurrence); } - } + }, ); } } diff --git a/lib/index.js b/lib/index.js index a34bae6..e641787 100644 --- a/lib/index.js +++ b/lib/index.js @@ -41,11 +41,11 @@ module.exports = function i18n(assetGraph, buildProductionOptions) { i18nTools.createI18nTagReplacer({ allKeysForLocale: i18nTools.extractAllKeysForLocale( assetGraph, - localeId + localeId, ), localeId, defaultLocaleId, - }) + }), ); asset.markDirty(); }); diff --git a/lib/mkpathSync.js b/lib/mkpathSync.js index 42fb6f5..cd1570e 100644 --- a/lib/mkpathSync.js +++ b/lib/mkpathSync.js @@ -14,7 +14,7 @@ function mkpathSync(p, permissions) { if (fragments.length > 1) { mkpathSync( fragments.slice(0, fragments.length - 1).join('/'), - permissions + permissions, ); fs.mkdirSync(p, permissions); } diff --git a/lib/tokenizePattern.js b/lib/tokenizePattern.js index ab0f268..2c4ce7e 100644 --- a/lib/tokenizePattern.js +++ b/lib/tokenizePattern.js @@ -5,7 +5,7 @@ module.exports = function tokenizePattern(pattern) { valueString = JSON.stringify(pattern); } catch (e) {} throw new Error( - 'i18nTools.tokenizePattern: Value must be a string: ' + valueString + 'i18nTools.tokenizePattern: Value must be a string: ' + valueString, ); } const tokens = []; diff --git a/lib/transforms/checkLanguageKeys.js b/lib/transforms/checkLanguageKeys.js index f5153c5..1c99cb2 100644 --- a/lib/transforms/checkLanguageKeys.js +++ b/lib/transforms/checkLanguageKeys.js @@ -68,9 +68,9 @@ module.exports = function (options) { _.difference( normalizeToArray(options.includeAttributeNames).concat( - defaultAttributeNamesThatMustBeTranslated + defaultAttributeNamesThatMustBeTranslated, ), - normalizeToArray(options.excludeAttributeNames) + normalizeToArray(options.excludeAttributeNames), ).forEach(function (attributeName) { mustBeTranslatedByAttributeName[attributeName] = true; }); @@ -87,7 +87,7 @@ module.exports = function (options) { supportedLocaleIds.forEach(function (localeId) { allKeysByLocaleId[localeId] = i18nTools.extractAllKeysForLocale( assetGraph, - localeId + localeId, ); }); @@ -190,7 +190,7 @@ module.exports = function (options) { return _.uniq( occurrences.map(function (occurrence) { return occurrence.asset.urlOrDescription; - }) + }), ).join(' '); } @@ -204,8 +204,8 @@ module.exports = function (options) { localeIdsByMissingKey[missingKey].join(',') + ' (used in ' + getAssetUrlStringForKey(missingKey) + - ')' - ) + ')', + ), ); }); @@ -219,32 +219,32 @@ module.exports = function (options) { localeIdsByUntranslatedKey[untranslatedKey].join(',') + ' (used in ' + getAssetUrlStringForKey(untranslatedKey) + - ')' - ) + ')', + ), ); }); - Object.keys(whitespaceWarningsByKey).forEach(function ( - whitespaceWarningKey - ) { - emitEvent( - 'whitespace', - new Error( - 'Language key ' + - whitespaceWarningKey + - ' has leading or trailing whitespace: ' + - util.inspect( - _.map( - whitespaceWarningsByKey[whitespaceWarningKey], - 'value' - ).join(', ') - ) + - ' (used in ' + - getAssetUrlStringForKey(whitespaceWarningKey) + - ')' - ) - ); - }); + Object.keys(whitespaceWarningsByKey).forEach( + function (whitespaceWarningKey) { + emitEvent( + 'whitespace', + new Error( + 'Language key ' + + whitespaceWarningKey + + ' has leading or trailing whitespace: ' + + util.inspect( + _.map( + whitespaceWarningsByKey[whitespaceWarningKey], + 'value', + ).join(', '), + ) + + ' (used in ' + + getAssetUrlStringForKey(whitespaceWarningKey) + + ')', + ), + ); + }, + ); const allKeys = {}; const i18nAssetByKey = {}; @@ -262,8 +262,8 @@ module.exports = function (options) { i18nAsset.urlOrDescription + ' (first seen in ' + i18nAssetByKey[key].urlOrDescription + - ')' - ) + ')', + ), ); } else { allKeys[key] = i18nAsset.parseTree[key]; @@ -279,8 +279,8 @@ module.exports = function (options) { 'Unused language key in ' + i18nAsset.urlOrDescription + ': ' + - key - ) + key, + ), ); if (options.removeUnused) { numUnusedKeysRemoved += 1; @@ -293,7 +293,7 @@ module.exports = function (options) { function checkThatValuesAreStructurallySimilar( values, - pathFragments + pathFragments, ) { const explodedKey = key + @@ -334,48 +334,48 @@ module.exports = function (options) { .sort(); if (!_.isEqual(actualKeys, expectedKeys)) { - _.difference(actualKeys, expectedKeys).forEach(function ( - extraKey - ) { - emitEvent( - 'warn', - new Error( - localeId + - ' should not have ' + - explodedKey + - '[' + - extraKey + - ']=' + - util.inspect(value[extraKey], false, 99) - ) - ); - }); - _.difference(expectedKeys, actualKeys).forEach(function ( - missingKey - ) { - emitEvent( - 'warn', - new Error( - localeId + - ' is missing ' + - explodedKey + - '[' + - missingKey + - ']' - ) - ); - }); + _.difference(actualKeys, expectedKeys).forEach( + function (extraKey) { + emitEvent( + 'warn', + new Error( + localeId + + ' should not have ' + + explodedKey + + '[' + + extraKey + + ']=' + + util.inspect(value[extraKey], false, 99), + ), + ); + }, + ); + _.difference(expectedKeys, actualKeys).forEach( + function (missingKey) { + emitEvent( + 'warn', + new Error( + localeId + + ' is missing ' + + explodedKey + + '[' + + missingKey + + ']', + ), + ); + }, + ); } }); } else { const keysPresentInOneOrMoreValues = _.union.apply( _, - values.map(Object.keys) + values.map(Object.keys), ); values.forEach(function (value, i) { _.difference( keysPresentInOneOrMoreValues, - Object.keys(value) + Object.keys(value), ).forEach(function (missingKey) { emitEvent( 'warn', @@ -385,28 +385,30 @@ module.exports = function (options) { explodedKey + '[' + missingKey + - ']' - ) + ']', + ), ); }); }); - keysPresentInOneOrMoreValues.forEach(function ( - keyPresentInOneOrMoreValues - ) { - checkThatValuesAreStructurallySimilar( - values.map(function (value) { - return value[keyPresentInOneOrMoreValues]; - }), - pathFragments.concat(keyPresentInOneOrMoreValues) - ); - }); + keysPresentInOneOrMoreValues.forEach( + function (keyPresentInOneOrMoreValues) { + checkThatValuesAreStructurallySimilar( + values.map(function (value) { + return value[keyPresentInOneOrMoreValues]; + }), + pathFragments.concat(keyPresentInOneOrMoreValues), + ); + }, + ); } } else { values.forEach(function (value, i) { if (value && typeof value === 'object') { emitEvent( 'warn', - new Error(localeIds[i] + ' has an object at ' + explodedKey) + new Error( + localeIds[i] + ' has an object at ' + explodedKey, + ), ); } }); @@ -416,7 +418,7 @@ module.exports = function (options) { localeIds.map(function (localeId) { return valueByLocaleId[localeId]; }), - [] + [], ); }); if (numUnusedKeysRemoved > 0) { @@ -428,8 +430,8 @@ module.exports = function (options) { ' unused language key' + (numUnusedKeysRemoved > 1 ? 's' : '') + ' from ' + - i18nAsset.urlOrDescription - ) + i18nAsset.urlOrDescription, + ), ); } }); @@ -458,7 +460,7 @@ module.exports = function (options) { if ( !_.isEqual( defaultValueInfos[i].value, - defaultValueInfos[i + 1].value + defaultValueInfos[i + 1].value, ) ) { allValuesAreIdentical = false; @@ -467,7 +469,7 @@ module.exports = function (options) { } if (allValuesAreIdentical) { const stringifiedDefaultLocaleValue = JSON.stringify( - canonicalizeObject(defaultValueInfos[i].value) + canonicalizeObject(defaultValueInfos[i].value), ); (keysByStringifiedDefaultLocaleValue[stringifiedDefaultLocaleValue] = keysByStringifiedDefaultLocaleValue[ @@ -480,11 +482,11 @@ module.exports = function (options) { const stringifiedValue = util.inspect( defaultValueInfo.value, false, - 99 + 99, ); (defaultValueInfosByStringifiedValue[stringifiedValue] = defaultValueInfosByStringifiedValue[stringifiedValue] || []).push( - defaultValueInfo + defaultValueInfo, ); }); defaultValueMismatchInfos[key] = defaultValueInfosByStringifiedValue; @@ -492,59 +494,62 @@ module.exports = function (options) { }); // Report info messages - Object.keys(keysByStringifiedDefaultLocaleValue).forEach(function ( - stringifiedDefaultLocaleValue - ) { - const keys = - keysByStringifiedDefaultLocaleValue[stringifiedDefaultLocaleValue]; - if (keys.length > 1) { - const defaultValue = JSON.parse(stringifiedDefaultLocaleValue); - emitEvent( - 'sameDefaultValue', - new Error( - keys.length + - ' language keys have the same default value ' + - util.inspect(defaultValue) + - '\n ' + - keys - .map(function (key) { - return ( - key + - ': ' + - defaultValueInfosByKey[key] - .filter(function (defaultValueInfo) { - return defaultValueInfo.asset.type !== 'I18n'; - }) - .map(function (defaultValueInfo) { - let urlOrDescription = - defaultValueInfo.asset.urlOrDescription; - - const asset = defaultValueInfo.asset; - if (asset.type === 'JavaScript' && !asset.isInline) { - const token = - defaultValueInfo.occurrence.node && - defaultValueInfo.occurrence.node.loc; - if (token) { - if (token.source) { - urlOrDescription = token.source; + Object.keys(keysByStringifiedDefaultLocaleValue).forEach( + function (stringifiedDefaultLocaleValue) { + const keys = + keysByStringifiedDefaultLocaleValue[stringifiedDefaultLocaleValue]; + if (keys.length > 1) { + const defaultValue = JSON.parse(stringifiedDefaultLocaleValue); + emitEvent( + 'sameDefaultValue', + new Error( + keys.length + + ' language keys have the same default value ' + + util.inspect(defaultValue) + + '\n ' + + keys + .map(function (key) { + return ( + key + + ': ' + + defaultValueInfosByKey[key] + .filter(function (defaultValueInfo) { + return defaultValueInfo.asset.type !== 'I18n'; + }) + .map(function (defaultValueInfo) { + let urlOrDescription = + defaultValueInfo.asset.urlOrDescription; + + const asset = defaultValueInfo.asset; + if ( + asset.type === 'JavaScript' && + !asset.isInline + ) { + const token = + defaultValueInfo.occurrence.node && + defaultValueInfo.occurrence.node.loc; + if (token) { + if (token.source) { + urlOrDescription = token.source; + } + urlOrDescription += + ':' + + token.start.line + + ':' + + (1 + token.start.column); } - urlOrDescription += - ':' + - token.start.line + - ':' + - (1 + token.start.column); } - } - return urlOrDescription; - }) - .join(' ') - ); - }) - .join('\n ') - ) - ); - } - }); + return urlOrDescription; + }) + .join(' ') + ); + }) + .join('\n '), + ), + ); + } + }, + ); // Report warn messages Object.keys(defaultValueMismatchInfos).forEach(function (key) { @@ -591,8 +596,8 @@ module.exports = function (options) { ')' ); }) - .join('\n') - ) + .join('\n'), + ), ); }); } @@ -639,7 +644,7 @@ module.exports = function (options) { (elementName === 'option' || (elementName === 'input' && /^(?:radio|checkbox|hidden)$/i.test( - element.getAttribute('type') + element.getAttribute('type'), ))) ) { return false; @@ -651,15 +656,15 @@ module.exports = function (options) { attributeValue !== '' && mustBeTranslatedByAttributeName[attributeName] ); - } + }, ); if (hasNonWhitespaceChildNodes || i18nAttributes.length > 0) { - const matchingOccurrences = occurrences.filter(function ( - occurrence - ) { - return occurrence.node === element; - }); + const matchingOccurrences = occurrences.filter( + function (occurrence) { + return occurrence.node === element; + }, + ); if ( hasNonWhitespaceChildNodes && !matchingOccurrences.some(function (matchingOccurrence) { @@ -672,8 +677,8 @@ module.exports = function (options) { 'Missing data-i18n attribute for tag contents (' + htmlAsset.urlOrDescription + '):\n' + - element.outerHTML - ) + element.outerHTML, + ), ); } i18nAttributes.forEach(function (i18nAttribute) { @@ -694,8 +699,8 @@ module.exports = function (options) { "' attribute (" + htmlAsset.urlOrDescription + '):\n' + - element.outerHTML - ) + element.outerHTML, + ), ); } }); diff --git a/package.json b/package.json index 04986e5..4f29e32 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "mocha": "^8.2.1", "nyc": "^15.0.0", "offline-github-changelog": "^3.0.0", - "prettier": "~2.8.0", + "prettier": "~3.0.0", "systemjs-builder": "0.16.15", "temp": "^0.9.4", "unexpected": "^13.0.0" diff --git a/test/bin/applyBabelJob.js b/test/bin/applyBabelJob.js index e4e559b..eb53429 100644 --- a/test/bin/applyBabelJob.js +++ b/test/bin/applyBabelJob.js @@ -16,7 +16,7 @@ describe('applyBabelJob', function () { 'bin', 'applyBabelJob', 'complex', - 'translationjob' + 'translationjob', ); const tmpTestCaseCopyDir = temp.mkdirSync(); @@ -28,13 +28,15 @@ describe('applyBabelJob', function () { 'testdata', 'bin', 'applyBabelJob', - 'complex' + 'complex', )}'/index.* ${tmpTestCaseCopyDir}`; childProcess.exec(copyCommand, function (err, stdout, stderr) { if (err) { return done( - new Error(`${copyCommand} failed: STDERR:${stderr}\nSTDOUT:${stdout}`) + new Error( + `${copyCommand} failed: STDERR:${stderr}\nSTDOUT:${stdout}`, + ), ); } const applyBabelJobProcess = childProcess.spawn( @@ -52,19 +54,21 @@ describe('applyBabelJob', function () { pathModule.join(tmpTestCaseCopyDir, 'index.i18n'), '--replace', pathModule.join(tmpTestCaseCopyDir, 'index.html'), - ] + ], ); applyBabelJobProcess.on('exit', function (exitCode) { if (exitCode) { done( new Error( - `The applyBabelJob process ended with a non-zero exit code: ${exitCode}` - ) + `The applyBabelJob process ended with a non-zero exit code: ${exitCode}`, + ), ); } else { expect( JSON.parse( - fs.readFileSync(pathModule.join(tmpTestCaseCopyDir, 'index.i18n')) + fs.readFileSync( + pathModule.join(tmpTestCaseCopyDir, 'index.i18n'), + ), ), 'to equal', { @@ -94,11 +98,11 @@ describe('applyBabelJob', function () { da: 'Denne oversatte nøgle har {0} pladsholdere', en: 'This proofread key has {0} proofread placeholders', }, - } + }, ); expect( JSON.parse( - fs.readFileSync(`${tmpTestCaseCopyDir}/index.someother.i18n`) + fs.readFileSync(`${tmpTestCaseCopyDir}/index.someother.i18n`), ), 'to equal', { @@ -106,12 +110,12 @@ describe('applyBabelJob', function () { en: 'Woop', da: 'Jubii', }, - } + }, ); expect( fs.readFileSync( pathModule.join(tmpTestCaseCopyDir, 'index.html'), - 'utf-8' + 'utf-8', ), 'to equal', '\n' + @@ -139,7 +143,7 @@ describe('applyBabelJob', function () { ' \n' + ' \n' + '\n' + - '' + '', ); done(); } @@ -156,7 +160,7 @@ describe('applyBabelJob', function () { 'bin', 'applyBabelJob', 'invalidPlurals', - 'translationjob' + 'translationjob', ); const tmpTestCaseCopyDir = temp.mkdirSync(); @@ -168,13 +172,15 @@ describe('applyBabelJob', function () { 'testdata', 'bin', 'applyBabelJob', - 'invalidPlurals' + 'invalidPlurals', )}'/index.* ${tmpTestCaseCopyDir}`; childProcess.exec(copyCommand, function (err, stdout, stderr) { if (err) { return done( - new Error(`${copyCommand} failed: STDERR:${stderr}\nSTDOUT:${stdout}`) + new Error( + `${copyCommand} failed: STDERR:${stderr}\nSTDOUT:${stdout}`, + ), ); } const applyBabelJobProcess = childProcess.spawn( @@ -192,20 +198,22 @@ describe('applyBabelJob', function () { pathModule.join(tmpTestCaseCopyDir, 'index.i18n'), '--replace', pathModule.join(tmpTestCaseCopyDir, 'index.html'), - ] + ], ); applyBabelJobProcess.on('exit', function (exitCode) { if (exitCode) { done( new Error( - `The applyBabelJob process ended with a non-zero exit code: ${exitCode}` - ) + `The applyBabelJob process ended with a non-zero exit code: ${exitCode}`, + ), ); } else { expect( JSON.parse( - fs.readFileSync(pathModule.join(tmpTestCaseCopyDir, 'index.i18n')) + fs.readFileSync( + pathModule.join(tmpTestCaseCopyDir, 'index.i18n'), + ), ), 'to equal', { @@ -221,12 +229,12 @@ describe('applyBabelJob', function () { many: 'wwww', }, }, - } + }, ); expect( fs.readFileSync( pathModule.join(tmpTestCaseCopyDir, 'index.html'), - 'utf-8' + 'utf-8', ), 'to equal', '\n' + @@ -242,7 +250,7 @@ describe('applyBabelJob', function () { ' }));\n' + ' \n' + ' \n' + - '\n' + '\n', ); done(); } @@ -259,7 +267,7 @@ describe('applyBabelJob', function () { 'bin', 'applyBabelJob', 'systemJs', - 'translationjob' + 'translationjob', ); const tmpTestCaseCopyDir = temp.mkdirSync(); @@ -270,13 +278,15 @@ describe('applyBabelJob', function () { '..', 'testdata', 'bin', - 'applyBabelJob' + 'applyBabelJob', )}'/systemJs/*.* ${tmpTestCaseCopyDir}`; childProcess.exec(copyCommand, function (err, stdout, stderr) { if (err) { return done( - new Error(`${copyCommand} failed: STDERR:${stderr}\nSTDOUT:${stdout}`) + new Error( + `${copyCommand} failed: STDERR:${stderr}\nSTDOUT:${stdout}`, + ), ); } const applyBabelJobProcess = childProcess.spawn( @@ -294,20 +304,22 @@ describe('applyBabelJob', function () { pathModule.join(tmpTestCaseCopyDir, 'index.i18n'), '--replace', pathModule.join(tmpTestCaseCopyDir, 'index.html'), - ] + ], ); applyBabelJobProcess.on('exit', function (exitCode) { if (exitCode) { done( new Error( - `The applyBabelJob process ended with a non-zero exit code: ${exitCode}` - ) + `The applyBabelJob process ended with a non-zero exit code: ${exitCode}`, + ), ); } else { expect( JSON.parse( - fs.readFileSync(pathModule.join(tmpTestCaseCopyDir, 'index.i18n')) + fs.readFileSync( + pathModule.join(tmpTestCaseCopyDir, 'index.i18n'), + ), ), 'to equal', { @@ -315,12 +327,12 @@ describe('applyBabelJob', function () { en: 'HelloFoo', cs: 'Ahoj', }, - } + }, ); expect( fs.readFileSync(`${tmpTestCaseCopyDir}/main.js`, 'utf-8'), 'to equal', - "alert(TR('myAlert', 'HelloFoo'));\n" + "alert(TR('myAlert', 'HelloFoo'));\n", ); done(); } @@ -337,7 +349,7 @@ describe('applyBabelJob', function () { 'bin', 'applyBabelJob', 'retranslationOfSomeNestedKeys', - 'translationjob' + 'translationjob', ); const tmpTestCaseCopyDir = temp.mkdirSync(); @@ -348,13 +360,15 @@ describe('applyBabelJob', function () { '..', 'testdata', 'bin', - 'applyBabelJob' + 'applyBabelJob', )}'/retranslationOfSomeNestedKeys/*.* ${tmpTestCaseCopyDir}`; childProcess.exec(copyCommand, function (err, stdout, stderr) { if (err) { return done( - new Error(`${copyCommand} failed: STDERR:${stderr}\nSTDOUT:${stdout}`) + new Error( + `${copyCommand} failed: STDERR:${stderr}\nSTDOUT:${stdout}`, + ), ); } const applyBabelJobProcess = childProcess.spawn( @@ -372,20 +386,22 @@ describe('applyBabelJob', function () { pathModule.join(tmpTestCaseCopyDir, 'index.i18n'), '--replace', pathModule.join(tmpTestCaseCopyDir, 'index.html'), - ] + ], ); applyBabelJobProcess.on('exit', function (exitCode) { if (exitCode) { done( new Error( - `The applyBabelJob process ended with a non-zero exit code: ${exitCode}` - ) + `The applyBabelJob process ended with a non-zero exit code: ${exitCode}`, + ), ); } else { expect( JSON.parse( - fs.readFileSync(pathModule.join(tmpTestCaseCopyDir, 'index.i18n')) + fs.readFileSync( + pathModule.join(tmpTestCaseCopyDir, 'index.i18n'), + ), ), 'to equal', { @@ -399,15 +415,15 @@ describe('applyBabelJob', function () { bar: 'Czech bar', }, }, - } + }, ); expect( fs.readFileSync( pathModule.join(tmpTestCaseCopyDir, 'index.html'), - 'utf-8' + 'utf-8', ), 'to contain', - "alert(TR('MyObject', { foo: 'New English foo', bar: 'English bar' }));\n" + "alert(TR('MyObject', { foo: 'New English foo', bar: 'English bar' }));\n", ); done(); } diff --git a/test/bin/makeBabelJob.js b/test/bin/makeBabelJob.js index fc1d48b..5ffad35 100644 --- a/test/bin/makeBabelJob.js +++ b/test/bin/makeBabelJob.js @@ -15,13 +15,15 @@ describe('makeBabelJob', function () { '..', '..', 'testdata', - 'bin' + 'bin', )}'/makeBabelJob/complex/* ${tmpTestCaseCopyDir}`; childProcess.exec(copyCommand, function (err, stdout, stderr) { if (err) { return done( - new Error(`${copyCommand} failed: STDERR:${stderr}\nSTDOUT:${stdout}`) + new Error( + `${copyCommand} failed: STDERR:${stderr}\nSTDOUT:${stdout}`, + ), ); } @@ -39,7 +41,7 @@ describe('makeBabelJob', function () { 'en', '--locales', 'en,pl,da,de,cs', - ] + ], ); const buffersByStreamName = {}; @@ -56,7 +58,7 @@ describe('makeBabelJob', function () { streamNames.forEach(function (streamName) { if (buffersByStreamName[streamName].length > 0) { outputText += `\n${streamName.toUpperCase()}: ${Buffer.concat( - buffersByStreamName[streamName] + buffersByStreamName[streamName], ).toString('utf-8')}\n`; } }); @@ -67,8 +69,8 @@ describe('makeBabelJob', function () { if (exitCode) { return done( new Error( - `The makeBabelJob process ended with a non-zero exit code: ${exitCode}${getStreamOutputText()}` - ) + `The makeBabelJob process ended with a non-zero exit code: ${exitCode}${getStreamOutputText()}`, + ), ); } @@ -103,7 +105,7 @@ describe('makeBabelJob', function () { '# NotYetTranslatedKeyWithPluralCasesInNestedStructure[foo][few]=', '# NotYetTranslatedKeyWithPluralCasesInNestedStructure[foo][many]=', '', - ].join('\n') + ].join('\n'), ); expect( @@ -120,7 +122,7 @@ describe('makeBabelJob', function () { 'NotYetTranslatedKeyWithPluralCasesInNestedStructure[foo][one]=', 'NotYetTranslatedKeyWithPluralCasesInNestedStructure[foo][other]=', '', - ].join('\n') + ].join('\n'), ); expect( @@ -137,7 +139,7 @@ describe('makeBabelJob', function () { 'NotYetTranslatedKeyWithPluralCasesInNestedStructure[foo][one]=', 'NotYetTranslatedKeyWithPluralCasesInNestedStructure[foo][other]=', '', - ].join('\n') + ].join('\n'), ); expect( @@ -160,7 +162,7 @@ describe('makeBabelJob', function () { 'NotYetTranslatedKeyWithPluralCasesInNestedStructure[foo][many]=', 'NotYetTranslatedKeyWithPluralCasesInNestedStructure[foo][other]=', '', - ].join('\n') + ].join('\n'), ); expect( @@ -183,15 +185,15 @@ describe('makeBabelJob', function () { 'NotYetTranslatedKeyWithPluralCasesInNestedStructure[foo][many]=', 'NotYetTranslatedKeyWithPluralCasesInNestedStructure[foo][other]=', '', - ].join('\n') + ].join('\n'), ); expect( JSON.parse( fs.readFileSync( pathModule.resolve(tmpTestCaseCopyDir, 'index.i18n'), - 'utf-8' - ) + 'utf-8', + ), ), 'to equal', { @@ -237,15 +239,15 @@ describe('makeBabelJob', function () { en: { one: 'foo', other: 'foo' }, pl: { few: null, many: null, one: null, other: null }, }, - } + }, ); expect( JSON.parse( fs.readFileSync( pathModule.resolve(tmpTestCaseCopyDir, 'other.i18n'), - 'utf-8' - ) + 'utf-8', + ), ), 'to equal', { @@ -256,7 +258,7 @@ describe('makeBabelJob', function () { da: null, pl: null, }, - } + }, ); done(); @@ -273,13 +275,15 @@ describe('makeBabelJob', function () { '..', '..', 'testdata', - 'bin' + 'bin', )}'/makeBabelJob/noTranslationsNecessary/* ${tmpTestCaseCopyDir}`; childProcess.exec(copyCommand, function (err, stdout, stderr) { if (err) { return done( - new Error(`${copyCommand} failed: STDERR:${stderr}\nSTDOUT:${stdout}`) + new Error( + `${copyCommand} failed: STDERR:${stderr}\nSTDOUT:${stdout}`, + ), ); } @@ -295,7 +299,7 @@ describe('makeBabelJob', function () { pathModule.resolve(tmpTestCaseCopyDir, 'index.html'), '--locales', 'en,cs', - ] + ], ); const buffersByStreamName = {}; @@ -313,7 +317,7 @@ describe('makeBabelJob', function () { streamNames.forEach(function (streamName) { if (buffersByStreamName[streamName].length > 0) { outputText += `\n${streamName.toUpperCase()}: ${Buffer.concat( - buffersByStreamName[streamName] + buffersByStreamName[streamName], ).toString('utf-8')}\n`; } }); @@ -324,8 +328,8 @@ describe('makeBabelJob', function () { if (exitCode) { return done( new Error( - `The makeBabelJob process ended with a non-zero exit code: ${exitCode}${getStreamOutputText()}` - ) + `The makeBabelJob process ended with a non-zero exit code: ${exitCode}${getStreamOutputText()}`, + ), ); } @@ -344,13 +348,15 @@ describe('makeBabelJob', function () { '..', '..', 'testdata', - 'bin' + 'bin', )}'/makeBabelJob/includeAllFlattened/* ${tmpTestCaseCopyDir}`; childProcess.exec(copyCommand, function (err, stdout, stderr) { if (err) { return done( - new Error(`${copyCommand} failed: STDERR:${stderr}\nSTDOUT:${stdout}`) + new Error( + `${copyCommand} failed: STDERR:${stderr}\nSTDOUT:${stdout}`, + ), ); } @@ -366,7 +372,7 @@ describe('makeBabelJob', function () { pathModule.resolve(tmpTestCaseCopyDir, 'index.html'), '--locales', 'en,cs', - ] + ], ); const buffersByStreamName = {}; @@ -384,7 +390,7 @@ describe('makeBabelJob', function () { streamNames.forEach(function (streamName) { if (buffersByStreamName[streamName].length > 0) { outputText += `\n${streamName.toUpperCase()}: ${Buffer.concat( - buffersByStreamName[streamName] + buffersByStreamName[streamName], ).toString('utf-8')}\n`; } }); @@ -395,15 +401,15 @@ describe('makeBabelJob', function () { if (exitCode) { return done( new Error( - `The makeBabelJob process ended with a non-zero exit code: ${exitCode}${getStreamOutputText()}` - ) + `The makeBabelJob process ended with a non-zero exit code: ${exitCode}${getStreamOutputText()}`, + ), ); } expect( fs.readFileSync(pathModule.resolve(babelDir, 'cs.txt'), 'utf-8'), 'to equal', - ['KeyPartiallyTranslatedToCzech[many]=', ''].join('\n') + ['KeyPartiallyTranslatedToCzech[many]=', ''].join('\n'), ); expect(fs.readdirSync(babelDir).sort(), 'to equal', [ @@ -420,15 +426,15 @@ describe('makeBabelJob', function () { '# NOTE: The language cs needs this additional key to cover all plural forms:', '# KeyPartiallyTranslatedToCzech[many]=', '', - ].join('\n') + ].join('\n'), ); expect( JSON.parse( fs.readFileSync( pathModule.resolve(tmpTestCaseCopyDir, 'index.i18n'), - 'utf-8' - ) + 'utf-8', + ), ), 'to equal', { @@ -436,7 +442,7 @@ describe('makeBabelJob', function () { en: { one: 'the one', other: 'the other' }, cs: { one: 'xxxx', other: 'yyyy', few: 'zzzz', many: null }, }, - } + }, ); done(); }); @@ -452,13 +458,15 @@ describe('makeBabelJob', function () { '..', '..', 'testdata', - 'bin' + 'bin', )}'/makeBabelJob/systemJs/* ${tmpTestCaseCopyDir}`; childProcess.exec(copyCommand, function (err, stdout, stderr) { if (err) { return done( - new Error(`${copyCommand} failed: STDERR:${stderr}\nSTDOUT:${stdout}`) + new Error( + `${copyCommand} failed: STDERR:${stderr}\nSTDOUT:${stdout}`, + ), ); } @@ -474,7 +482,7 @@ describe('makeBabelJob', function () { pathModule.resolve(tmpTestCaseCopyDir, 'index.html'), '--locales', 'en,cs', - ] + ], ); const buffersByStreamName = {}; @@ -492,7 +500,7 @@ describe('makeBabelJob', function () { streamNames.forEach(function (streamName) { if (buffersByStreamName[streamName].length > 0) { outputText += `\n${streamName.toUpperCase()}: ${Buffer.concat( - buffersByStreamName[streamName] + buffersByStreamName[streamName], ).toString('utf-8')}\n`; } }); @@ -503,15 +511,15 @@ describe('makeBabelJob', function () { if (exitCode) { return done( new Error( - `The makeBabelJob process ended with a non-zero exit code: ${exitCode}${getStreamOutputText()}` - ) + `The makeBabelJob process ended with a non-zero exit code: ${exitCode}${getStreamOutputText()}`, + ), ); } expect( fs.readFileSync(pathModule.resolve(babelDir, 'cs.txt'), 'utf-8'), 'to equal', - ['myAlert=', ''].join('\n') + ['myAlert=', ''].join('\n'), ); expect(fs.readdirSync(babelDir).sort(), 'to equal', [ @@ -522,15 +530,15 @@ describe('makeBabelJob', function () { expect( fs.readFileSync(pathModule.resolve(babelDir, 'en.txt'), 'utf-8'), 'to equal', - ['myAlert=Hello', ''].join('\n') + ['myAlert=Hello', ''].join('\n'), ); expect( JSON.parse( fs.readFileSync( pathModule.resolve(tmpTestCaseCopyDir, 'index.i18n'), - 'utf-8' - ) + 'utf-8', + ), ), 'to equal', { @@ -538,7 +546,7 @@ describe('makeBabelJob', function () { en: 'Hello', cs: null, }, - } + }, ); done(); }); diff --git a/test/bin/makeBabelJobAndApplyBabelJob.js b/test/bin/makeBabelJobAndApplyBabelJob.js index 4b142eb..5065791 100644 --- a/test/bin/makeBabelJobAndApplyBabelJob.js +++ b/test/bin/makeBabelJobAndApplyBabelJob.js @@ -15,13 +15,15 @@ describe('makeBabelJob and applyBabelJob', function () { '..', '..', 'testdata', - 'bin' + 'bin', )}'/makeBabelJobAndApplyBabelJob/* ${tmpTestCaseCopyDir}`; childProcess.exec(copyCommand, function (err, stdout, stderr) { if (err) { return done( - new Error(`${copyCommand} failed: STDERR:${stderr}\nSTDOUT:${stdout}`) + new Error( + `${copyCommand} failed: STDERR:${stderr}\nSTDOUT:${stdout}`, + ), ); } @@ -37,7 +39,7 @@ describe('makeBabelJob and applyBabelJob', function () { '--i18n', pathModule.resolve(tmpTestCaseCopyDir, 'thething.i18n'), pathModule.resolve(tmpTestCaseCopyDir, 'index.html'), - ] + ], ); const buffersByStreamName = {}; @@ -55,7 +57,7 @@ describe('makeBabelJob and applyBabelJob', function () { streamNames.forEach(function (streamName) { if (buffersByStreamName[streamName].length > 0) { outputText += `\n${streamName.toUpperCase()}: ${Buffer.concat( - buffersByStreamName[streamName] + buffersByStreamName[streamName], ).toString('utf-8')}\n`; } }); @@ -66,8 +68,8 @@ describe('makeBabelJob and applyBabelJob', function () { if (exitCode) { return done( new Error( - `The makeBabelJob process ended with a non-zero exit code: ${exitCode}${getStreamOutputText()}` - ) + `The makeBabelJob process ended with a non-zero exit code: ${exitCode}${getStreamOutputText()}`, + ), ); } @@ -100,7 +102,7 @@ describe('makeBabelJob and applyBabelJob', function () { 'stringvalue=value', 'withexistingkeys=the English value', '', - ] + ], ); expect( @@ -126,7 +128,7 @@ describe('makeBabelJob and applyBabelJob', function () { 'stringvalue=', 'withexistingkeys=the Danish value', '', - ] + ], ); expect( @@ -152,7 +154,7 @@ describe('makeBabelJob and applyBabelJob', function () { 'stringvalue=', 'withexistingkeys=', '', - ] + ], ); // Add translations to da.txt, duplicate the test case and run applyBabelJob on it: @@ -177,7 +179,7 @@ describe('makeBabelJob and applyBabelJob', function () { 'simplekeyinhtmlattribute=Simpel nøgle i HTML-attribut på dansk', 'keywithplaceholdersinhtml=Nøgle med pladsholdere på dansk', ].join('\n'), - 'utf-8' + 'utf-8', ); const applyBabelJobProcess = childProcess.spawn( @@ -192,14 +194,14 @@ describe('makeBabelJob and applyBabelJob', function () { '--i18n', pathModule.resolve(tmpTestCaseCopyDir, 'thething.i18n'), pathModule.resolve(tmpTestCaseCopyDir, 'index.html'), - ] + ], ); applyBabelJobProcess.on('exit', function (exitCode) { if (exitCode) { return done( new Error( - `The applyBabelJob process ended with a non-zero exit code: ${exitCode}` - ) + `The applyBabelJob process ended with a non-zero exit code: ${exitCode}`, + ), ); } @@ -207,8 +209,8 @@ describe('makeBabelJob and applyBabelJob', function () { JSON.parse( fs.readFileSync( pathModule.resolve(tmpTestCaseCopyDir, 'thething.i18n'), - 'utf-8' - ) + 'utf-8', + ), ), 'to equal', { @@ -286,7 +288,7 @@ describe('makeBabelJob and applyBabelJob', function () { theNotYetTranslatedOne: '', }, }, - } + }, ); done(); }); diff --git a/test/i18nTools.js b/test/i18nTools.js index a95d626..d9f6312 100644 --- a/test/i18nTools.js +++ b/test/i18nTools.js @@ -9,7 +9,7 @@ describe('i18nTools', function () { ' to tokenize as ', function (expect, subject, value) { expect(i18nTools.tokenizePattern(subject), 'to equal', value); - } + }, ); describe('#tokenizePattern()', function () { diff --git a/test/transforms/checkLanguageKeys.js b/test/transforms/checkLanguageKeys.js index 047797b..197a409 100644 --- a/test/transforms/checkLanguageKeys.js +++ b/test/transforms/checkLanguageKeys.js @@ -15,7 +15,7 @@ describe('checkLanguageKeys', function () { 'testdata', 'transforms', 'checkLanguageKeys', - 'combo' + 'combo', ), }) .on('info', function (err) { @@ -27,7 +27,7 @@ describe('checkLanguageKeys', function () { require('../../lib/transforms/checkLanguageKeys')({ supportedLocaleIds: ['en_us', 'da'], defaultLocaleId: 'en_us', - }) + }), ) .queue(function (assetGraph) { expect(infos, 'to satisfy', [ @@ -54,7 +54,7 @@ describe('checkLanguageKeys', function () { 'testdata', 'transforms', 'checkLanguageKeys', - 'neverEndingSpaceLoop' + 'neverEndingSpaceLoop', ), }) .on('info', function (err) { @@ -66,7 +66,7 @@ describe('checkLanguageKeys', function () { require('../../lib/transforms/checkLanguageKeys')({ supportedLocaleIds: ['en_us', 'da'], defaultLocaleId: 'en_us', - }) + }), ) .queue(function (assetGraph) { expect(infos, 'to have length', 2); @@ -83,7 +83,7 @@ describe('checkLanguageKeys', function () { 'testdata', 'transforms', 'checkLanguageKeys', - 'pluralRule' + 'pluralRule', ), }) .on('info', function (err) { @@ -95,21 +95,21 @@ describe('checkLanguageKeys', function () { require('../../lib/transforms/checkLanguageKeys')({ supportedLocaleIds: ['en_us', 'cs', 'da'], defaultLocaleId: 'en_us', - }) + }), ) .queue(function (assetGraph) { expect(infos, 'to equal', [ new Error('cs is missing EveryNWeeks[few]'), new Error('cs is missing EveryNWeeks[many]'), new Error( - "da should not have EveryNWeeks[many]='I should not be here'" + "da should not have EveryNWeeks[many]='I should not be here'", ), new Error('en is missing DeeplyStructured[bar]'), new Error('da is missing DeeplyStructured[bar]'), new Error('cs is missing DeeplyStructured[foo][few]'), new Error('cs is missing DeeplyStructured[foo][many]'), new Error( - "da should not have DeeplyStructured[foo][many]='I should not be here'" + "da should not have DeeplyStructured[foo][many]='I should not be here'", ), ]); }); @@ -125,7 +125,7 @@ describe('checkLanguageKeys', function () { 'testdata', 'transforms', 'checkLanguageKeys', - 'duplicateLanguageKeys' + 'duplicateLanguageKeys', ), }) .on('info', function (err) { @@ -138,7 +138,7 @@ describe('checkLanguageKeys', function () { supportedLocaleIds: ['en_us', 'cs', 'da'], ignoreMessageTypes: 'missing', defaultLocaleId: 'en_us', - }) + }), ) .queue(function (assetGraph) { expect(infos, 'to satisfy', [