From 0b2e0ce1b614b4e78d81e1d05f8ef72c628ebf51 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Thu, 19 Mar 2026 10:57:43 -0700 Subject: [PATCH] Fix linting issues --- src/main.ts | 25 +++++++++--------- src/modals/daily-note-select-modal.ts | 38 +++++++++++++-------------- src/modals/heading-select-modal.ts | 4 +-- src/modals/note-select-modal.ts | 4 +-- src/settings.ts | 6 ++--- src/views/todo-sidebar-view.ts | 34 +++++++++++++----------- tsconfig.json | 3 ++- 7 files changed, 58 insertions(+), 56 deletions(-) diff --git a/src/main.ts b/src/main.ts index 64226ef..e3912cf 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,9 +1,9 @@ import { Plugin, WorkspaceLeaf } from 'obsidian'; -import { DEFAULT_SETTINGS, MyPluginSettings, SampleSettingTab } from './settings'; +import { DEFAULT_SETTINGS, TodoTrackerSettings, TodoTrackerSettingTab } from './settings'; import { TodoSidebarView, TODO_VIEW_TYPE } from './views/todo-sidebar-view'; export default class TodoTrackerPlugin extends Plugin { - settings: MyPluginSettings; + settings: TodoTrackerSettings; async onload() { await this.loadSettings(); @@ -14,26 +14,25 @@ export default class TodoTrackerPlugin extends Plugin { }); // Add ribbon icon to open todo tracker - this.addRibbonIcon('check-square', 'Open Todo Tracker', () => { - this.activateView(); + this.addRibbonIcon('check-square', 'Open todo tracker', () => { + void this.activateView(); }); // Add command to toggle todo tracker this.addCommand({ - id: 'open-todo-tracker', - name: 'Open Todo Tracker', + id: 'open', + name: 'Open sidebar', callback: () => { - this.activateView(); + void this.activateView(); }, }); // Add settings tab - this.addSettingTab(new SampleSettingTab(this.app, this)); + this.addSettingTab(new TodoTrackerSettingTab(this.app, this)); } onunload() { - // Detach all leaves of this view type to ensure clean unload - this.app.workspace.detachLeavesOfType(TODO_VIEW_TYPE); + // Cleanup is handled automatically by registered events } async activateView(): Promise { @@ -45,7 +44,7 @@ export default class TodoTrackerPlugin extends Plugin { // Reveal the existing view const leaf = existingLeaves[0]; if (leaf) { - workspace.revealLeaf(leaf); + await workspace.revealLeaf(leaf); } return; } @@ -57,12 +56,12 @@ export default class TodoTrackerPlugin extends Plugin { type: TODO_VIEW_TYPE, active: true, }); - workspace.revealLeaf(leaf); + await workspace.revealLeaf(leaf); } } async loadSettings() { - this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData() as Partial); + this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData() as Partial); } async saveSettings() { diff --git a/src/modals/daily-note-select-modal.ts b/src/modals/daily-note-select-modal.ts index 1ac8a9f..50baf80 100644 --- a/src/modals/daily-note-select-modal.ts +++ b/src/modals/daily-note-select-modal.ts @@ -1,25 +1,25 @@ import { App, Modal, Setting } from 'obsidian'; export class DailyNoteSelectModal extends Modal { - constructor(app: App, onSubmit: (result: string) => void) { - super(app); - this.setTitle('Select a daily note'); - - let name = ''; - new Setting(this.contentEl) - .setName('Date') - .addMomentFormat((component) => { - - }); - - new Setting(this.contentEl) - .addButton((btn) => - btn - .setButtonText('Submit') - .setCta() - .onClick(() => { + constructor(app: App, onSubmit: (result: string) => void) { + super(app); + this.setTitle('Select a daily note'); + + let name = ''; + new Setting(this.contentEl) + .setName('Date') + .addMomentFormat((component) => { + + }); + + new Setting(this.contentEl) + .addButton((btn) => + btn + .setButtonText('Submit') + .setCta() + .onClick(() => { this.close(); onSubmit(name); - })); - } + })); + } } diff --git a/src/modals/heading-select-modal.ts b/src/modals/heading-select-modal.ts index b5cd252..a95fd38 100644 --- a/src/modals/heading-select-modal.ts +++ b/src/modals/heading-select-modal.ts @@ -55,8 +55,8 @@ export class HeadingSelectModal extends FuzzySuggestModal { return option.displayText; } - async onChooseItem(option: HeadingOption): Promise { - await this.moveTodo(option.heading); + onChooseItem(option: HeadingOption): void { + void this.moveTodo(option.heading); } private async moveTodo(selectedHeading: HeadingCache | null): Promise { diff --git a/src/modals/note-select-modal.ts b/src/modals/note-select-modal.ts index 9417058..050b557 100644 --- a/src/modals/note-select-modal.ts +++ b/src/modals/note-select-modal.ts @@ -22,7 +22,7 @@ export class NoteSelectModal extends FuzzySuggestModal { return file.path; } - async onChooseItem(file: TFile): Promise { + onChooseItem(file: TFile): void { // Get headings from the target file const fileCache = this.app.metadataCache.getFileCache(file); const headings = fileCache?.headings ?? []; @@ -38,7 +38,7 @@ export class NoteSelectModal extends FuzzySuggestModal { ).open(); } else { // No headings - move directly to beginning of file - await this.moveTodo(file); + void this.moveTodo(file); } } diff --git a/src/settings.ts b/src/settings.ts index e67fa2b..92490bb 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1,15 +1,15 @@ import {App, PluginSettingTab, Setting} from "obsidian"; import TodoTrackerPlugin from "./main"; -export interface MyPluginSettings { +export interface TodoTrackerSettings { mySetting: string; } -export const DEFAULT_SETTINGS: MyPluginSettings = { +export const DEFAULT_SETTINGS: TodoTrackerSettings = { mySetting: 'default' } -export class SampleSettingTab extends PluginSettingTab { +export class TodoTrackerSettingTab extends PluginSettingTab { plugin: TodoTrackerPlugin; constructor(app: App, plugin: TodoTrackerPlugin) { diff --git a/src/views/todo-sidebar-view.ts b/src/views/todo-sidebar-view.ts index 5f87b2d..3f7d8ca 100644 --- a/src/views/todo-sidebar-view.ts +++ b/src/views/todo-sidebar-view.ts @@ -1,4 +1,4 @@ -import { ItemView, Platform, TFile, WorkspaceLeaf } from 'obsidian'; +import { App, ItemView, Platform, TFile, WorkspaceLeaf } from 'obsidian'; import type { TodoItem, TodoGroup } from '../core/types'; import { parseTodosGroupedByHeading } from '../core/todo-parser'; import { toggleTodo } from '../core/todo-transformer'; @@ -27,7 +27,7 @@ export class TodoSidebarView extends ItemView { } getDisplayText(): string { - return 'Todo Tracker'; + return 'Todo tracker'; } getIcon(): string { @@ -44,14 +44,14 @@ export class TodoSidebarView extends ItemView { this.registerEvent( this.app.workspace.on('active-leaf-change', () => { - this.refresh(); + void this.refresh(); }) ); this.registerEvent( this.app.vault.on('modify', (file) => { if (this.currentFile && file.path === this.currentFile.path) { - this.refresh(); + void this.refresh(); } }) ); @@ -142,7 +142,7 @@ export class TodoSidebarView extends ItemView { group: TodoGroup ): void { const itemEl = createTodoItemEl(container, todo, { - onToggle: (t) => this.handleToggle(file, t), + onToggle: (t) => { void this.handleToggle(file, t); }, onMoveClick: (t) => this.handleMoveClick(t, file), onMoveDailyNoteClick: (t) => this.handleMoveDailyNoteClick(t, file), onClick: (t) => this.openTodoInEditor(file, t), @@ -163,9 +163,9 @@ export class TodoSidebarView extends ItemView { group: TodoGroup ): void { // Find the child's
  • element within the parent - const childEl = parentEl.querySelector( + const childEl = parentEl.querySelector( `li[data-line-number="${todo.lineNumber}"]` - ) as HTMLElement | null; + ); if (childEl) { this.flatTodoList.push({ todo, element: childEl, group }); @@ -222,15 +222,19 @@ export class TodoSidebarView extends ItemView { } private isToggleCheckboxHotkey(evt: KeyboardEvent): boolean { - // Bug 3 fix: properly match Obsidian hotkeys using correct API - const hotkeyManager = (this.app as any).hotkeyManager; + interface HotkeyDef { modifiers: string[]; key: string; } + interface HotkeyManager { + getHotkeys(commandId: string): HotkeyDef[]; + getDefaultHotkeys(commandId: string): HotkeyDef[]; + } + const hotkeyManager = (this.app as App & { hotkeyManager?: HotkeyManager }).hotkeyManager; if (!hotkeyManager) return false; const commandId = 'editor:toggle-checklist-status'; // Get custom hotkeys (user-configured), then fall back to defaults - const customHotkeys = hotkeyManager.getHotkeys?.(commandId) ?? []; - const defaultHotkeys = hotkeyManager.getDefaultHotkeys?.(commandId) ?? []; + const customHotkeys = hotkeyManager.getHotkeys(commandId); + const defaultHotkeys = hotkeyManager.getDefaultHotkeys(commandId); const allHotkeys = [...customHotkeys, ...defaultHotkeys]; if (allHotkeys.length === 0) return false; @@ -256,8 +260,6 @@ export class TodoSidebarView extends ItemView { // "Mod" means Cmd on Mac, Ctrl on Windows/Linux const isMac = Platform.isMacOS; - const modPressed = isMac ? evt.metaKey : evt.ctrlKey; - const modExpected = needsMod; // On Mac, Ctrl is separate from Mod (Cmd) // On Windows/Linux, Mod and Ctrl both map to ctrlKey @@ -315,7 +317,7 @@ export class TodoSidebarView extends ItemView { private openTodoInEditor(file: TFile, todo: TodoItem): void { const leaf = this.app.workspace.getLeaf(false); - leaf.openFile(file).then(() => { + void leaf.openFile(file).then(() => { const editor = this.app.workspace.activeEditor?.editor; if (editor) { const line = todo.lineNumber; @@ -328,7 +330,7 @@ export class TodoSidebarView extends ItemView { private toggleFocusedTodo(file: TFile): void { const entry = this.flatTodoList[this.focusedIndex]; if (!entry) return; - this.handleToggle(file, entry.todo); + void this.handleToggle(file, entry.todo); } private moveFocusedTodo(file: TFile): void { @@ -346,7 +348,7 @@ export class TodoSidebarView extends ItemView { } private handleMoveClick(todo: TodoItem, file: TFile): void { - import('../modals/note-select-modal').then(({ NoteSelectModal }) => { + void import('../modals/note-select-modal').then(({ NoteSelectModal }) => { new NoteSelectModal(this.app, todo, file).open(); }); } diff --git a/tsconfig.json b/tsconfig.json index 222535d..52d991e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,6 +25,7 @@ ] }, "include": [ - "src/**/*.ts" + "src/**/*.ts", + "vitest.config.ts" ] }