From 5c712f2131346fcdde202408af1378fe7e3cb6f3 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 12 Mar 2021 17:12:41 +0100 Subject: [PATCH] Enable the ESLint `no-var` rule in the `examples/` folder Updating the examples to use `let`/`const` should be fine, given that they are available in all browsers/platforms that the PDF.js library now supports; please note the following compatibility information: - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#browser_compatibility - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const#browser_compatibility --- examples/.eslintrc | 5 +++++ examples/mobile-viewer/viewer.js | 4 +++- examples/node/domstubs.js | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/.eslintrc b/examples/.eslintrc index 433abdbfa..14eeee2f8 100644 --- a/examples/.eslintrc +++ b/examples/.eslintrc @@ -8,4 +8,9 @@ "pdfjsLib": false, "pdfjsViewer": false, }, + + "rules": { + // ECMAScript 6 + "no-var": "error", + }, } diff --git a/examples/mobile-viewer/viewer.js b/examples/mobile-viewer/viewer.js index 4d5891151..b4f837d53 100644 --- a/examples/mobile-viewer/viewer.js +++ b/examples/mobile-viewer/viewer.js @@ -35,7 +35,7 @@ const MIN_SCALE = 0.25; const MAX_SCALE = 10.0; const DEFAULT_SCALE_VALUE = "auto"; -var PDFViewerApplication = { +const PDFViewerApplication = { pdfLoadingTask: null, pdfDocument: null, pdfViewer: null, @@ -425,6 +425,8 @@ var PDFViewerApplication = { }, }; +window.PDFViewerApplication = PDFViewerApplication; + document.addEventListener( "DOMContentLoaded", function () { diff --git a/examples/node/domstubs.js b/examples/node/domstubs.js index d4bfa8dde..1d1039a0b 100644 --- a/examples/node/domstubs.js +++ b/examples/node/domstubs.js @@ -188,9 +188,9 @@ DOMElementSerializer.prototype = { this._loopIndex = 0; /* falls through */ case 5: // Serialize child nodes (only for non-tspan/style elements). - var value; while (true) { - value = this._childSerializer && this._childSerializer.getNext(); + const value = + this._childSerializer && this._childSerializer.getNext(); if (value !== null) { return value; }