From a42af638b67b5936a39367f1d18eb6798df17579 Mon Sep 17 00:00:00 2001 From: lin onetwo Date: Fri, 31 Oct 2025 00:10:44 +0800 Subject: [PATCH] lint --- eslint.config.mjs | 2 +- features/stepDefinitions/application.ts | 12 ++++----- features/supports/paths.ts | 2 +- package.json | 4 +-- scripts/compilePlugins.mjs | 34 +++++++++++++------------ scripts/developmentMkdir.ts | 4 ++- scripts/start-e2e-app.ts | 9 ++++--- scripts/startMockOpenAI.ts | 4 ++- tsconfig.json | 2 +- 9 files changed, 40 insertions(+), 33 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 5067fad9..b081d096 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -22,7 +22,7 @@ export default [ }, }, { - files: ['**/*.test.ts', '**/*.test.tsx', '**/*.spec.ts', '**/*.spec.tsx'], + files: ['**/*.test.ts', '**/*.test.tsx', '**/*.spec.ts', '**/*.spec.tsx', "*.env.d.ts"], rules: { '@typescript-eslint/unbound-method': 'off', 'unicorn/prevent-abbreviations': 'off', diff --git a/features/stepDefinitions/application.ts b/features/stepDefinitions/application.ts index f478d7bf..37b796b8 100644 --- a/features/stepDefinitions/application.ts +++ b/features/stepDefinitions/application.ts @@ -222,12 +222,12 @@ AfterStep(async function(this: ApplicationWorld, { pickle, pickleStep, result }) } } - const scenarioName = pickle.name; - // Limit scenario slug to avoid extremely long directory names - const cleanScenarioName = makeSlugPath(scenarioName, 60); + const scenarioName = pickle.name; + // Limit scenario slug to avoid extremely long directory names + const cleanScenarioName = makeSlugPath(scenarioName, 60); - // Limit step text slug to avoid excessively long filenames which can trigger ENAMETOOLONG - const cleanStepText = makeSlugPath(stepText, 80); + // Limit step text slug to avoid excessively long filenames which can trigger ENAMETOOLONG + const cleanStepText = makeSlugPath(stepText, 80); const stepStatus = result && typeof result.status === 'string' ? result.status : 'unknown-status'; const featureDirectory = path.resolve(screenshotsDirectory, cleanScenarioName); @@ -247,7 +247,7 @@ AfterStep(async function(this: ApplicationWorld, { pickle, pickleStep, result }) } const timestamp = new Date().toISOString().replace(/[:.]/g, '-'); - + // Try to capture both WebContentsView and Page screenshots let webViewCaptured = false; if (this.app) { diff --git a/features/supports/paths.ts b/features/supports/paths.ts index a0ef3b65..26820e5a 100644 --- a/features/supports/paths.ts +++ b/features/supports/paths.ts @@ -66,7 +66,7 @@ const unsafeChars = /[^\p{L}\p{N}\s\-_()]/gu; const collapseDashes = /-+/g; const collapseSpaces = /\s+/g; export const makeSlugPath = (input: string | undefined, maxLength = 120) => { - let s = String(input || 'unknown').normalize('NFKC'); + let s = (input || 'unknown').normalize('NFKC'); // remove dots explicitly s = s.replace(/\./g, ''); // replace unsafe characters with dashes diff --git a/package.json b/package.json index 408eb641..e52c030a 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,8 @@ "make": "pnpm run build:plugin && cross-env NODE_ENV=production electron-forge make", "make:analyze": "cross-env ANALYZE=true pnpm run make", "init:git-submodule": "git submodule update --init --recursive && git submodule update --remote", - "lint": "eslint ./src --ext js,ts,tsx,json", - "lint:fix": "eslint ./src --ext ts,tsx --fix", + "lint": "eslint ./src ./features ./scripts ./localization ./*.ts --ext js,ts,tsx,json", + "lint:fix": "eslint ./src ./features ./scripts ./localization ./*.ts --ext ts,tsx,json --fix", "check": "tsc --noEmit --skipLibCheck", "installType": "typesync" }, diff --git a/scripts/compilePlugins.mjs b/scripts/compilePlugins.mjs index cfcb5b9a..d45aa1ae 100644 --- a/scripts/compilePlugins.mjs +++ b/scripts/compilePlugins.mjs @@ -1,14 +1,16 @@ +/* eslint-disable @typescript-eslint/use-unknown-in-catch-callback-variable */ +/* eslint-disable @typescript-eslint/restrict-template-expressions */ +/* eslint-disable no-undef */ /* eslint-disable @typescript-eslint/no-unsafe-argument */ /* eslint-disable @typescript-eslint/no-unsafe-return */ -/* eslint-disable unicorn/prevent-abbreviations */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-call */ import esbuild from 'esbuild'; import fs from 'fs-extra'; import path from 'path'; -import { fileURLToPath } from 'url'; import { rimraf } from 'rimraf'; +import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -23,15 +25,15 @@ const nativeNodeModulesPlugin = { // Rewrite nsfw's require() to use node_modules path build.onLoad({ filter: /nsfw[/\\]js[/\\]src[/\\]index\.js$/ }, async (args) => { let contents = await fs.readFile(args.path, 'utf8'); - + // Replace relative path with require from node_modules // Original: require('../../build/Release/nsfw.node') // New: require('nsfw/build/Release/nsfw.node') contents = contents.replace( /require\(['"]\.\.\/\.\.\/build\/Release\/nsfw\.node['"]\)/g, - "require('nsfw/build/Release/nsfw.node')" + "require('nsfw/build/Release/nsfw.node')", ); - + return { contents, loader: 'js', @@ -110,7 +112,7 @@ function getPluginOutputDirs(pluginName) { const resourcesPath = path.join(outDir, dirent.name, 'resources/node_modules/tiddlywiki/plugins/linonetwo', pluginName); return resourcesPath; }); - + // Only add directories that exist (have been created by afterPack) packDirs.forEach(dir => { const parentDir = path.dirname(dir); @@ -142,7 +144,7 @@ async function buildEntryPoints(plugin, outDirs) { } const sourcePath = path.join(__dirname, plugin.sourceFolder); - + await Promise.all( outDirs.flatMap(outDir => plugin.entryPoints.map(entryPoint => @@ -152,7 +154,7 @@ async function buildEntryPoints(plugin, outDirs) { outdir: outDir, }) ) - ) + ), ); } @@ -161,7 +163,7 @@ async function buildEntryPoints(plugin, outDirs) { */ async function copyNonTsFiles(plugin, outDirs) { const sourcePath = path.join(__dirname, plugin.sourceFolder); - + await Promise.all(outDirs.map(async (outDir) => { await fs.copy(sourcePath, outDir, { filter: filterNonTsFiles }); console.log(`✓ Copied ${plugin.name} to: ${outDir}`); @@ -173,19 +175,19 @@ async function copyNonTsFiles(plugin, outDirs) { */ async function buildPlugin(plugin) { console.log(`\nBuilding plugin: ${plugin.name}`); - + const outDirs = getPluginOutputDirs(plugin.name); console.log(` Output directories: ${outDirs.length}`); - + // Prepare output directories await prepareOutputDirs(outDirs); - + // Build TypeScript entry points await buildEntryPoints(plugin, outDirs); - + // Copy non-TypeScript files await copyNonTsFiles(plugin, outDirs); - + console.log(`✓ Completed ${plugin.name}`); } @@ -194,11 +196,11 @@ async function buildPlugin(plugin) { */ async function main() { console.log('Starting plugin compilation...\n'); - + for (const plugin of PLUGINS) { await buildPlugin(plugin); } - + console.log('\n✓ All plugins compiled successfully!'); } diff --git a/scripts/developmentMkdir.ts b/scripts/developmentMkdir.ts index 788e6c29..1adcc7b0 100644 --- a/scripts/developmentMkdir.ts +++ b/scripts/developmentMkdir.ts @@ -3,5 +3,7 @@ import { DEFAULT_FIRST_WIKI_FOLDER_PATH } from '../src/constants/paths'; try { fs.removeSync(DEFAULT_FIRST_WIKI_FOLDER_PATH); -} catch {} +} catch { + // ignore +} fs.mkdirpSync(DEFAULT_FIRST_WIKI_FOLDER_PATH); diff --git a/scripts/start-e2e-app.ts b/scripts/start-e2e-app.ts index b4ed9b5f..f427007b 100644 --- a/scripts/start-e2e-app.ts +++ b/scripts/start-e2e-app.ts @@ -1,4 +1,5 @@ // pnpm exec cross-env NODE_ENV=test tsx ./scripts/start-e2e-app.ts +/* eslint-disable unicorn/prevent-abbreviations */ import { spawn } from 'child_process'; import { getPackedAppPath } from '../features/supports/paths'; @@ -7,16 +8,16 @@ import { getPackedAppPath } from '../features/supports/paths'; const appPath = getPackedAppPath(); console.log('Starting TidGi E2E app:', appPath); -const env = Object.assign({}, process.env, { +const environment = Object.assign({}, process.env, { NODE_ENV: 'test', LANG: process.env.LANG || 'zh-Hans.UTF-8', LANGUAGE: process.env.LANGUAGE || 'zh-Hans:zh', LC_ALL: process.env.LC_ALL || 'zh-Hans.UTF-8', }); -const child = spawn(appPath, [], { env, stdio: 'inherit' }); +const child = spawn(appPath, [], { env: environment, stdio: 'inherit' }); child.on('exit', code => process.exit(code ?? 0)); -child.on('error', err => { - console.error('Failed to start TidGi app:', err); +child.on('error', error => { + console.error('Failed to start TidGi app:', error); process.exit(1); }); diff --git a/scripts/startMockOpenAI.ts b/scripts/startMockOpenAI.ts index cdb57af1..32ed4f2f 100644 --- a/scripts/startMockOpenAI.ts +++ b/scripts/startMockOpenAI.ts @@ -43,8 +43,10 @@ async function main() { }); // 防止进程退出 - 使用 setInterval 而不是空的 Promise - const keepAlive = setInterval(() => { + // 注意在 e2e 的 CleanUp 里关闭服务器 + setInterval(() => { // 每10秒输出一次状态,确认服务器还在运行 + console.log('Mock OpenAI 服务器仍在运行...'); }, 10000); } catch (error) { console.error('❌ 启动服务器失败:', error); diff --git a/tsconfig.json b/tsconfig.json index a92bba40..38939d3a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "exclude": ["template/**/*.js", "features/cucumber.config.js", "**/__mocks__/**/*.js"], - "include": ["src", "features", "test", "./*.*.ts", "./*.*.js", "forge.config.ts"], + "include": ["src", "features", "test", "scripts", "./*.*.ts", "./*.*.js", "forge.config.ts"], "ts-node": { "files": true, "compilerOptions": {