Skip to content

refactor(lint): clear the directory scanner's TypeScript warnings - #725

Merged
Quorafind merged 5 commits into
masterfrom
refactor/scanner-ts-warnings
Nov 29, 2026
Merged

Quorafind merged 5 commits into
masterfrom
refactor/scanner-ts-warnings

Conversation

@Quorafind

Copy link
Copy Markdown
Member

Clears the remaining TypeScript warnings that the community-directory scanner reports. It runs eslint-plugin-obsidianmd 0.4.1, the version pinned by obsidian-workflows, without the calendar submodule.

Rule Before After
Promise-returning function passed where void is expected / Promise passed as an argument 10 + 2 0
Non-Promise value used in a boolean condition 8 0
Unnecessary type assertion (both variants) 7 + 4 0
clearTimeout / setTimeout instead of window.* 7 + 6 0
Node built-in import (http / url / net) 5 + 1 + 1 0
any swallowing a union / unresolved error type 4 + 2 0
require()-style import 4 0
global / globalThis 2 + 1 0
TFile cast, document.createElement 1 + 1 0
Unused _ (info) 9 0

getSettingDefinitions() (the declarative settings API) is left for a separate change.

Worth a look

  • Node built-ins. The MCP server (http, url), its port probe (net) and the Google OAuth callback server (http) now load these modules with await import() inside a function whose first statement is if (!Platform.isDesktop) throw …. Their types come from import("http") type aliases, which emit no code.
  • esbuild.config.mjs adds supported: { "dynamic-import": false }. Without it, import("http") would stay a native dynamic import, which can't resolve in Obsidian's renderer. With it, the call compiles to the same deferred require() as before. This setting changes the bundle only at those four call sites.
  • Error handling. The async request listener for MCP requests is wrapped so a rejected request is logged with console.error instead of becoming an unhandled rejection.
  • Mobile emulation. In the desktop app's "emulate mobile" developer mode, the MCP and OAuth servers now refuse to start, because Platform.isDesktop is false there.
  • src/test-setup.ts.
    • The console mocks are now set on the console object itself, because two test suites run in the node environment, where window doesn't exist.
    • The window.performance mock is removed. jsdom's window.performance has a getter and no setter, so the old assignment never took effect.

Verification

Still to check by hand on desktop:

  • MCP: enable it and confirm the start notice appears and /health responds, and that a port conflict still shows the conflict notice.
  • Google Calendar: connect it and confirm OAuth completes.

…flags

Scanner rule @typescript-eslint/no-misused-promises (obsidianmd 0.4.1,
as the community directory runs it): 20 -> 0.

Promise-returning function provided to a void property (10):
TaskView, TaskSpecificView and TaskBasesView passed the async
toggleTaskCompletion as onTaskCompleted to Kanban, Gantt, Quadrant and
ViewComponentManager, which call it fire-and-forget. They now pass a sync
handler. TaskSpecificView/TaskBasesView catch and log the rejection with
console.error, as their other toggleTaskCompletion call sites do; TaskView
uses `void`, like its other call sites.

Promise returned in a function argument (2): the task-completed workspace
listener in OnCompletionManager now catches and logs a rejection of
handleTaskCompleted instead of leaving it unhandled; the forEach callback
in ViewTaskFilter no longer returns the chaining DropdownComponent.

Non-Promise value expected in a boolean conditional (8): Obsidian's
TextComponent/ToggleComponent declare a chaining `then`, so truthiness
checks on them read as checks on a promise. The text-replacement modals
check `testInput?.getValue()` (testInput is now typed as possibly
undefined, which it is until the test field renders), and the filter
panel calls `toggle?.setValue(...)`. Same behaviour.
Scanner rules (obsidianmd 0.4.1): prefer-window-timers 13 -> 0,
no-global-this 3 -> 0.

ProjectDataWorkerManager, TaskWorkerManager and WorkerOrchestrator run on
the main thread (the worker scripts import none of them), so their
setTimeout/clearTimeout calls now go through window. PoolWorker's
timeoutHandle is typed number, which window.setTimeout returns. The
__taskGeniusDebug.workerTimeoutMs override is read from window instead of
globalThis; no test sets it.

src/test-setup.ts: the console mocks are assigned onto the console object
instead of replacing global.console, since two suites run in the node
environment, where there is no window. The performance mock is dropped:
jsdom's window.performance is a getter without a setter, so
`global.performance = ...` never took effect in the jsdom suites (checked
with jest.isMockFunction(performance.now)), and the two node suites read
SCSS files without timing anything. Applying the mock for real makes the
calendar caching benchmark compare two 0 ms readings.
…p guard

Scanner rules (obsidianmd 0.4.1): no-nodejs-modules 7 -> 0,
@typescript-eslint/no-require-imports 4 -> 0.

The MCP server (http, url), its port probe (net) and the Google OAuth
callback server (http) already loaded Node's modules with a guarded
require() inside the function that needs them, and their types with
`import type`. The 0.4.1 rule the directory scanner runs still reports
both: it flags every import declaration of a Node built-in, type-only
ones included, and accepts only `Platform.isDesktop` (not isDesktopApp)
in an early exit that is the function's first statement.

- The http types are now import() type aliases, which emit nothing.
- The modules are loaded with `await import(...)` in a function whose
  first statement is `if (!Platform.isDesktop) throw ...`, with the same
  error messages as before: McpServer.loadNodeModules() (called first in
  start(), as the old guard was), McpServerManager.isPortAvailable() (now
  async; both callers already await it) and
  CalendarAuthManager.startCallbackServer().
- esbuild keeps import() of an external module as a native import(),
  which cannot resolve "http" in Obsidian's renderer. `supported:
  { "dynamic-import": false }` makes it emit
  `Promise.resolve().then(() => __toESM(require("http")))`, the same
  require() as before, still only run when the server starts. The bundle
  differs from one built without the option only at these four imports.
- With http typed instead of `any`, the async request listener given to
  http.createServer is wrapped in logRejections(), which logs a rejected
  request with console.error instead of leaving it unhandled; the
  listener body is unchanged.

Platform.isDesktop is false in the desktop app only under the developer
"emulate mobile" mode, where the MCP and OAuth servers now refuse to
start; on phones and tablets nothing changes.
…nions

Scanner rules (obsidianmd 0.4.1): no-unnecessary-type-assertion
11 -> 0, no-redundant-type-constituents 6 -> 0.

The directory scanner never checks out the packages/calendar submodule
and cannot install the @codemirror/language GitHub fork, so types from
@taskgenius/calendar and syntaxTree() are unresolved there and act as
`any`. Several findings exist only in that environment; the changes below
keep the same types where they do resolve.

Unnecessary assertions:
- moment(currentDate) without `as unknown as Date` (agenda/year views).
- TGAgendaView/TGYearView.convertEvents build the array into an
  `unknown` binding and assert it once; the outer `as unknown as` was
  reported where the TG event type is unresolved.
- DatePickerComponent types its quick options, so `option.unit` needs no
  assertion.
- t() already returns string (MCP settings tab); the time-range display
  element needs no HTMLElement cast to set textContent.

Redundant type constituents:
- CustomViewCalendarConfig is an interface extending
  ExtendedCalendarConfig instead of an intersection.
- CalendarComponent.tgCalendar is an optional field instead of
  `Calendar | null`; it was only ever truth-tested.
- dayFilter/timeFilter are typed ViewConfig["dayFilter"/"timeFilter"],
  the same function types the view config takes.
- date-picker-utils names `SyntaxNode | null` as SyntaxNode["parent"].
…ed `_`

Scanner rules (obsidianmd 0.4.1): no-tfile-tfolder-cast 1 -> 0,
prefer-create-el 1 -> 0, @typescript-eslint/no-unused-vars 9 -> 0.

- DuplicateActionExecutor narrows the getFileByPath() result with
  instanceof TFile instead of casting it first; it creates the target file
  in the same cases as before.
- The tray icon canvas is made with createEl("canvas").
- Unused `_` bindings: `catch {}` without a binding (FluentIntegration,
  FluentLayoutManager, TimelineSidebarView, closed/completed status
  predicates) and array holes `[symbol, , type]` / `[, mark]` in
  destructuring (TaskStatusSettingsTab, status-cycler), as elsewhere in
  the code base.
@Quorafind
Quorafind merged commit aea682c into master Nov 29, 2026
3 of 4 checks passed
@Quorafind
Quorafind deleted the refactor/scanner-ts-warnings branch November 29, 2026 03:45
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant