From a3aff4c04e2516297e3cbe827d9fe9259809e2c8 Mon Sep 17 00:00:00 2001 From: James Manuel Date: Fri, 31 Jul 2026 12:42:32 +0200 Subject: [PATCH] chore(lint): enable no-undef for the native browser shims common/Native/ stubs window, document, navigator, console, setTimeout and performance for the embedded JS context used by DoctRenderer/x2t. Nothing in CI executes that bundle - the QUnit suites run in a real browser, where these stubs are never loaded - so an undeclared identifier here reaches production completely unexercised. Enable no-undef for those files and run eslint in the code-style job. Scoped deliberately: repo-wide the rule reports ~86k violations across 1437 identifiers, almost all legitimate cross-module namespaces (AscCommon, AscDFH, Asc, AscFormat), which would need a globals list larger than the rule is worth. browser is set to false for these files because they provide the browser globals rather than consuming them; leaving it on makes every stub read as a redeclaration of a built-in. The three host globals injected by the converter before any script runs are declared instead, with references to where core installs them. jquery_native.js is ignored, matching tests/code-style/check.py. Co-Authored-By: Claude Opus 5 (1M context) Signed-off-by: James Manuel --- .eslintignore | 2 ++ .eslintrc.yaml | 46 +++++++++++++++++++++++++++++++ .github/workflows/check-build.yml | 12 ++++++++ 3 files changed, 60 insertions(+) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000000..dc2d62d347 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +# Vendored jQuery fork. tests/code-style/check.py excludes it as well. +common/Native/jquery_native.js diff --git a/.eslintrc.yaml b/.eslintrc.yaml index e88f956150..9b407fb613 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -36,3 +36,49 @@ rules: # Stylistic Issues # http://eslint.org/docs/rules/#stylistic-issues linebreak-style: [error, unix] + +overrides: + # The files in common/Native stub the browser environment for the embedded JS + # context used by DoctRenderer/x2t. Nothing in CI executes that bundle - the + # QUnit suites run in a real browser, where these stubs are never loaded - so + # an undeclared identifier here reaches production completely unexercised. + # That is how console.error() came to reference an undeclared `param` and + # abort every converter operation that logged an error. + # + # no-undef is enabled for this directory only. Enabling it repo-wide would + # report ~86k violations across 1437 identifiers, almost all of them + # legitimate cross-module namespaces (AscCommon, AscDFH, Asc, AscFormat, ...), + # which would need a globals list larger than the rule is worth. + # `browser: false` in both blocks below is deliberate and load-bearing. These + # files *provide* window/document/navigator/console/setTimeout/performance for + # a context that has none. Treating them as browser code makes every stub read + # as a redeclaration of a built-in and buries the real defects in the noise. + # + # The two host globals are injected by the converter before any script runs: + # window -> the global object itself, doctrenderer.cpp:579 + # native -> doctrenderer.cpp:583 (global_js->set("native", ...)) + # CreateEmbedObject -> js_internal/v8/v8_base.cpp:218 (InsertToGlobal) + - files: + - common/Native/native.js + env: + browser: false + es2015: true + globals: + window: readonly + native: readonly + rules: + no-undef: error + + - files: + - common/Native/native_graphics.js + env: + browser: false + es2015: true + globals: + window: readonly + CreateEmbedObject: readonly + # Declared by native.js, which editors.cpp (GetAllScript) concatenates + # ahead of this file. + AscCommon: readonly + rules: + no-undef: error diff --git a/.github/workflows/check-build.yml b/.github/workflows/check-build.yml index 584ad8a016..1c1ca1e78d 100644 --- a/.github/workflows/check-build.yml +++ b/.github/workflows/check-build.yml @@ -22,6 +22,18 @@ jobs: - name: execute check styles run: python tests/code-style/check.py + - name: setup node + uses: actions/setup-node@v6 + with: + node-version: 20 + + # Scoped to common/Native on purpose - see the overrides block in + # .eslintrc.yaml. Those shims are the one part of the tree that no test + # ever executes, so no-undef is the only thing standing between an + # undeclared identifier and a converter that aborts on every logged error. + - name: lint native shims + run: npx --yes eslint@8.57.1 'common/Native/*.js' + unit-tests: runs-on: ubuntu-latest steps: