Enable the ESLint no-var rule in the external/builder/ folder

As part of testing this, I've diffed the output of `gulp mozcentral` with/without this patch and the *only* difference is the incremented `version`/`build` numbers.
This commit is contained in:
Jonas Jenwald 2021-03-13 17:40:44 +01:00
parent 06494ccdac
commit f0f307a4b5
3 changed files with 28 additions and 16 deletions

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

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

View File

@ -33,6 +33,11 @@ const fs = require("fs"),
* //#endif * //#endif
*/ */
function preprocess(inFilename, outFilename, defines) { function preprocess(inFilename, outFilename, defines) {
let lineNumber = 0;
function loc() {
return fs.realpathSync(inFilename) + ":" + lineNumber;
}
// TODO make this really read line by line. // TODO make this really read line by line.
const lines = fs.readFileSync(inFilename).toString().split("\n"); const lines = fs.readFileSync(inFilename).toString().split("\n");
const totalLines = lines.length; const totalLines = lines.length;
@ -118,10 +123,7 @@ function preprocess(inFilename, outFilename, defines) {
let state = STATE_NONE; let state = STATE_NONE;
const stack = []; const stack = [];
const control = /^(?:\/\/|<!--)\s*#(if|elif|else|endif|expand|include|error)\b(?:\s+(.*?)(?:-->)?$)?/; const control = /^(?:\/\/|<!--)\s*#(if|elif|else|endif|expand|include|error)\b(?:\s+(.*?)(?:-->)?$)?/;
let lineNumber = 0;
var loc = function () {
return fs.realpathSync(inFilename) + ":" + lineNumber;
};
while ((line = readLine()) !== null) { while ((line = readLine()) !== null) {
++lineNumber; ++lineNumber;
const m = control.exec(line); const m = control.exec(line);
@ -277,11 +279,11 @@ exports.preprocessCSS = preprocessCSS;
* the first. * the first.
*/ */
function merge(defaults, defines) { function merge(defaults, defines) {
const ret = {}; const ret = Object.create(null);
for (var key in defaults) { for (const key in defaults) {
ret[key] = defaults[key]; ret[key] = defaults[key];
} }
for (key in defines) { for (const key in defines) {
ret[key] = defines[key]; ret[key] = defines[key];
} }
return ret; return ret;

View File

@ -34,14 +34,14 @@ function handlePreprocessorAction(ctx, actionName, args, loc) {
if (!arg || arg.type !== "Literal" || typeof arg.value !== "string") { if (!arg || arg.type !== "Literal" || typeof arg.value !== "string") {
throw new Error("No code for testing is given"); throw new Error("No code for testing is given");
} }
var isTrue = !!evalWithDefines(arg.value, ctx.defines); const isTrue = !!evalWithDefines(arg.value, ctx.defines);
return { type: "Literal", value: isTrue, loc }; return { type: "Literal", value: isTrue, loc };
case "eval": case "eval":
arg = args[0]; arg = args[0];
if (!arg || arg.type !== "Literal" || typeof arg.value !== "string") { if (!arg || arg.type !== "Literal" || typeof arg.value !== "string") {
throw new Error("No code for eval is given"); throw new Error("No code for eval is given");
} }
var result = evalWithDefines(arg.value, ctx.defines); const result = evalWithDefines(arg.value, ctx.defines);
if ( if (
typeof result === "boolean" || typeof result === "boolean" ||
typeof result === "string" || typeof result === "string" ||
@ -62,14 +62,14 @@ function handlePreprocessorAction(ctx, actionName, args, loc) {
if (!arg || arg.type !== "Literal" || typeof arg.value !== "string") { if (!arg || arg.type !== "Literal" || typeof arg.value !== "string") {
throw new Error("Path to JSON is not provided"); throw new Error("Path to JSON is not provided");
} }
var jsonPath = arg.value; let jsonPath = arg.value;
if (jsonPath.indexOf(ROOT_PREFIX) === 0) { if (jsonPath.indexOf(ROOT_PREFIX) === 0) {
jsonPath = path.join( jsonPath = path.join(
ctx.rootPath, ctx.rootPath,
jsonPath.substring(ROOT_PREFIX.length) jsonPath.substring(ROOT_PREFIX.length)
); );
} }
var jsonContent = fs.readFileSync(jsonPath).toString(); const jsonContent = fs.readFileSync(jsonPath).toString();
const parsedJSON = acorn.parse("(" + jsonContent + ")", { const parsedJSON = acorn.parse("(" + jsonContent + ")", {
ecmaVersion: ACORN_ECMA_VERSION, ecmaVersion: ACORN_ECMA_VERSION,
}); });
@ -175,7 +175,7 @@ function postprocessNode(ctx, node) {
case "string": case "string":
case "boolean": case "boolean":
case "number": case "number":
var equal = node.left.value === node.right.value; const equal = node.left.value === node.right.value;
return { return {
type: "Literal", type: "Literal",
value: (node.operator[0] === "=") === equal, value: (node.operator[0] === "=") === equal,
@ -210,7 +210,7 @@ function postprocessNode(ctx, node) {
} }
break; break;
case "BlockStatement": case "BlockStatement":
var subExpressionIndex = 0; let subExpressionIndex = 0;
while (subExpressionIndex < node.body.length) { while (subExpressionIndex < node.body.length) {
switch (node.body[subExpressionIndex].type) { switch (node.body[subExpressionIndex].type) {
case "EmptyStatement": case "EmptyStatement":
@ -219,7 +219,7 @@ function postprocessNode(ctx, node) {
continue; continue;
case "BlockStatement": case "BlockStatement":
// Block statements inside a block are moved to the parent one. // Block statements inside a block are moved to the parent one.
var subChildren = node.body[subExpressionIndex].body; const subChildren = node.body[subExpressionIndex].body;
Array.prototype.splice.apply( Array.prototype.splice.apply(
node.body, node.body,
[subExpressionIndex, 1].concat(subChildren) [subExpressionIndex, 1].concat(subChildren)
@ -240,7 +240,7 @@ function postprocessNode(ctx, node) {
break; break;
case "FunctionDeclaration": case "FunctionDeclaration":
case "FunctionExpression": case "FunctionExpression":
var block = node.body; const block = node.body;
if ( if (
block.body.length > 0 && block.body.length > 0 &&
block.body[block.body.length - 1].type === "ReturnStatement" && block.body[block.body.length - 1].type === "ReturnStatement" &&
@ -292,7 +292,7 @@ function fixComments(ctx, node) {
function traverseTree(ctx, node) { function traverseTree(ctx, node) {
// generic node processing // generic node processing
for (const i in node) { for (const i in node) {
var child = node[i]; const child = node[i];
if (typeof child === "object" && child !== null && child.type) { if (typeof child === "object" && child !== null && child.type) {
const result = traverseTree(ctx, child); const result = traverseTree(ctx, child);
if (result !== child) { if (result !== child) {