TagSpaces is an offline, open source, document manager with tagging support
fix: eslint issues
Ilian Sapundshiev48d0c3abfcf4
diff --git a/.eslintignore b/.eslintignoreindex 7c7301076..4a2fe475b 100644--- a/.eslintignore+++ b/.eslintignore@@ -32,6 +32,7 @@ __snapshots__extensionscordova+capacitorweb# eslint ignores hidden directories by default:diff --git a/.eslintrc.js b/.eslintrc.jsindex 85a1aa65f..5d9266312 100644--- a/.eslintrc.js+++ b/.eslintrc.js@@ -1,6 +1,10 @@module.exports = {extends: 'erb',plugins: ['@typescript-eslint'],+ globals: {+ // Standard ES2020 global not recognized by the inherited 'erb' config.+ globalThis: 'readonly',+ },rules: {// A temporary hack related to IDE not resolving correct package.json'import/no-extraneous-dependencies': 'off',diff --git a/plugins/TsMetaPlugin.ts b/plugins/TsMetaPlugin.tsindex f45672a25..23a1df720 100644--- a/plugins/TsMetaPlugin.ts+++ b/plugins/TsMetaPlugin.ts@@ -4,7 +4,7 @@ import webpackPaths from '../.erb/configs/webpack.paths';import fs from 'fs';import fsPromises from 'fs/promises';import chalk from 'chalk';-import { execFile, spawn } from 'child_process';+import { spawn } from 'child_process';export class TsMetaPlugin {apply(compiler: webpack.Compiler) {@@ -69,17 +69,19 @@ export class TsMetaPlugin {const cwd = path.resolve(webpackPaths.rootPath);const script = path.join(cwd, 'scripts', 'versionmeta.js');- // Spawn "npm run version-meta" asynchronously+ // Run "node scripts/versionmeta.js" asynchronously, inheriting stdioawait new Promise<void>((resolve, reject) => {- execFile(- 'node',- [script],- { cwd, stdio: 'inherit' },- (err, _stdout, _stderr) => {- if (err) return reject(err);- resolve();- },- );+ const child = spawn(process.execPath, [script], {+ cwd,+ stdio: 'inherit',+ shell: false,+ });+ child.on('error', reject);+ child.on('exit', (code, signal) => {+ if (signal) return reject(new Error(`killed by signal ${signal}`));+ if (code !== 0) return reject(new Error(`exit code ${code}`));+ resolve();+ });});}@@ -111,16 +113,18 @@ export class TsMetaPlugin {const cwd = path.resolve(webpackPaths.rootPath);const script = path.join(cwd, 'scripts', 'jwt_generate.js');- await new Promise((resolve, reject) => {- execFile(- 'node',- [script],- { cwd, stdio: 'inherit' },- (err, _stdout, _stderr) => {- if (err) return reject(err);- resolve();- },- );+ await new Promise<void>((resolve, reject) => {+ const child = spawn(process.execPath, [script], {+ cwd,+ stdio: 'inherit',+ shell: false,+ });+ child.on('error', reject);+ child.on('exit', (code, signal) => {+ if (signal) return reject(new Error(`killed by signal ${signal}`));+ if (code !== 0) return reject(new Error(`exit code ${code}`));+ resolve();+ });});}// beforeRun fires once, before compiling beginsdiff --git a/src/renderer/components/dialogs/SettingsDialog.tsx b/src/renderer/components/dialogs/SettingsDialog.tsxindex dd758576f..ea47c9533 100644--- a/src/renderer/components/dialogs/SettingsDialog.tsx+++ b/src/renderer/components/dialogs/SettingsDialog.tsx@@ -37,7 +37,7 @@ import SettingsPerspectives from '-/components/dialogs/components/SettingsPerspeimport SettingsTemplates from '-/components/dialogs/components/SettingsTemplates';import TsDialogActions from '-/components/dialogs/components/TsDialogActions';import TsDialogTitle from '-/components/dialogs/components/TsDialogTitle';-import type { TransferSection } from '-/services/export-import-validators';+import type { SettingsBackupIntent } from '-/services/export-import-validators';import { openURLExternally } from '-/services/utils-io';import ArticleIcon from '@mui/icons-material/Article';import Dialog from '@mui/material/Dialog';@@ -62,16 +62,10 @@ export enum SettingsTab {AI = 'ai',}-/**- * Lets callers (e.g. the Locations menu) open Settings directly on the Backup- * tab and immediately start an export/import scoped to one section, instead of- * spawning a separate dialog.- */-export type SettingsBackupIntent = {- mode: 'export' | 'import';- scope?: TransferSection;- importFile?: File;-};+// Re-exported for callers that import it from the dialog (e.g. the settings+// dialog context provider). Defined in export-import-validators to avoid an+// import cycle with SettingsBackupRestore.+export type { SettingsBackupIntent };interface Props {open: boolean;diff --git a/src/renderer/components/dialogs/components/SettingsBackupRestore.tsx b/src/renderer/components/dialogs/components/SettingsBackupRestore.tsxindex eab0d3fb5..14d76d8de 100644--- a/src/renderer/components/dialogs/components/SettingsBackupRestore.tsx+++ b/src/renderer/components/dialogs/components/SettingsBackupRestore.tsx@@ -19,9 +19,11 @@import AppConfig from '-/AppConfig';import { ExportIcon, ImportIcon } from '-/components/CommonIcons';import TsButton from '-/components/TsButton';-import type { SettingsBackupIntent } from '-/components/dialogs/SettingsDialog';import ExportImportPanel from '-/components/dialogs/ExportImportPanel';-import type { TransferSection } from '-/services/export-import-validators';+import type {+ SettingsBackupIntent,+ TransferSection,+} from '-/services/export-import-validators';import Box from '@mui/material/Box';import List from '@mui/material/List';import ListItem from '@mui/material/ListItem';@@ -129,4 +131,8 @@ function SettingsBackupRestore(props: Props) {);}+SettingsBackupRestore.defaultProps = {+ backup: undefined,+};+export default SettingsBackupRestore;diff --git a/src/renderer/services/export-import-utils.ts b/src/renderer/services/export-import-utils.tsindex 6a1f52484..c327ac655 100644--- a/src/renderer/services/export-import-utils.ts+++ b/src/renderer/services/export-import-utils.ts@@ -109,7 +109,7 @@ export async function downloadEnvelope(): Promise<void> {const { blob, ext } = await serializeEnvelope(env, aesPassword);const dateTimeTag = formatDateTime4Tag(new Date(), true);- saveAsTextFile(blob, 'tagspaces-export [' + dateTimeTag + ']' + ext);+ saveAsTextFile(blob, `tagspaces-export [${dateTimeTag}]${ext}`);}export function readImportFile(diff --git a/src/renderer/services/export-import-validators.ts b/src/renderer/services/export-import-validators.tsindex caf83aaaf..6ccad20fb 100644--- a/src/renderer/services/export-import-validators.ts+++ b/src/renderer/services/export-import-validators.ts@@ -45,6 +45,18 @@ export interface TransferEnvelope {searches?: TS.SearchQuery[];}+/**+ * Lets callers (e.g. the Locations menu) open Settings directly on the Backup+ * tab and immediately start an export/import scoped to one section, instead of+ * spawning a separate dialog. Defined here (dependency-free) so SettingsDialog+ * and SettingsBackupRestore can both import it without an import cycle.+ */+export type SettingsBackupIntent = {+ mode: 'export' | 'import';+ scope?: TransferSection;+ importFile?: File;+};+/*** Settings keys that must never travel through an export/import: volatile* runtime/session state and environment-derived static lists.@@ -258,14 +270,11 @@ export function mergeImportedSettings(let mergedKeyBindings = state.keyBindings;if (Array.isArray(incoming.keyBindings)) {const stateKb = Array.isArray(state.keyBindings) ? state.keyBindings : [];- mergedKeyBindings = (defaultKeyBindings || []).map((x) =>- Object.assign(- {},- x,- stateKb.find((y: any) => y && y.name === x.name),- incoming.keyBindings.find((y: any) => y && y.name === x.name),- ),- );+ mergedKeyBindings = (defaultKeyBindings || []).map((x) => ({+ ...x,+ ...stateKb.find((y: any) => y && y.name === x.name),+ ...incoming.keyBindings.find((y: any) => y && y.name === x.name),+ }));delete incoming.keyBindings;}return {@@ -309,8 +318,12 @@ const WEAK_SUBSTRINGS = [* it uses a single character class.*/export function evaluatePasswordStrength(pw: string): PasswordStrength {- const toLabel = (s: number): PasswordStrength['label'] =>- s <= 1 ? 'weak' : s === 2 ? 'fair' : s === 3 ? 'good' : 'strong';+ const toLabel = (s: number): PasswordStrength['label'] => {+ if (s <= 1) return 'weak';+ if (s === 2) return 'fair';+ if (s === 3) return 'good';+ return 'strong';+ };if (!pw) {return { score: 0, ok: false, label: 'weak' };diff --git a/src/renderer/services/secure-crypto.ts b/src/renderer/services/secure-crypto.tsindex f151aa16e..040c70e9d 100644--- a/src/renderer/services/secure-crypto.ts+++ b/src/renderer/services/secure-crypto.ts@@ -36,6 +36,9 @@* count is stored in the header so future tuning never breaks old files.*/+/* eslint-disable no-bitwise -- byte ↔ base64 / WordArray conversion and the+ constant-time MAC compare legitimately require bitwise operators. */+import CryptoJS from 'crypto-js';const TSENC_VERSION = 2;@@ -213,7 +216,7 @@ export async function encryptString(const ivB64 = bytesToB64(ivBytes);const ctB64 = enc.ciphertext.toString(CryptoJS.enc.Base64);const mac = CryptoJS.HmacSHA256(- saltB64 + '.' + ivB64 + '.' + ctB64,+ `${saltB64}.${ivB64}.${ctB64}`,macKey,).toString();return JSON.stringify({@@ -267,7 +270,7 @@ export async function decryptString(iter,);const expectedMac = CryptoJS.HmacSHA256(- header.salt + '.' + header.iv + '.' + header.ct,+ `${header.salt}.${header.iv}.${header.ct}`,macKey,).toString();if (