From 4c18a669848cc8eae73ad826c7e8a4a907bd7b56 Mon Sep 17 00:00:00 2001 From: johnny1093 <46250921+jsmorabito@users.noreply.github.com> Date: Sat, 11 Jul 2026 09:55:13 -0400 Subject: [PATCH] lint: scope Node/mobile-compat rules off test and config files, tidy up a few regressions - no-nodejs-modules, no-global-this, and prefer-create-el only exist to protect the shipped mobile bundle; scope them off for eslint.config.mts, vitest.config.ts, and src/__tests__/** since none of that runs inside Obsidian. - Fix vitest.config.ts's __dirname the same way eslint.config.mts already was (fileURLToPath(import.meta.url)), since __dirname isn't defined under ESM. - Disable no-empty-function (with a description) on the two intentionally-empty open()/close() mock methods introduced earlier. - Drop the now-unused `error` catch binding left over from removing its console.log in an earlier commit. --- eslint.config.mts | 11 +++++++++++ src/__tests__/__mocks__/obsidian.ts | 4 ++++ src/manager/commands/menuManager.ts | 2 +- vitest.config.ts | 3 +++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/eslint.config.mts b/eslint.config.mts index 4210b92..582df90 100644 --- a/eslint.config.mts +++ b/eslint.config.mts @@ -63,4 +63,15 @@ export default defineConfig( 'obsidianmd/commands/no-command-in-command-id': 'off', }, }, + { + files: ['eslint.config.mts', 'vitest.config.ts', 'src/__tests__/**'], + rules: { + // These only run under Node (eslint/vitest CLI), never bundled + // into main.js or loaded inside Obsidian, so the mobile/runtime + // compatibility rationale behind these rules doesn't apply here. + 'obsidianmd/no-nodejs-modules': 'off', + 'obsidianmd/no-global-this': 'off', + 'obsidianmd/prefer-create-el': 'off', + }, + }, ); diff --git a/src/__tests__/__mocks__/obsidian.ts b/src/__tests__/__mocks__/obsidian.ts index e4eb0a2..0d951a9 100644 --- a/src/__tests__/__mocks__/obsidian.ts +++ b/src/__tests__/__mocks__/obsidian.ts @@ -27,14 +27,18 @@ export class FuzzySuggestModal { public app: unknown; protected declare items: T[]; public constructor(app: unknown) { this.app = app; } + // eslint-disable-next-line @typescript-eslint/no-empty-function -- minimal test double, no-op is intentional public open(): void {} + // eslint-disable-next-line @typescript-eslint/no-empty-function -- minimal test double, no-op is intentional public close(): void {} } export class SuggestModal { public app: unknown; protected declare items: T[]; public constructor(app: unknown) { this.app = app; } + // eslint-disable-next-line @typescript-eslint/no-empty-function -- minimal test double, no-op is intentional public open(): void {} + // eslint-disable-next-line @typescript-eslint/no-empty-function -- minimal test double, no-op is intentional public close(): void {} } export class PluginSettingTab { diff --git a/src/manager/commands/menuManager.ts b/src/manager/commands/menuManager.ts index e160979..69e1339 100644 --- a/src/manager/commands/menuManager.ts +++ b/src/manager/commands/menuManager.ts @@ -161,7 +161,7 @@ abstract class Base extends CommandManagerBase { const pair = await chooseNewCommand(plugin); commandList.push(pair); await plugin.saveSettings(); - } catch (error) { + } catch { // User cancelled command/icon selection, nothing to do } }); diff --git a/vitest.config.ts b/vitest.config.ts index 7f17458..74c9b69 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,5 +1,8 @@ import { defineConfig } from "vitest/config"; import path from "path"; +import { fileURLToPath } from "url"; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); export default defineConfig({ test: {