From c719978d798b5d94a9609e15845aeb69682d0790 Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Mon, 21 Oct 2024 09:17:21 -0700 Subject: [PATCH 1/2] Use type-safe equality check for narrative title MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previous check of != null would fail on non-null falsey values. In practice, I don't think Element.querySelector can return any falsey values other than null. Nevertheless, it's good to be explicit that we only care about null, i.e. no matches are found.¹ ¹ https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelector#return_value --- src/util/parseNarrative.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/parseNarrative.js b/src/util/parseNarrative.js index d426a35a7..5ab213539 100644 --- a/src/util/parseNarrative.js +++ b/src/util/parseNarrative.js @@ -91,7 +91,7 @@ function* parseNarrativeBody(markdown, fallbackDataset, markdownParser) { const titleLinkSelector = "h1 > a:only-child"; const isTitle = (node) => node.nodeType === Node.ELEMENT_NODE && - node.querySelector(titleLinkSelector) != null; + node.querySelector(titleLinkSelector) !== null; for (const titleLink of doc.querySelectorAll(titleLinkSelector)) { const slide = doc.createElement("slide"); From a2e4c548957d1dd6c7eb444ed69d4eb8a883fbd3 Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Mon, 21 Oct 2024 09:10:52 -0700 Subject: [PATCH 2/2] Enforce usage of type-safe equality operators Using == / != is a source of bugs. Rule doc page: https://eslint.org/docs/latest/rules/eqeqeq --- .eslintrc.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 3f385f2fb..51926d896 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -21,6 +21,7 @@ globals: rules: # Code quality rules + eqeqeq: error "@typescript-eslint/no-empty-function": ["error", { "allow": ["arrowFunctions"] }] "@typescript-eslint/no-explicit-any": off # Allow explicit any to make incremental TypeScript adoption easier. no-unused-vars: off