1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Enable the dot-notation ESLint rule

*Please note:* These changes were done automatically, using the `gulp lint --fix` command.

This rule is already enabled in mozilla-central, see https://searchfox.org/mozilla-central/rev/567b68b8ff4b6d607ba34a6f1926873d21a7b4d7/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js#103-104

The main advantage, besides improved consistency, of this rule is that it reduces the size of the code (by 3 bytes for each case). In the PDF.js code-base there's close to 8000 instances being fixed by the `dot-notation` ESLint rule, which end up reducing the size of even the *built* files significantly; the total size of the `gulp mozcentral` build target changes from `3 247 456` to `3 224 278` bytes, which is a *reduction* of `23 178` bytes (or ~0.7%) for a completely mechanical change.

A large number of these changes affect the (large) lookup tables used on the worker-thread, but given that they are still initialized lazily I don't *think* that the new formatting this patch introduces should undo any of the improvements from PR 6915.

Please find additional details about the ESLint rule at https://eslint.org/docs/rules/dot-notation
This commit is contained in:
Jonas Jenwald 2020-04-17 12:06:27 +02:00
parent c218e94f66
commit 1cc3dbb694
26 changed files with 7773 additions and 7785 deletions

View file

@ -46,7 +46,7 @@ function group(stats, groupBy) {
if (vals[key] === undefined) {
vals[key] = [];
}
vals[key].push(curStat["time"]);
vals[key].push(curStat.time);
}
return vals;
}
@ -58,14 +58,14 @@ function group(stats, groupBy) {
function flatten(stats) {
var rows = [];
stats.forEach(function (curStat) {
curStat["stats"].forEach(function (s) {
curStat.stats.forEach(function (s) {
rows.push({
browser: curStat["browser"],
page: curStat["page"],
pdf: curStat["pdf"],
round: curStat["round"],
stat: s["name"],
time: s["end"] - s["start"],
browser: curStat.browser,
page: curStat.page,
pdf: curStat.pdf,
round: curStat.round,
stat: s.name,
time: s.end - s.start,
});
});
});

View file

@ -191,7 +191,7 @@ function examineRefImages() {
server.port +
"/test/resources/reftest-analyzer.html#web=/test/eq.log";
var config = Object.assign({}, sessions[0].config);
config["headless"] = false;
config.headless = false;
var browser = WebBrowser.create(config);
browser.start(startUrl);
}
@ -271,7 +271,7 @@ function startRefTest(masterMode, showRefImages) {
startTime = Date.now();
startServer();
server.hooks["POST"].push(refTestPostHandler);
server.hooks.POST.push(refTestPostHandler);
onAllSessionsClosed = finalize;
startBrowsers("/test/test_slave.html", function (session) {
@ -692,7 +692,7 @@ function refTestPostHandler(req, res) {
function startUnitTest(testUrl, name) {
var startTime = Date.now();
startServer();
server.hooks["POST"].push(unitTestPostHandler);
server.hooks.POST.push(unitTestPostHandler);
onAllSessionsClosed = function () {
stopServer();
var numRuns = 0,

View file

@ -1116,15 +1116,15 @@ describe("api", function () {
var promise = pdfDocument.getMetadata();
promise
.then(function ({ info, metadata, contentDispositionFilename }) {
expect(info["Title"]).toEqual("Basic API Test");
expect(info.Title).toEqual("Basic API Test");
// Custom, non-standard, information dictionary entries.
expect(info["Custom"]).toEqual(undefined);
expect(info.Custom).toEqual(undefined);
// The following are PDF.js specific, non-standard, properties.
expect(info["PDFFormatVersion"]).toEqual("1.7");
expect(info["IsLinearized"]).toEqual(false);
expect(info["IsAcroFormPresent"]).toEqual(false);
expect(info["IsXFAPresent"]).toEqual(false);
expect(info["IsCollectionPresent"]).toEqual(false);
expect(info.PDFFormatVersion).toEqual("1.7");
expect(info.IsLinearized).toEqual(false);
expect(info.IsAcroFormPresent).toEqual(false);
expect(info.IsXFAPresent).toEqual(false);
expect(info.IsCollectionPresent).toEqual(false);
expect(metadata instanceof Metadata).toEqual(true);
expect(metadata.get("dc:title")).toEqual("Basic API Test");
@ -1142,11 +1142,11 @@ describe("api", function () {
return pdfDoc.getMetadata();
})
.then(function ({ info, metadata, contentDispositionFilename }) {
expect(info["Creator"]).toEqual("TeX");
expect(info["Producer"]).toEqual("pdfeTeX-1.21a");
expect(info["CreationDate"]).toEqual("D:20090401163925-07'00'");
expect(info.Creator).toEqual("TeX");
expect(info.Producer).toEqual("pdfeTeX-1.21a");
expect(info.CreationDate).toEqual("D:20090401163925-07'00'");
// Custom, non-standard, information dictionary entries.
const custom = info["Custom"];
const custom = info.Custom;
expect(typeof custom === "object" && custom !== null).toEqual(true);
expect(custom["PTEX.Fullbanner"]).toEqual(
@ -1154,11 +1154,11 @@ describe("api", function () {
"Version 3.141592-1.21a-2.2 (Web2C 7.5.4) kpathsea version 3.5.6"
);
// The following are PDF.js specific, non-standard, properties.
expect(info["PDFFormatVersion"]).toEqual("1.4");
expect(info["IsLinearized"]).toEqual(false);
expect(info["IsAcroFormPresent"]).toEqual(false);
expect(info["IsXFAPresent"]).toEqual(false);
expect(info["IsCollectionPresent"]).toEqual(false);
expect(info.PDFFormatVersion).toEqual("1.4");
expect(info.IsLinearized).toEqual(false);
expect(info.IsAcroFormPresent).toEqual(false);
expect(info.IsXFAPresent).toEqual(false);
expect(info.IsCollectionPresent).toEqual(false);
expect(metadata).toEqual(null);
expect(contentDispositionFilename).toEqual(null);
@ -1176,11 +1176,11 @@ describe("api", function () {
})
.then(function ({ info, metadata, contentDispositionFilename }) {
// The following are PDF.js specific, non-standard, properties.
expect(info["PDFFormatVersion"]).toEqual(null);
expect(info["IsLinearized"]).toEqual(false);
expect(info["IsAcroFormPresent"]).toEqual(false);
expect(info["IsXFAPresent"]).toEqual(false);
expect(info["IsCollectionPresent"]).toEqual(false);
expect(info.PDFFormatVersion).toEqual(null);
expect(info.IsLinearized).toEqual(false);
expect(info.IsAcroFormPresent).toEqual(false);
expect(info.IsXFAPresent).toEqual(false);
expect(info.IsCollectionPresent).toEqual(false);
expect(metadata).toEqual(null);
expect(contentDispositionFilename).toEqual(null);

View file

@ -47,7 +47,7 @@ describe("node_stream", function () {
response.end(`File ${request.url} not found!`);
return;
}
if (!request.headers["range"]) {
if (!request.headers.range) {
const contentLength = stat.size;
const stream = fs.createReadStream(filePath);
response.writeHead(200, {
@ -57,7 +57,7 @@ describe("node_stream", function () {
});
stream.pipe(response);
} else {
const [start, end] = request.headers["range"]
const [start, end] = request.headers.range
.split("=")[1]
.split("-")
.map(x => {

View file

@ -19,7 +19,7 @@ var TestReporter = function (browser, appPath) {
}
}
};
json["browser"] = browser;
json.browser = browser;
r.send(JSON.stringify(json));
}
@ -33,7 +33,7 @@ var TestReporter = function (browser, appPath) {
description,
};
if (typeof error !== "undefined") {
message["error"] = error;
message.error = error;
}
send("/submit_task_results", message);
}

View file

@ -107,7 +107,7 @@ describe("unicode", function () {
});
it("should not normalize standard characters", function () {
expect(NormalizedUnicodes["A"]).toEqual(undefined);
expect(NormalizedUnicodes.A).toEqual(undefined);
});
});

View file

@ -163,7 +163,7 @@ WebServer.prototype = {
return;
}
var range = req.headers["range"];
var range = req.headers.range;
if (range && !disableRangeRequests) {
var rangesMatches = /^bytes=(\d+)\-(\d+)?/.exec(range);
if (!rangesMatches) {
@ -344,11 +344,11 @@ WebServer.prototype = {
// http://localhost:8888/test/unit/unit_test.html?spec=Cross-origin
function crossOriginHandler(req, res) {
if (req.url === "/test/pdfs/basicapi.pdf?cors=withCredentials") {
res.setHeader("Access-Control-Allow-Origin", req.headers["origin"]);
res.setHeader("Access-Control-Allow-Origin", req.headers.origin);
res.setHeader("Access-Control-Allow-Credentials", "true");
}
if (req.url === "/test/pdfs/basicapi.pdf?cors=withoutCredentials") {
res.setHeader("Access-Control-Allow-Origin", req.headers["origin"]);
res.setHeader("Access-Control-Allow-Origin", req.headers.origin);
}
}