Skip to content

style: fix lint violations surfaced by the Nx 24 lint targets - #11685

Merged
NathanWalker merged 11 commits into
mainfrom
chore/lint-nx24-violations
Nov 28, 2026
Merged

NathanWalker merged 11 commits into
mainfrom
chore/lint-nx24-violations

Conversation

@NathanWalker

@NathanWalker NathanWalker commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

Stacked on #11684 (chore/nx-24). Under Nx 24 the inferred @nx/eslint/plugin lint tasks lint webpack5, the three apps and workspace-plugin for the first time, and they report existing violations. #11684 left them as an open question. This PR fixes them.

What is the new behavior?

Every project's lint target passes. No rule is turned off for a whole project.

Lint results (nx run <project>:lint --skip-nx-cache)

Project Before After
apps-automated 3230 errors 0
apps-ui 335 errors, 1 warning 0 errors, 1 warning
apps-toolbox 17 errors 0
webpack5 23 errors 0
workspace-plugin 2 errors, 1 warning 0
core 0 errors, 23 warnings 0 errors, 23 warnings (unchanged)
vite 3 errors, 22 warnings 0 errors, 22 warnings

By rule:

Project Rule Count How it was fixed
apps-automated no-var 1897 1535 by autofix. 361 by hand: ESLint never autofixes an exported var or one referenced before its declaration, so these went var to let, then prefer-const autofix. One kept as var with a reason.
apps-automated prefer-const 864 Autofix, except 38 let x; … x = v; cases merged by hand into const x = v;
apps-automated @nx/enforce-module-boundaries 429 Config: see below
apps-automated @typescript-eslint/prefer-as-const 33 Applied the rule's suggestion (= 'row' as const)
apps-automated no-constant-binary-expression 4 TKUnit.assert(true === true) → TKUnit.assert(true)
apps-automated @typescript-eslint/triple-slash-reference 1 Config: see below
apps-automated @typescript-eslint/no-unused-expressions 1 Removed a bare ModuleNameResolver; statement
apps-automated prefer-spread 1 Array.apply(null, Array(10)) → [...Array(10)]
apps-ui no-var 171 169 by autofix, 2 exported var → const by hand
apps-ui prefer-const 163 Autofix
apps-ui no-extra-boolean-cast 1 Autofix (!!!x → !x)
apps-toolbox prefer-const / no-var 16 / 1 Autofix
webpack5 prefer-const 23 Autofix
workspace-plugin @nx/dependency-checks 2 Declared the real dependency, dropped the unused one
workspace-plugin unused eslint-disable (warning) 1 Removed
vite no-fallthrough 2 Added // falls through to the two intentional empty-case fallthroughs
vite no-irregular-whitespace 1 /^<literal U+FEFF>/ → /^/ (same regex)

Left as is: the apps-ui warning (an unused require('webpack') in apps/ui/webpack.config.js), and the core and vite warnings (no-this-alias, and "Unused eslint-disable directive" from ESLint 9's reportUnusedDisableDirectives).

Checking var → let/const

apps/automated runs only on a device, so a temporal dead zone (TDZ) error would only show up at runtime. The changes were checked for this:

  • ESLint's no-var autofix skips any var that is referenced before its declaration, captured per-iteration in a loop, redeclared, used outside its block, or declared directly in a case.
  • That still leaves one gap: a hoisted function declaration, or a callback passed to a call, that reads the binding and runs before the declaration. Every converted binding (1536 autofixed and 362 by hand in apps-automated, 171 in apps-ui) was checked with the TypeScript AST for references that could run before the declaration. A reference counts as safe only when it sits inside a function value that cannot be invoked before the declaration. None were found. The 22 hand-converted bindings with earlier references (for example _createButtonFunc, used by the export const test… = function bodies above it) are all read only inside test functions, and those run after the module has loaded.
  • Exported var → const does not change how the test runner finds tests: it enumerates module exports, and nothing reassigns them. Type checking would report any reassignment of a const.

Hand fixes where var semantics mattered:

  • application/application-tests.ios.ts: observer was declared with var inside an if and used after it. It is now declared before the if.
  • xml-parser-tests.ts: two case clauses declared variables. They now have their own block, which no-case-declarations requires.
  • ui/repeater/repeater-tests.ts: the date converter padded the day using month before declaring it (hoisted, so always undefined). With const this would throw. It now pads on day, the same as the identical converter in list-view-tests.ts. The test compares the converter against itself, so its result doesn't change.
  • Kept as var with an eslint-disable-next-line no-var -- <reason>:
    • file-system/file-system-tests.ts: const globalConsole = console; var console = {…} relies on hoisting. globalConsole reads undefined today; with let it would throw.
    • globals.d.ts: declare var __CI__, because an ambient global needs declare var to also exist on globalThis.

Config decisions

  1. @nx/enforce-module-boundaries "lazy-loaded library" (429 errors). The cause is a single line in apps/automated/src/ui/animation/animation-tests.ts: require('@nativescript/core/ui/animation')._getTransformMismatchErrorMessage. It is a require() because that function exists only in index.ios.ts and isn't declared in the .d.ts. Nx records require() as a dynamic dependency, so the rule treated core as lazy-loaded and reported every static @nativescript/core import in the project. The fix sets the rule's checkDynamicDependenciesExceptions: ['@nativescript/core', '@nativescript/core/**'] in the root config. NativeScript apps bundle core whole and never code-split it, so the check doesn't apply to core. Every other module-boundary check (dependency constraints, buildable-lib, circular) is still enforced. I chose this over rewriting the test import: the require() is a legitimate platform-conditional lookup, and the rule would fire again the next time a test does the same thing.
  2. @typescript-eslint/triple-slash-reference. The root config already turns it off for **/references.d.ts. apps/automated/reference.d.ts is the same file under a singular name, so it was added to that override.

workspace-plugin

@nx/dependency-checks reported that the app generator imports @angular-devkit/schematics but package.json doesn't declare it, and that tslib is declared but unused (importHelpers is off). @angular-devkit/schematics is now declared as ^18.2.21, the installed version, and tslib is removed. The root package.json and the lockfile are unchanged: the package arrives transitively through @nstudio/focus.

Formatting

The pre-commit lint-staged hook ran Prettier on each touched file. In apps/ui and apps/automated it also reformatted about 20 lines next to the fixes (trailing commas, wrapped constructor parameters). prettier --check passes on every changed file.

Commits

  1. fix(workspace-plugin): declare dependencies
  2. build(lint): exempt @nativescript/core from the lazy-loaded library check
  3. style(webpack5): apply eslint autofixes
  4. style(apps): apply eslint autofixes to toolbox
  5. style(apps): apply eslint autofixes to ui
  6. style(apps): apply eslint autofixes to automated
  7. build(lint): allow the triple-slash reference in apps/automated/reference.d.ts
  8. fix(apps): resolve the lint errors that autofix leaves in the test apps
  9. style(vite): fix the remaining lint errors
  10. style: fix lint errors in code added since the lint sweep: two export var typed-array body tests (fix(http): send typed array, DataView and Blob request bodies #11654) and a never-reassigned let TransitionListener (fix(android): stop fragment transition listeners from holding their transition #11656) that reached main after the sweep.
  11. build(lint): ignore native platform build output in apps: apps/**/platforms/** is generated by a local ns build and is gitignored; without the ignore, apps-automated:lint reports thousands of errors from the bundled .mjs files.

Verification

The baseline is chore/nx-24 after npm ci. Everything ran with --skip-nx-cache.

Check Baseline This PR
lint (7 projects) see the table above see the table above
tsc --noEmit for apps/automated, apps/ui, apps/toolbox 826 / 400 / 130 errors (existing: unresolved platform modules and the like) the same errors, compared as file + code + message with positions ignored
tsc --noEmit for webpack5 (tsconfig.json, tsconfig.lib.json) and workspace-plugin (tsconfig.lib.json, tsconfig.spec.json) 0 0
core:test 565 passed, 1 skipped 565 passed, 1 skipped
vite:test 1929 passed 1929 passed
webpack5:test 16 failed / 65 passed the same 16 failed / 65 passed
workspace-plugin:test no tests no tests
nx run-many -t build -p core,webpack5,vite pass pass
workspace-plugin:build pass
prettier --check (changed files) pass

The apps/automated device suite wasn't run locally. The apps/automated/ios and apps/automated/android workflows run on this PR.

Notes

  • workspace-plugin's only generator calls externalSchematic('@nx/workspace', 'lib', …), an Angular-devkit schematic bridge. Its dependency is now declared, but whether that schematic still exists under Nx 24 wasn't checked. The generator may be dead code.

@nx-cloud

nx-cloud Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 93a4ed1

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 4s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-11-28 00:36:25 UTC

@pkg-pr-new

pkg-pr-new Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nativescript/core@11685
npm i https://pkg.pr.new/@nativescript/vite@11685
npm i https://pkg.pr.new/@nativescript/webpack@11685

commit: 93a4ed1

@NathanWalker NathanWalker mentioned this pull request Nov 25, 2026
3 of 5 tasks
@NathanWalker
NathanWalker force-pushed the chore/lint-nx24-violations branch from f824d5b to 9e36e46 Compare November 28, 2026 00:17
@NathanWalker
NathanWalker force-pushed the chore/lint-nx24-violations branch from 9e36e46 to c0bdaa3 Compare November 28, 2026 00:30
Base automatically changed from chore/nx-24 to main November 28, 2026 00:33
Declare @angular-devkit/schematics, which the app generator imports, and drop tslib, which nothing uses (importHelpers is off). Also remove the unused eslint-disable directive from jest.config.ts.
…heck

apps/automated has one platform-conditional require() of @nativescript/core/ui/animation. Nx records require() as a dynamic dependency, so enforce-module-boundaries reported every static @nativescript/core import in the project (429 errors) as a static import of a lazy-loaded library. NativeScript apps bundle core whole and never code-split it, so the check does not apply to core.
prefer-const, plus one function-local no-var.
no-var, prefer-const and one no-extra-boolean-cast. ESLint only autofixes a var when no reference precedes it; a check for hoisted function declarations that could reach a converted binding before its declaration found none.
no-var and prefer-const. ESLint only autofixes a var when no reference precedes it and it is not captured per-iteration in a loop; a check for hoisted function declarations or callbacks that could reach a converted binding before its declaration found none.
…ence.d.ts

It is the automated app's counterpart of the references.d.ts files the rule is already off for: a triple-slash reference is how it pulls in core's ambient types.
- no-var on exported and early-referenced declarations (ESLint never
  autofixes these): var -> let, then prefer-const autofix. References
  that precede a declaration are all inside test functions or callbacks
  that cannot run before it.
- application-tests.ios.ts: declare the observer before the if-block it
  was assigned in.
- xml-parser-tests.ts: give the two case clauses that declared variables
  their own block.
- repeater-tests.ts: the date converter read month before declaring it
  when padding the day; pad on day, as the list-view copy does.
- file-system-tests.ts and globals.d.ts keep var, with a reason.
- prefer-const on `let x; ... x = v;`: declare at the assignment.
- prefer-as-const: apply the rule's suggestion.
- no-constant-binary-expression, no-unused-expressions, prefer-spread:
  assert(true), drop a bare ModuleNameResolver statement, spread instead
  of Array.apply.
Mark the intentional empty-case fallthroughs in the optimizeDeps flavor switch, and write the BOM in the css-device-module regex as \uFEFF instead of a literal U+FEFF. No behavior change.
Covers the typed-array body tests and the fragment TransitionListener that landed on main after the initial pass.
apps/*/platforms holds generated bundles after a local ns build; linting them reports thousands of errors.
@NathanWalker
NathanWalker force-pushed the chore/lint-nx24-violations branch from c0bdaa3 to 93a4ed1 Compare November 28, 2026 00:33
@NathanWalker
NathanWalker merged commit 7aea47d into main Nov 28, 2026
13 checks passed
@NathanWalker
NathanWalker deleted the chore/lint-nx24-violations branch November 28, 2026 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant