Enable the ESLint no-var rule in the importL10n/ folder

This commit is contained in:
Jonas Jenwald 2021-03-13 17:23:41 +01:00
parent 17c0bf0473
commit 2ffa428d78
2 changed files with 34 additions and 23 deletions

10
external/importL10n/.eslintrc vendored Normal file
View File

@ -0,0 +1,10 @@
{
"extends": [
"../.eslintrc"
],
"rules": {
// ECMAScript 6
"no-var": "error",
},
}

View File

@ -15,16 +15,16 @@
"use strict"; "use strict";
var fs = require("fs"); const fs = require("fs");
var https = require("https"); const https = require("https");
var path = require("path"); const path = require("path");
// Fetches all languages that have an *active* translation in mozilla-central. // Fetches all languages that have an *active* translation in mozilla-central.
// This is used in gulpfile.js for the `importl10n` command. // This is used in gulpfile.js for the `importl10n` command.
var DEFAULT_LOCALE = "en-US"; const DEFAULT_LOCALE = "en-US";
var EXCLUDE_LANG_CODES = ["ca-valencia", "ja-JP-mac"]; const EXCLUDE_LANG_CODES = ["ca-valencia", "ja-JP-mac"];
function normalizeText(s) { function normalizeText(s) {
return s.replace(/\r\n?/g, "\n").replace(/\uFEFF/g, ""); return s.replace(/\r\n?/g, "\n").replace(/\uFEFF/g, "");
@ -33,23 +33,23 @@ function normalizeText(s) {
function downloadLanguageCodes() { function downloadLanguageCodes() {
console.log("Downloading language codes...\n"); console.log("Downloading language codes...\n");
var ALL_LOCALES = const ALL_LOCALES =
"https://hg.mozilla.org/mozilla-central/raw-file/tip/browser/locales/all-locales"; "https://hg.mozilla.org/mozilla-central/raw-file/tip/browser/locales/all-locales";
return new Promise(function (resolve) { return new Promise(function (resolve) {
https.get(ALL_LOCALES, function (response) { https.get(ALL_LOCALES, function (response) {
if (response.statusCode === 200) { if (response.statusCode === 200) {
var content = ""; let content = "";
response.setEncoding("utf8"); response.setEncoding("utf8");
response.on("data", function (chunk) { response.on("data", function (chunk) {
content += chunk; content += chunk;
}); });
response.on("end", function () { response.on("end", function () {
content = content.trim(); // Remove any leading/trailing white-space. content = content.trim(); // Remove any leading/trailing white-space.
var langCodes = normalizeText(content).split("\n"); const langCodes = normalizeText(content).split("\n");
// Remove all locales that we don't want to download below. // Remove all locales that we don't want to download below.
for (var langCode of [DEFAULT_LOCALE, ...EXCLUDE_LANG_CODES]) { for (const langCode of [DEFAULT_LOCALE, ...EXCLUDE_LANG_CODES]) {
var i = langCodes.indexOf(langCode); const i = langCodes.indexOf(langCode);
if (i > -1) { if (i > -1) {
langCodes.splice(i, 1); langCodes.splice(i, 1);
} }
@ -68,14 +68,14 @@ function downloadLanguageFiles(root, langCode) {
// Constants for constructing the URLs. Translations are taken from the // Constants for constructing the URLs. Translations are taken from the
// Nightly channel as those are the most recent ones. // Nightly channel as those are the most recent ones.
var MOZ_CENTRAL_ROOT = "https://hg.mozilla.org/l10n-central/"; const MOZ_CENTRAL_ROOT = "https://hg.mozilla.org/l10n-central/";
var MOZ_CENTRAL_PDFJS_DIR = "/raw-file/default/browser/pdfviewer/"; const MOZ_CENTRAL_PDFJS_DIR = "/raw-file/default/browser/pdfviewer/";
// Defines which files to download for each language. // Defines which files to download for each language.
var files = ["viewer.properties"]; const files = ["viewer.properties"];
var downloadsLeft = files.length; let downloadsLeft = files.length;
var outputDir = path.join(root, langCode); const outputDir = path.join(root, langCode);
if (!fs.existsSync(outputDir)) { if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir); fs.mkdirSync(outputDir);
} }
@ -83,14 +83,15 @@ function downloadLanguageFiles(root, langCode) {
return new Promise(function (resolve) { return new Promise(function (resolve) {
// Download the necessary files for this language. // Download the necessary files for this language.
files.forEach(function (fileName) { files.forEach(function (fileName) {
var outputPath = path.join(outputDir, fileName); const outputPath = path.join(outputDir, fileName);
var url = MOZ_CENTRAL_ROOT + langCode + MOZ_CENTRAL_PDFJS_DIR + fileName; const url =
MOZ_CENTRAL_ROOT + langCode + MOZ_CENTRAL_PDFJS_DIR + fileName;
https.get(url, function (response) { https.get(url, function (response) {
// Not all files exist for each language. Files without translations // Not all files exist for each language. Files without translations
// have been removed (https://bugzilla.mozilla.org/show_bug.cgi?id=1443175). // have been removed (https://bugzilla.mozilla.org/show_bug.cgi?id=1443175).
if (response.statusCode === 200) { if (response.statusCode === 200) {
var content = ""; let content = "";
response.setEncoding("utf8"); response.setEncoding("utf8");
response.on("data", function (chunk) { response.on("data", function (chunk) {
content += chunk; content += chunk;
@ -112,18 +113,18 @@ function downloadLanguageFiles(root, langCode) {
} }
async function downloadL10n(root, callback) { async function downloadL10n(root, callback) {
var langCodes = await downloadLanguageCodes(); const langCodes = await downloadLanguageCodes();
for (var langCode of langCodes) { for (const langCode of langCodes) {
if (!langCode) { if (!langCode) {
continue; continue;
} }
await downloadLanguageFiles(root, langCode); await downloadLanguageFiles(root, langCode);
} }
var removeCodes = []; const removeCodes = [];
for (var entry of fs.readdirSync(root)) { for (const entry of fs.readdirSync(root)) {
var dirPath = path.join(root, entry), const dirPath = path.join(root, entry),
stat = fs.lstatSync(dirPath); stat = fs.lstatSync(dirPath);
if ( if (