Repository navigation
refactor(lint): clear the directory scanner's TypeScript warnings - #725
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
clearTimeout/setTimeoutinstead ofwindow.*http/url/net)anyswallowing a union / unresolvederrortyperequire()-style importglobal/globalThisTFilecast,document.createElement_(info)getSettingDefinitions()(the declarative settings API) is left for a separate change.Worth a look
http,url), its port probe (net) and the Google OAuth callback server (http) now load these modules withawait import()inside a function whose first statement isif (!Platform.isDesktop) throw …. Their types come fromimport("http")type aliases, which emit no code.esbuild.config.mjsaddssupported: { "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 deferredrequire()as before. This setting changes the bundle only at those four call sites.console.errorinstead of becoming an unhandled rejection.Platform.isDesktopis false there.src/test-setup.ts.windowdoesn't exist.window.performancemock is removed. jsdom'swindow.performancehas a getter and no setter, so the old assignment never took effect.Verification
tscpass.Still to check by hand on desktop:
/healthresponds, and that a port conflict still shows the conflict notice.