Update ESLint rules and resolve bot review feedback #8

Merged
AlexKucera merged 24 commits from obsidian-bot-review into master 2025-11-09 12:06:31 +01:00
7 changed files with 27 additions and 29 deletions
Showing only changes of commit 7d805eda45 - Show all commits

No files matched your search

+1 -1
View File
1
@@ -38,7 +38,7 @@ export class CommandRegistry {
// Check dependencies command
this.plugin.addCommand({
id: 'check-dependencies',
name: 'Check Pandoc and Typst dependencies',
name: 'Check pandoc and typst dependencies',
callback: () => {
this.plugin.showDependencyStatus().catch(error => {
console.error('Failed to show dependency status:', error);
+6 -4
View File
@@ -88,7 +88,7 @@ export class EmbedProcessor {
* Returns the local path if successful, null if failed
*/
private async downloadRemoteImage(imageUrl: string, tempDir: string): Promise<string | null> {
return new Promise((resolve) => {
return new Promise((resolve, reject) => {
try {
// Parse URL to get filename
const urlObj = new URL(imageUrl);
@@ -124,7 +124,7 @@ export class EmbedProcessor {
const absoluteRedirectUrl = new URL(redirectUrl, imageUrl).href;
console.debug(`Export:Following redirect to: ${absoluteRedirectUrl}`);
// Recursively follow redirect with resolved absolute URL
this.downloadRemoteImage(absoluteRedirectUrl, tempDir).then(resolve);
this.downloadRemoteImage(absoluteRedirectUrl, tempDir).then(resolve).catch(reject);
return;
}
}
@@ -143,7 +143,8 @@ export class EmbedProcessor {
chunks.push(chunk);
});
response.on('end', async () => {
response.on('end', () => {
void (async () => {
try {
// Check if file already exists to avoid overwriting
const exists = await this.pathUtils.fileExists(outputPath);
@@ -165,7 +166,8 @@ export class EmbedProcessor {
console.error(`Export: Error writing image file: ${err.message}`);
resolve(null);
}
});
})();
});
response.on('error', (err) => {
console.error(`Export: Error receiving image data: ${err.message}`);
+3 -3
View File
@@ -20,7 +20,7 @@ export class EventHandlers {
if (file.extension === 'md') {
menu.addItem((item) => {
item
.setTitle('Export to PDF (Typst)')
.setTitle('Export to PDF')
.setIcon('file-output')
.onClick(() => {
this.plugin.exportFile(file).catch(error => {
@@ -37,7 +37,7 @@ export class EventHandlers {
this.plugin.app.workspace.on('editor-menu', (menu: Menu, editor: Editor, view: MarkdownView) => {
menu.addItem((item) => {
item
.setTitle('Export to PDF (Typst)')
.setTitle('Export to PDF')
.setIcon('file-output')
.onClick(() => {
this.plugin.exportCurrentNote(view).catch(error => {
@@ -57,7 +57,7 @@ export class EventHandlers {
if (markdownFiles.length > 0) {
menu.addItem((item) => {
item
.setTitle(`Export to PDF (Typst)`)
.setTitle(`Export to PDF`)
.setIcon('file-output')
.onClick(() => {
this.plugin.exportFiles(markdownFiles).catch(error => {
+3 -3
View File
@@ -162,9 +162,9 @@ export class ExportOrchestrator {
cls: 'mod-warning'
});
cancelButton.addEventListener('click', () => this.cancelExport());
progressNotice.setMessage('Preprocessing markdown content...');
progressNotice.setMessage('Preprocessing Markdown content...');
// Preprocess markdown
// Preprocess Markdown
const preprocessor = new MarkdownPreprocessor({
vaultPath: vaultPath,
options: {
@@ -322,7 +322,7 @@ export class ExportOrchestrator {
const markdownFiles = folder.children.filter((file) => this.plugin.isMarkdownFile(file));
if (markdownFiles.length === 0) {
new Notice('No markdown files found in this folder');
new Notice('No Markdown files found in this folder');
return;
}
+11 -15
View File
@@ -28,10 +28,6 @@ export class ObsidianTypstPDFExportSettingTab extends PluginSettingTab {
const { containerEl } = this;
containerEl.empty();
new Setting(containerEl)
.setName('Typst PDF Export Settings')
.setHeading();
// Executable paths section
this.createExecutablePathsSection(containerEl);
@@ -66,9 +62,9 @@ export class ObsidianTypstPDFExportSettingTab extends PluginSettingTab {
new Setting(containerEl)
.setName('Pandoc path')
.setDesc('Path to pandoc executable (leave empty to use system PATH)')
.setDesc('Path to pandoc executable (leave empty to use system path)')
.addText(text => text
.setPlaceholder('pandoc')
.setPlaceholder('Pandoc')
.setValue(this.plugin.settings.pandocPath)
.onChange(async (value) => {
if (!SecurityUtils.validateExecutablePath(value)) {
@@ -81,9 +77,9 @@ export class ObsidianTypstPDFExportSettingTab extends PluginSettingTab {
new Setting(containerEl)
.setName('Typst path')
.setDesc('Path to typst executable (leave empty to use system PATH)')
.setDesc('Path to typst executable (leave empty to use system path)')
.addText(text => text
.setPlaceholder('typst')
.setPlaceholder('Typst')
.setValue(this.plugin.settings.typstPath)
.onChange(async (value) => {
if (!SecurityUtils.validateExecutablePath(value)) {
@@ -95,10 +91,10 @@ export class ObsidianTypstPDFExportSettingTab extends PluginSettingTab {
}));
new Setting(containerEl)
.setName('ImageMagick path')
.setDesc('Path to ImageMagick executable (leave empty to use system PATH)')
.setName('Imagemagick path')
.setDesc('Path to imagemagick executable (leave empty to use system path)')
.addText(text => text
.setPlaceholder('magick')
.setPlaceholder('Magick')
.setValue(this.plugin.settings.executablePaths.imagemagickPath)
.onChange(async (value) => {
if (!SecurityUtils.validateExecutablePath(value)) {
@@ -141,7 +137,7 @@ export class ObsidianTypstPDFExportSettingTab extends PluginSettingTab {
new Setting(containerEl)
.setName('Default template')
.setDesc('Default Typst template for exports')
.setDesc('Default typst template for exports')
.addDropdown(async (dropdown) => {
try {
const templates = await this.plugin.templateManager.getAvailableTemplates();
@@ -163,7 +159,7 @@ export class ObsidianTypstPDFExportSettingTab extends PluginSettingTab {
} catch (error) {
console.error('Failed to load templates:', error);
// Fallback to text input
dropdown.addOption('default.typ', 'default.typ');
dropdown.addOption('default.typ', 'Default.typ');
dropdown.setValue(this.plugin.settings.exportDefaults.template);
}
});
@@ -182,10 +178,10 @@ export class ObsidianTypstPDFExportSettingTab extends PluginSettingTab {
new Setting(containerEl)
.setName('Output folder')
.setDesc('Default folder for exported PDFs (relative to vault root)')
.setDesc('Folder for exported pdfs (relative to vault root)')
.addText(text => {
text
.setPlaceholder('exports')
.setPlaceholder('Exports')
.setValue(this.plugin.settings.outputFolder)
.onChange(async (value) => {
const normalizedValue = normalizePath(value);
1
+1 -1
View File
@@ -154,7 +154,7 @@ export class ModalRenderer {
text: 'Export',
coderabbitai[bot] commented 2025-11-05 19:26:59 +01:00 (Migrated from github.com)
Review

⚠️ Potential issue | 🟠 Major

Handle potential promise rejection from async onSubmit.

The void operator correctly discards the promise, but if onSubmit is async and throws an error, it will result in an unhandled promise rejection. This could lead to unexpected behavior or silent failures.

Apply this diff to add proper error handling:

-		this.submitButton.addEventListener('click', () => void this.callbacks.onSubmit());
+		this.submitButton.addEventListener('click', async () => {
+			try {
+				await this.callbacks.onSubmit();
+			} catch (error) {
+				console.error('Export failed:', error);
+				// Optionally show error to user via validation errors
+				this.showValidationErrors([`Export failed: ${error instanceof Error ? error.message : String(error)}`]);
+			}
+		});

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/ui/modal/ModalRenderer.ts around line 157, the click handler currently
calls this.callbacks.onSubmit() with the void operator which discards the
returned promise and can create unhandled promise rejections if onSubmit is
async; change the handler to capture the promise and attach error handling
(e.g., call Promise.resolve(this.callbacks.onSubmit()).catch(err => { /*
handle/log error and update UI state */ })) or wrap the invocation in an async
function with try/catch so any thrown/rejected error is caught and handled
appropriately (log the error and provide user-facing feedback or disable the
submit button as needed).

✅ Addressed in commits f0daebc to c1c02ee

_⚠️ Potential issue_ | _🟠 Major_ **Handle potential promise rejection from async onSubmit.** The `void` operator correctly discards the promise, but if `onSubmit` is async and throws an error, it will result in an unhandled promise rejection. This could lead to unexpected behavior or silent failures. Apply this diff to add proper error handling: ```diff - this.submitButton.addEventListener('click', () => void this.callbacks.onSubmit()); + this.submitButton.addEventListener('click', async () => { + try { + await this.callbacks.onSubmit(); + } catch (error) { + console.error('Export failed:', error); + // Optionally show error to user via validation errors + this.showValidationErrors([`Export failed: ${error instanceof Error ? error.message : String(error)}`]); + } + }); ``` > Committable suggestion skipped: line range outside the PR's diff. <details> <summary>🤖 Prompt for AI Agents</summary> ``` In src/ui/modal/ModalRenderer.ts around line 157, the click handler currently calls this.callbacks.onSubmit() with the void operator which discards the returned promise and can create unhandled promise rejections if onSubmit is async; change the handler to capture the promise and attach error handling (e.g., call Promise.resolve(this.callbacks.onSubmit()).catch(err => { /* handle/log error and update UI state */ })) or wrap the invocation in an async function with try/catch so any thrown/rejected error is caught and handled appropriately (log the error and provide user-facing feedback or disable the submit button as needed). ``` </details> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commits f0daebc to c1c02ee
cls: 'mod-cta'
});
this.submitButton.addEventListener('click', () => this.callbacks.onSubmit());
this.submitButton.addEventListener('click', () => void this.callbacks.onSubmit());
}
/**
+2 -2
View File
@@ -74,10 +74,10 @@ export class GeneralSection implements ModalSection {
new Setting(this.container)
coderabbitai[bot] commented 2025-11-05 19:26:59 +01:00 (Migrated from github.com)
Review

⚠️ Potential issue | 🟡 Minor

Description contradicts absolute path handling.

The description states "relative to vault root", but the code on lines 84-85 now accepts and preserves absolute paths. Either update the description to clarify that absolute paths are supported, or remove the absolute path handling to match the description.

If absolute paths are intended, consider updating the description:

-			.setDesc('Location for exported PDF files (relative to vault root)')
+			.setDesc('Location for exported PDF files (relative to vault root, or absolute path)')
🤖 Prompt for AI Agents
In src/ui/modal/sections/GeneralSection.ts around line 78, the UI description
currently reads "Location for exported PDF files (relative to vault root)" but
the code now accepts and preserves absolute paths; update the description to
accurately reflect that both relative paths (resolved against vault root) and
absolute paths are supported (e.g., "Location for exported PDF files (relative
to vault root or absolute path)") or, if absolute paths are not intended, remove
the absolute-path handling in the code so the behavior matches the original
"relative" wording; ensure text is concise and consistent with the actual path
handling logic.

✅ Addressed in commits f0daebc to c1c02ee

_⚠️ Potential issue_ | _🟡 Minor_ **Description contradicts absolute path handling.** The description states "relative to vault root", but the code on lines 84-85 now accepts and preserves absolute paths. Either update the description to clarify that absolute paths are supported, or remove the absolute path handling to match the description. If absolute paths are intended, consider updating the description: ```diff - .setDesc('Location for exported PDF files (relative to vault root)') + .setDesc('Location for exported PDF files (relative to vault root, or absolute path)') ``` <details> <summary>🤖 Prompt for AI Agents</summary> ``` In src/ui/modal/sections/GeneralSection.ts around line 78, the UI description currently reads "Location for exported PDF files (relative to vault root)" but the code now accepts and preserves absolute paths; update the description to accurately reflect that both relative paths (resolved against vault root) and absolute paths are supported (e.g., "Location for exported PDF files (relative to vault root or absolute path)") or, if absolute paths are not intended, remove the absolute-path handling in the code so the behavior matches the original "relative" wording; ensure text is concise and consistent with the actual path handling logic. ``` </details> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commits f0daebc to c1c02ee
.setName('Output folder')
.setDesc('Folder where PDFs will be saved (relative to vault root)')
.setDesc('Location for exported PDF files (relative to vault root)')
.addText(text => {
const input = text
.setPlaceholder('exports')
.setPlaceholder('PDF exports')
.setValue(state.settings.outputFolder || 'exports')
.onChange(value => {
const normalizedValue = normalizePath(value);
1