From 47dbfc4ade2893d5cb6d3c35cfcab3e93f996511 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 27 Nov 2022 17:16:46 +0100 Subject: [PATCH] Enable the `no-typeof-undefined` ESLint plugin rule Please see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-typeof-undefined.md --- .eslintrc | 1 + src/display/canvas.js | 6 ++---- src/display/fetch_stream.js | 2 +- src/display/network.js | 2 +- src/display/node_stream.js | 2 +- systemjs.config.js | 2 +- test/unit/testreporter.js | 2 +- 7 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.eslintrc b/.eslintrc index 15a47c299..6d151bc27 100644 --- a/.eslintrc +++ b/.eslintrc @@ -61,6 +61,7 @@ "unicorn/prefer-modern-dom-apis": "error", "unicorn/prefer-regexp-test": "error", "unicorn/prefer-string-starts-ends-with": "error", + "unicorn/no-typeof-undefined": ["error", { "checkGlobalVariables": false, }], // Possible errors "for-direction": "error", diff --git a/src/display/canvas.js b/src/display/canvas.js index d447cf7a9..a49b8fae0 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -1870,8 +1870,7 @@ class CanvasGraphics { this.ctx.closePath(); } - stroke(consumePath) { - consumePath = typeof consumePath !== "undefined" ? consumePath : true; + stroke(consumePath = true) { const ctx = this.ctx; const strokeColor = this.current.strokeColor; // For stroke we want to temporarily change the global alpha to the @@ -1904,8 +1903,7 @@ class CanvasGraphics { this.stroke(); } - fill(consumePath) { - consumePath = typeof consumePath !== "undefined" ? consumePath : true; + fill(consumePath = true) { const ctx = this.ctx; const fillColor = this.current.fillColor; const isPatternFill = this.current.patternFill; diff --git a/src/display/fetch_stream.js b/src/display/fetch_stream.js index 7cb1f3c8c..a2d19f563 100644 --- a/src/display/fetch_stream.js +++ b/src/display/fetch_stream.js @@ -46,7 +46,7 @@ function createHeaders(httpHeaders) { const headers = new Headers(); for (const property in httpHeaders) { const value = httpHeaders[property]; - if (typeof value === "undefined") { + if (value === undefined) { continue; } headers.append(property, value); diff --git a/src/display/network.js b/src/display/network.js index b199d9846..59d6bc933 100644 --- a/src/display/network.js +++ b/src/display/network.js @@ -82,7 +82,7 @@ class NetworkManager { xhr.withCredentials = this.withCredentials; for (const property in this.httpHeaders) { const value = this.httpHeaders[property]; - if (typeof value === "undefined") { + if (value === undefined) { continue; } xhr.setRequestHeader(property, value); diff --git a/src/display/node_stream.js b/src/display/node_stream.js index 44866fbc5..238881b0e 100644 --- a/src/display/node_stream.js +++ b/src/display/node_stream.js @@ -373,7 +373,7 @@ class PDFNodeStreamRangeReader extends BaseRangeReader { this._httpHeaders = {}; for (const property in stream.httpHeaders) { const value = stream.httpHeaders[property]; - if (typeof value === "undefined") { + if (value === undefined) { continue; } this._httpHeaders[property] = value; diff --git a/systemjs.config.js b/systemjs.config.js index a4a02bc0f..10ac23a23 100644 --- a/systemjs.config.js +++ b/systemjs.config.js @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* eslint-disable no-var */ +/* eslint-disable no-var, unicorn/no-typeof-undefined */ "use strict"; diff --git a/test/unit/testreporter.js b/test/unit/testreporter.js index b87f4b450..924f79bf5 100644 --- a/test/unit/testreporter.js +++ b/test/unit/testreporter.js @@ -35,7 +35,7 @@ const TestReporter = function (browser) { status, description, }; - if (typeof error !== "undefined") { + if (error !== undefined) { message.error = error; } send("/submit_task_results", message);