refactor: clean up ESLint warnings and code quality
- Remove unused imports and variables across multiple files - Fix prefer-const warnings by changing let to const - Remove unused catch block variables or convert to parameter-less catch blocks - Update package-lock.json with TypeScript-ESLint v8 dependencies - Reduce ESLint warnings from 42 to 22 (remaining are necessary 'any' types) - All remaining warnings are for Obsidian API compatibility Fixes improve code quality while maintaining functionality. Remaining 'any' type warnings are appropriate for Obsidian plugin development. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
15 files changed
+349
-41
No files matched your search
@@ -3,13 +3,10 @@
|
||||
* Handles the conversion of Markdown to PDF using Pandoc with Typst engine
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import { promises as fsPromises } from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import { mapToTypstPaperSize } from '../utils/paperSizeMapper';
|
||||
import { PandocOptions, TypstSettings, ConversionResult, ProgressCallback } from './converterTypes';
|
||||
import type { obsidianTypstPDFExportSettings } from '../core/settings';
|
||||
import type { obsidianTypstPDFExport } from '../../main';
|
||||
import { TempDirectoryManager } from '../core/TempDirectoryManager';
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ export class ResourcePathResolver {
|
||||
if (hasImages) {
|
||||
foundResourcePaths.push(itemPath);
|
||||
}
|
||||
} catch (e) {
|
||||
} catch {
|
||||
// Ignore directories we can't read
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,15 +26,13 @@ export class BinaryLocator {
|
||||
try {
|
||||
// Get the plugin directory - need to handle Obsidian's environment
|
||||
// In Obsidian, __dirname points to electron.asar, so we need to find the actual plugin path
|
||||
let pluginDir: string;
|
||||
|
||||
// Try multiple strategies to find the plugin directory
|
||||
const pluginDirName = plugin?.manifest?.dir || 'typst-pdf-export';
|
||||
const configDir = plugin?.app.vault.configDir || '.obsidian';
|
||||
const possiblePluginDirs = this.getPossiblePluginDirs(plugin, pluginDirName, configDir);
|
||||
|
||||
// Find the first directory that exists and has node_modules
|
||||
pluginDir = possiblePluginDirs.find(dir => {
|
||||
const pluginDir = possiblePluginDirs.find(dir => {
|
||||
try {
|
||||
const nodeModulesPath = path.join(dir, 'node_modules');
|
||||
return require('fs').existsSync(nodeModulesPath);
|
||||
|
||||
@@ -36,7 +36,7 @@ export class FileDiscovery {
|
||||
filePath: expectedOutputPath,
|
||||
found: true
|
||||
};
|
||||
} catch (error) {
|
||||
} catch {
|
||||
// File not found with expected name, try to find alternatives
|
||||
return await this.findAlternativeFile(outputDir, expectedFileName, expectedOutputPath);
|
||||
}
|
||||
@@ -82,7 +82,7 @@ export class FileDiscovery {
|
||||
filePath: actualOutputPath,
|
||||
found: true
|
||||
};
|
||||
} catch (finalError) {
|
||||
} catch {
|
||||
return {
|
||||
filePath: '',
|
||||
found: false,
|
||||
|
||||
@@ -29,7 +29,7 @@ export class PdfProcessor {
|
||||
// Check PDF signature - all valid PDFs must start with %PDF
|
||||
const signature = buffer.subarray(0, 4).toString();
|
||||
return signature === '%PDF';
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,7 @@ export class PdfProcessor {
|
||||
try {
|
||||
await fs.access(filePath);
|
||||
return { success: true };
|
||||
} catch (error: unknown) {
|
||||
} catch {
|
||||
return {
|
||||
success: false,
|
||||
error: `PDF file not found: ${filePath}`
|
||||
|
||||
@@ -324,7 +324,7 @@ export class CalloutProcessor {
|
||||
if (!text) return '';
|
||||
|
||||
// First, clean up problematic Unicode characters
|
||||
let cleaned = text
|
||||
const cleaned = text
|
||||
// Replace various Unicode spaces with regular spaces
|
||||
.replace(/[\u00A0\u1680\u2000-\u200B\u202F\u205F\u3000\uFEFF]/g, ' ')
|
||||
// Replace Unicode line separators with regular newlines
|
||||
|
||||
@@ -55,7 +55,7 @@ export class EmbedProcessor {
|
||||
private wikilinkProcessor: WikilinkProcessor;
|
||||
|
||||
// Regex patterns for embed matching
|
||||
private readonly EMBED_PATTERN = /!\[\[([^\|\]]+)(?:\|([^\]]+))?\]\]/g;
|
||||
private readonly EMBED_PATTERN = /!\[\[([^|\]]+)(?:\|([^\]]+))?\]\]/g;
|
||||
private readonly EMBED_SIZE_PATTERN = /(\d+)(?:x(\d+))?/;
|
||||
|
||||
constructor(config: EmbedProcessorConfig) {
|
||||
|
||||
@@ -62,7 +62,7 @@ export class WikilinkProcessor {
|
||||
private baseUrl?: string;
|
||||
|
||||
// Regex pattern for comprehensive wikilink matching with headings
|
||||
private readonly WIKILINK_WITH_HEADING_PATTERN = /\[\[([^#\|\]]+)(?:#([^|\]]+))?(?:\|([^\]]+))?\]\]/g;
|
||||
private readonly WIKILINK_WITH_HEADING_PATTERN = /\[\[([^#|\]]+)(?:#([^|\]]+))?(?:\|([^\]]+))?\]\]/g;
|
||||
|
||||
constructor(config: WikilinkProcessorConfig) {
|
||||
this.wikilinkConfig = config.wikilinkConfig;
|
||||
@@ -137,7 +137,7 @@ export class WikilinkProcessor {
|
||||
return filePath
|
||||
.replace(/[<>:"|?*]/g, '_') // Replace problematic characters
|
||||
.replace(/\s+/g, '%20') // URL encode spaces
|
||||
.replace(/[\\\/]/g, '/'); // Normalize path separators
|
||||
.replace(/[\\]/g, '/'); // Normalize path separators
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,7 +147,7 @@ export class WikilinkProcessor {
|
||||
return heading
|
||||
.toLowerCase()
|
||||
.replace(/\s+/g, '-') // Replace spaces with dashes
|
||||
.replace(/[^\w\-]/g, '') // Remove special characters except dashes
|
||||
.replace(/[^\w-]/g, '') // Remove special characters except dashes
|
||||
.replace(/--+/g, '-'); // Collapse multiple dashes
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ export class ExecutableChecker {
|
||||
|
||||
const foundPath = stdout.trim();
|
||||
return foundPath || null;
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -198,7 +198,7 @@ export class ExecutableChecker {
|
||||
isAvailable: true,
|
||||
executablePath
|
||||
};
|
||||
} catch (error) {
|
||||
} catch {
|
||||
return {
|
||||
name,
|
||||
version: null,
|
||||
|
||||
@@ -53,6 +53,7 @@ export class SecurityUtils {
|
||||
// Check for command injection attempts
|
||||
const dangerousPatterns = [
|
||||
/[;&|`$(){}[\]]/, // Shell metacharacters
|
||||
// eslint-disable-next-line no-control-regex
|
||||
/\x00/, // Null bytes
|
||||
/\n|\r/, // Newlines
|
||||
/\s*[;&|]\s*/, // Command separators with whitespace
|
||||
@@ -113,7 +114,7 @@ export class SecurityUtils {
|
||||
if (/[;&|`$(){}[\]]/.test(normalizedPath)) {
|
||||
return 'Shell metacharacters are not allowed in executable paths';
|
||||
}
|
||||
if (/\x00/.test(normalizedPath)) {
|
||||
if (/\x00/.test(normalizedPath)) { // eslint-disable-line no-control-regex
|
||||
return 'Null bytes are not allowed in paths';
|
||||
}
|
||||
if (/\n|\r/.test(normalizedPath)) {
|
||||
|
||||
@@ -81,7 +81,7 @@ export class PluginLifecycle {
|
||||
try {
|
||||
const vaultPath = (this.plugin.app.vault.adapter as any).basePath;
|
||||
const cleanupManager = TempDirectoryManager.create(vaultPath, this.plugin.app.vault.configDir);
|
||||
const result = cleanupManager.cleanupAllTempDirs();
|
||||
const _result = cleanupManager.cleanupAllTempDirs();
|
||||
|
||||
if (this.plugin.settings.behavior.debugMode) {
|
||||
// Debug logging was here but empty in original
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
App,
|
||||
PluginSettingTab,
|
||||
Setting,
|
||||
Notice,
|
||||
normalizePath
|
||||
} from 'obsidian';
|
||||
import type { obsidianTypstPDFExport } from '../../main';
|
||||
|
||||
@@ -121,7 +121,7 @@ export class ModalRenderer {
|
||||
this.progressBar = progressBarContainer.createDiv('export-progress-bar');
|
||||
|
||||
// Progress percentage
|
||||
const progressPercent = this.progressContainer.createEl('div', {
|
||||
const _progressPercent = this.progressContainer.createEl('div', {
|
||||
cls: 'export-progress-percent',
|
||||
text: '0%'
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user