chore: add eslint configuration and improve file conversion type safety

This commit is contained in:
Rhys 2026-05-04 11:29:11 +02:00
parent b2749e81c3
commit c6ea3a2f82
4 changed files with 4667 additions and 13 deletions

23
eslint.config.js Normal file
View file

@ -0,0 +1,23 @@
// eslint.config.mjs
import tsparser from "@typescript-eslint/parser";
import { defineConfig } from "eslint/config";
import obsidianmd from "eslint-plugin-obsidianmd";
export default defineConfig([
...obsidianmd.configs.recommended,
{
files: ["**/*.ts"],
languageOptions: {
parser: tsparser,
parserOptions: { project: "./tsconfig.json" },
},
// You can add your own configuration to override or add rules
rules: {
// example: turn off a rule from the recommended set
"obsidianmd/sample-names": "off",
// example: add a rule not in the recommended set and set its severity
"obsidianmd/prefer-file-manager-trash-file": "error",
},
},
]);

4633
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -6,7 +6,8 @@
"type": "module",
"scripts": {
"dev": "node esbuild.config.mjs",
"build": "tsc --noEmit --skipLibCheck && node esbuild.config.mjs production"
"build": "tsc --noEmit --skipLibCheck && node esbuild.config.mjs production",
"lint": "eslint \"**/*.ts\""
},
"license": "MIT",
"dependencies": {
@ -16,6 +17,8 @@
"@types/node": "^22.0.0",
"builtin-modules": "^4.0.0",
"esbuild": "^0.25.5",
"eslint": "^10.3.0",
"eslint-plugin-obsidianmd": "^0.2.9",
"typescript": "^5.8.3"
}
}
}

View file

@ -1,5 +1,6 @@
import {
App,
FileSystemAdapter,
Modal,
Notice,
Plugin,
@ -124,8 +125,6 @@ class DocDropSettingTab extends PluginSettingTab {
const { containerEl } = this;
containerEl.empty();
containerEl.createEl("h2", { text: "DocDrop" });
new Setting(containerEl)
.setName("Executable path")
.setDesc(
@ -173,7 +172,7 @@ class DocDropSettingTab extends PluginSettingTab {
);
}
containerEl.createEl("h3", { text: "Conversion options" });
new Setting(containerEl).setName("Conversion").setHeading();
new Setting(containerEl)
.setName("Keep images")
@ -391,7 +390,7 @@ export default class DocDropPlugin extends Plugin {
new Notice(`DocDrop does not support .${activeFile.extension} files.`);
return;
}
this.convertFile(activeFile);
void this.convertFile(activeFile);
},
});
@ -413,7 +412,7 @@ export default class DocDropPlugin extends Plugin {
onunload(): void {}
async loadSettings(): Promise<void> {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData() as Partial<DocDropSettings>);
}
async saveSettings(): Promise<void> {
@ -422,7 +421,11 @@ export default class DocDropPlugin extends Plugin {
private async convertFile(pdfFile: TFile): Promise<void> {
const adapter = this.app.vault.adapter;
const basePath = (adapter as any).getBasePath() as string;
if (!(adapter instanceof FileSystemAdapter)) {
new Notice("DocDrop only works on desktop (local vault).");
return;
}
const basePath = adapter.getBasePath();
const absolutePdfPath = `${basePath}/${pdfFile.path}`;
const outputVaultPath = this.resolveOutputPath(pdfFile);
@ -438,7 +441,7 @@ export default class DocDropPlugin extends Plugin {
new OverwriteModal(
this.app,
outputVaultPath,
() => this.runConversion(absolutePdfPath, outputVaultPath, existing),
() => { void this.runConversion(absolutePdfPath, outputVaultPath, existing); },
() => new Notice("Conversion cancelled.")
).open();
return;